Permalink
Browse files

new model constructs

  • Loading branch information...
1 parent 73b065a commit f4d977b2b25597c4f9ebe8680b1d25abdfad0033 @lynxbat lynxbat committed Feb 24, 2012
View
@@ -0,0 +1 @@
+--no-private --protected ./lib/**/*.rb
View
@@ -1,13 +1,13 @@
# A sample Gemfile
source "http://rubygems.org"
-gem "mongo" # You need to install the newest per the README.rdoc
+#gem "mongo" # You need to install the newest per the README.rdoc
gem "bson"
gem "bson_ext"
gem "rspec"
gem "syntax"
gem "uuid"
-gem "log4r"
+gem "logger"
gem "extlib" # used for full_const_get method
gem "json"
gem "colored"
View
@@ -1,86 +0,0 @@
-# Project Razor
-
-## Introduction
-
-Project Razor is a power control, provisioning, and management application designed
-to deploy both bare-metal and virtual compute resources with tight integration to
-DevOps-style tool sets.
-
-## Authors
-
-[Nicholas Weaver](https://github.com/lynxbat)
-[Tom McSweeney](https://github.com/tjmcs)
-
-## Installation
-
-### Node.js:
-[Node.js install with package manager](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager)
-[Node Package Manager(NPM)](http://npmjs.org/)
-[Express install via NPM](http://expressjs.com/guide.html)
-
-### Database
-
-#### Mongo
-
-_todo_
-
-## Prereqs
-
-* Ruby >= 1.9.3
-* Assorted gems - see (Gemfile)
-* Node.js >= 0.6.10
-* Node.js Express package
-
-
-## Environment Variables
-* $RAZOR_HOME
- >Root directory for Razor install
-
-* $RAZOR_RSPEC_WEBPATH
- >Root directory for dropping RSpec html _(optional)_
-
-* $RAZOR_LOG_PATH
->Path for razor logs _(optional)_l
->>Default = $RAZOR_HOME/log
-
-* $RAZOR_LOG_LEVEL
- > Verbosity for logs _(optional)_
- >> 0 = Debug
- >> 1 = Info
- >> 2 = Warn
- >> 3 = Error (default)
- >> 4 = Fatal
- >> 5 = Unknown
-
-
-## Directory structure
- ./bin - control scripts
- ./conf - configuration YAML files
- ./doc - Documentation (YARD)
- ./images - default images directory
- ./install - installation bits
- ./lib - root library folder
- ./test_scripts - testing scripts
- ./rspec - unit tests (RSpec)
-
-## Starting services
-
-Start Razor API with:
-
- cd $RAZOR_HOME/bin/node
- node razor.js
-
-
-## Notes
-
-Use the newest mongo ruby driver build as there is a bug with connect_timeout scoping error
-that hasn't been merged into available gem yet
-
-The fix below is assuming RVM as Ruby environment manager. If using global RVM gems make sure
-and 'rvm use ruby-1.9.3@global' before installing updated mongo driver.
-
- wget https://github.com/mongodb/mongo-ruby-driver/zipball/master
- unzip master
- cd mongodb-mongo-ruby-driver-99d9dfd/
- gem build mongo.gemspec
- gem install mongo-1.5.2.gem
View
@@ -83,6 +83,7 @@ function getConfig() {
}
// TODO Add catch for if razor.js is already running on port
+// Start our server if we can get a valid config
function startServer(json_config) {
config = JSON.parse(json_config);
if (config['@api_port'] != null) {
View
@@ -28,6 +28,7 @@ def load_slices
get_slices_loaded
end
+# Call the slice
def call_razor_slice
if is_slice?
razor_module = Object.full_const_get(SLICE_PREFIX + @namespace.capitalize).new(@args)
@@ -44,6 +45,7 @@ def call_razor_slice
end
end
+# Load slices
def get_slices_loaded
temp_hash = {}
ObjectSpace.each_object do
@@ -58,6 +60,7 @@ def get_slices_loaded
@slice_array = @slice_array.each_value.collect {|x| x}
end
+# Validate slice
def is_slice?
@slice_array.each { |slice| return true if @namespace.downcase == slice.downcase }
false
@@ -28,11 +28,12 @@ class Configuration
attr_accessor :checkin_offset
attr_accessor :register_timeout
+ # init
def initialize
use_defaults
end
-
+ # Set defaults
def use_defaults
@persist_mode = :mongo
@persist_host = "127.0.0.1"
@@ -41,7 +42,11 @@ def use_defaults
@admin_port = 8017
@api_port = 8026
- @logpath = "#{ENV['RAZOR_HOME']}/log/"
+ @logpath = "#{ENV['RAZOR_HOME']}/log"
+
+ @checkin_sleep = 60
+ @checkin_offset = 5
+ @register_timeout = 120
end
View
@@ -184,9 +184,9 @@ def reset_config
new_conf = Razor::Configuration.new
# Very important that we only write the file if it doesn't exist as we may not be the only thread using it
- if !File.exist?(CONFIG_PATH)
+ unless File.exist?(CONFIG_PATH)
begin
- new_conf_file = File.new(CONFIG_PATH,'w+')
+ new_conf_file = File.new(CONFIG_PATH, 'w+')
new_conf_file.write(("#{new_conf_header}#{YAML.dump(new_conf)}"))
new_conf_file.close
logger.info "Default config saved to (#{CONFIG_PATH})"
View
@@ -0,0 +1,24 @@
+# This adds Razor Common lib path to the load path for this child proc
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
+
+# Root Razor namespace
+# @author Nicholas Weaver
+module Razor
+
+ # Used for all event-driven commands and policy resolution
+ # @author Nicholas Weaver
+ class Engine
+
+ # TODO policy resolve
+
+
+ # TODO tag rules resolve
+
+
+
+
+
+
+
+ end
+end
View
@@ -1,23 +0,0 @@
-# This adds Razor Common lib path to the load path for this child proc
-$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
-
-require "object"
-
-module Razor
-class Model < Razor::Object
- attr_accessor :name
- attr_accessor :model_type
- attr_accessor :values_hash
-
-
- # @param hash [Hash]
- def initialize(hash)
- @name = nil
- @model_type = nil
- @values_hash = nil
- super()
- @_collection = :model
- from_hash(hash)
- end
-end
- end
View
@@ -3,23 +3,27 @@
require "object"
-# Razor class representing Nodes
-#noinspection RubyResolve
+# Root Razor namespace
+# @author Nicholas Weaver
module Razor
-class Node < Razor::Object
- attr_accessor :name
- attr_accessor :attributes_hash
- attr_accessor :timestamp
- attr_accessor :last_state
- attr_accessor :current_state
- attr_accessor :next_state
- # @param hash [Hash]
- def initialize(hash)
- super()
- @_collection = :node
- @attributes_hash = {}
- from_hash(hash)
+ # Root Razor::Node namespace
+ # @author Nicholas Weaver
+ class Node < Razor::Object
+ attr_accessor :name
+ attr_accessor :attributes_hash
+ attr_accessor :timestamp
+ attr_accessor :last_state
+ attr_accessor :current_state
+ attr_accessor :next_state
+
+ # init
+ # @param hash [Hash]
+ def initialize(hash)
+ super()
+ @_collection = :node
+ @attributes_hash = {}
+ from_hash(hash)
+ end
end
-end
end
View
@@ -4,7 +4,8 @@
require "utility"
require "logging"
-
+# Root Razor namespace
+# @author Nicholas Weaver
module Razor
# Common object for all base Razor objects
# @abstract
@@ -48,7 +49,7 @@ def update_self
true
end
-
+ # Get logger object
def get_logger
logger
end
View
@@ -0,0 +1,28 @@
+# This adds Razor Common lib path to the load path for this child proc
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
+
+require "object"
+
+# Root Razor namespace
+# @author Nicholas Weaver
+module Razor
+ # Root Model object
+ # @author Nicholas Weaver
+ # @abstract
+ class Model < Razor::Object
+ attr_accessor :name
+ attr_accessor :model_type
+ attr_accessor :values_hash
+
+ # init
+ # @param hash [Hash]
+ def initialize(hash)
+ @name = nil
+ @model_type = nil
+ @values_hash = nil
+ super()
+ @_collection = :model
+ from_hash(hash)
+ end
+ end
+end
@@ -3,7 +3,6 @@
require "configuration"
require "persist_database_mongo"
-require "model"
require "logging"
# Persistence Controller for Razor
@@ -7,6 +7,7 @@
# This adds Razor Common lib path to the load path for this child proc
$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
+# @author Nicholas Weaver
module Razor
module Persist
module Database
View
@@ -1,9 +1,14 @@
require "yaml"
+# Root Razor namespace
+# @author Nicholas Weaver
module Razor
+
+ # Razor::Utility namespace
+ # @author Nicholas Weaver
module Utility
- # returns a hash array of instance variable symbol and instance variable value for self
+ # Returns a hash array of instance variable symbol and instance variable value for self
# will ignore instance variables that start with '_'
def to_hash
hash = {}
@@ -15,8 +20,9 @@ def to_hash
hash
end
- # sets instance variables
+ # Sets instance variables
# will not include any that start with "_" (Mongo specific)
+ # @param [Hash] hash
def from_hash(hash)
hash.each_pair {|key, value| self.instance_variable_set(key,value) unless key.to_s.start_with?("_")}
end
@@ -29,6 +35,7 @@ def validate_instance_vars
end
# Returns the version number as [String] from ./conf/version
+ # @return [String]
def get_razor_version
file = File.open("#{ENV['RAZOR_HOME']}/conf/version", "rb")
version = file.read
Oops, something went wrong.

0 comments on commit f4d977b

Please sign in to comment.