Permalink
Browse files

Massive complete rewrite of almost everything in prep for making this…

… into a gem and realizing what a proper ruby structure looks like

Also linked the image svc config items to Node.js

Also contains the new client_config response for mk
  • Loading branch information...
1 parent b2c3c5c commit 7dc44e0ba1c42dcb61f6d225bb65d18dd32ee2fc @lynxbat lynxbat committed Mar 2, 2012
Showing with 1,311 additions and 1,393 deletions.
  1. +2 −9 .autotest
  2. +1 −0 Gemfile
  3. +1 −1 README.markdown
  4. +11 −10 bin/{node/razor_api.js → api.js}
  5. +16 −12 bin/{node/razor_image.js → image_svc.js}
  6. +19 −18 bin/razor
  7. 0 {images → image}/README
  8. 0 {images → image}/iso/README
  9. 0 {images → image}/media/README
  10. 0 {images → image}/mk/README
  11. +0 −61 lib/common/configuration.rb
  12. +0 −79 lib/common/engine/engine.rb
  13. +0 −32 lib/common/node.rb
  14. +0 −68 lib/common/object.rb
  15. +0 −215 lib/common/persist/database_mongo.rb
  16. +0 −27 lib/common/persist/database_object.rb
  17. +0 −37 lib/common/policy.rb
  18. +0 −99 lib/common/tagging/tag_rule.rb
  19. +0 −43 lib/models/model_base.rb
  20. +24 −0 lib/project_razor.rb
  21. +9 −0 lib/project_razor/config.rb
  22. +87 −0 lib/project_razor/config/server.rb
  23. +45 −57 lib/{common → project_razor}/data.rb
  24. +68 −0 lib/project_razor/engine.rb
  25. +5 −8 lib/{common → project_razor}/logging.rb
  26. +41 −0 lib/project_razor/model.rb
  27. +5 −10 lib/{models → project_razor/model}/ubuntu_oneiric.rb
  28. +24 −0 lib/project_razor/node.rb
  29. +63 −0 lib/project_razor/object.rb
  30. +12 −0 lib/project_razor/persist.rb
  31. +7 −12 lib/{common/persist/persist_controller.rb → project_razor/persist/controller.rb}
  32. +210 −0 lib/project_razor/persist/mongoplugin.rb
  33. +22 −0 lib/project_razor/policy.rb
  34. +12 −0 lib/project_razor/slice.rb
  35. +11 −10 lib/{slices/slice_base.rb → project_razor/slice/base.rb}
  36. +47 −0 lib/project_razor/slice/boot.rb
  37. +43 −0 lib/project_razor/slice/config.rb
  38. +62 −0 lib/project_razor/slice/model.rb
  39. +259 −0 lib/project_razor/slice/node.rb
  40. +4 −4 lib/{ → project_razor}/systems/system_base.rb
  41. +5 −5 lib/{ → project_razor}/systems/system_puppet.rb
  42. +3 −8 lib/{common → project_razor}/tagging/tag_matcher.rb
  43. +94 −0 lib/project_razor/tagging/tag_rule.rb
  44. +2 −7 lib/{common → project_razor}/utility.rb
  45. +0 −53 lib/slices/slice_boot.rb
  46. +0 −44 lib/slices/slice_config.rb
  47. +0 −68 lib/slices/slice_model.rb
  48. +0 −263 lib/slices/slice_node.rb
  49. +0 −28 lib/slices/slice_template.rb
  50. +59 −62 spec/common/rz_data_spec.rb
  51. +1 −1 spec/engine/rz_engine_spec.rb
  52. +20 −26 spec/persist/rz_persist_controller_spec.rb
  53. +1 −0 spec/{common → }/rz_rspec_matchers.rb
  54. +10 −10 spec/slice/rz_slice_node_spec.rb
  55. +4 −4 spec/tagging/rz_tagging_spec.rb
  56. +2 −2 start_node.sh
View
@@ -1,16 +1,9 @@
-
-
Autotest.add_hook(:initialize) {|at|
at.add_exception %r{^\.git} # ignore Version Control System
at.add_exception %r{^./tmp} # ignore temp files, lest autotest will run again, and again...
at.clear_mappings # take out the default (test/test*rb)
- #at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
- # Dir['spec/**/*_spec.rb']
- #}
-
at.add_mapping(%r{^lib/.*\.rb$}) {|f, _|
- Dir['spec/**/*_spec.rb']
- }
-
+ Dir['spec/**/*_spec.rb']
+ }
nil
}
View
@@ -13,3 +13,4 @@ gem "json"
gem "colored"
gem "bluepill"
gem "autotest"
+gem "redcarpet"
View
@@ -29,7 +29,7 @@ DevOps-style tool sets.
#### Mongo
-_todo_
+Requires MongoDB 2.0.X+
## Prereqs
@@ -1,9 +1,10 @@
// EMC Confidential Information, protected under EMC Bilateral Non-Disclosure Agreement.
// Copyright © 2012 EMC Corporation, All Rights Reserved
//
-// Node.js endpoint for Razor API
+// Node.js endpoint for ProjectRazor API
-var razor_bin = process.env.RAZOR_HOME + "/bin/razor -w"; // Set razor.rb path
+var razor_bin = __dirname+ "/razor -w"; // Set project_razor.rb path
+console.log(razor_bin);
var exec = require("child_process").exec; // create our exec object
var express = require('express'); // include our express libs
@@ -13,7 +14,7 @@ app.use(express.bodyParser()); // Enable body parsing for POST
// app.use(express.logger()); // Uncomment for logging to console
// Exception for boot API request
-app.get('/razor/api/boot*',
+app.get('/project_razor/api/boot*',
function(req, res) {
args = req.path.split("/");
args.splice(0,3);
@@ -29,7 +30,7 @@ app.get('/razor/api/boot*',
});
});
-app.get('/razor/api/*',
+app.get('/project_razor/api/*',
function(req, res) {
args = req.path.split("/");
args.splice(0,3);
@@ -47,7 +48,7 @@ app.get('/razor/api/*',
-app.post('/razor/api/*',
+app.post('/project_razor/api/*',
function(req, res) {
args = req.path.split("/");
args.splice(0,3);
@@ -70,10 +71,10 @@ app.get('/*',
case "/":
res.send('404 Error: Bad Request', 404);
break;
- case "/razor":
+ case "/project_razor":
res.send('404 Error: Bad Request(No module selected)', 404);
break;
- case "/razor/api":
+ case "/project_razor/api":
res.send('404 Error: Bad Request(No slice selected)', 404);
break;
default:
@@ -106,15 +107,15 @@ function getConfig() {
});
}
-// TODO Add catch for if razor.js is already running on port
+// TODO Add catch for if project_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) {
app.listen(config['@api_port']);
- console.log('Razor API Web Server started and listening on:%s', app.address().port);
+ console.log('ProjectRazor API Web Server started and listening on:%s', app.address().port);
} else {
- console.log("There is a problem with your Razor configuration. Cannot load config.")
+ console.log("There is a problem with your ProjectRazor configuration. Cannot load config.")
}
}
@@ -1,26 +1,28 @@
// EMC Confidential Information, protected under EMC Bilateral Non-Disclosure Agreement.
// Copyright © 2012 EMC Corporation, All Rights Reserved
//
-// Node.js Endpoint for Razor Image Service
+// Node.js Endpoint for ProjectRazor Image Service
-var memdisk = process.env.RAZOR_HOME + "/images/mk/memdisk";
-var mk_iso = process.env.RAZOR_HOME + "/images/mk/rz_mk-image.iso";
-var razor_bin = process.env.RAZOR_HOME + "/bin/razor -w"; // Set razor.rb path
+var memdisk;
+var mk_iso;
+
+var razor_bin = __dirname+ "/razor -w"; // Set project_razor.rb path
+console.log(razor_bin);
var exec = require("child_process").exec; // create our exec object
var express = require('express'); // include our express libs
fs = require('fs');
app = express.createServer(); // our express server
-app.get('/razor/image/mk',
+app.get('/project_razor/image/mk',
function(req, res) {
res.writeHead(200, {'Content-Type': 'application/octet-stream'});
var fileStream = fs.createReadStream(mk_iso);
fileStream.pipe(res);
});
-app.get('/razor/image/memdisk',
+app.get('/project_razor/image/memdisk',
function(req, res) {
console.log("Called");
res.writeHead(200, {'Content-Type': 'application/octet-stream'});
@@ -36,21 +38,23 @@ function getConfig() {
});
}
-// TODO Add catch for if razor.js is already running on port
+// TODO Add catch for if project_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);
+ var config = JSON.parse(json_config);
+ memdisk = config['@image_svc_path'] + "/mk/memdisk";
+ mk_iso = config['@image_svc_path'] + "/mk/" + config['@base_mk'] ;
+
if (config['@imagesvc_port'] != null) {
if (config['@base_mk'] != null) {
mk_iso = process.env.RAZOR_HOME + "/images/mk/" + config['@base_mk'];
}
-
-
app.listen(config['@imagesvc_port']);
- console.log('Razor Image Service Web Server started and listening on:%s', app.address().port);
+ console.log('ProjectRazor Image Service Web Server started and listening on:%s', app.address().port);
+ console.log('Default MK path: ' + mk_iso)
} else {
- console.log("There is a problem with your Razor configuration. Cannot load config.")
+ console.log("There is a problem with your ProjectRazor configuration. Cannot load config.")
}
}
View
@@ -3,32 +3,33 @@
# EMC Confidential Information, protected under EMC Bilateral Non-Disclosure Agreement.
# Copyright © 2012 EMC Corporation, All Rights Reserved
#
-# Primary control for Razor
+# Primary control for ProjectRazor
# Modules are dynamically loaded and accessed through corresponding namespace
-# Format will be 'razor [module namespace] [module args{}]'
+# Format will be 'project_razor [module namespace] [module args{}]'
#
-# This adds Razor Common lib path to the load path for this child proc
+# This adds ProjectRazor Common lib path to the load path for this child proc
-Dir.glob(ENV['RAZOR_HOME'] + '/lib/**/').each {|x| $LOAD_PATH << x} # adds Razor lib/dirs to load path
-
-MODULE_PATH = "#{ENV['RAZOR_HOME']}/lib/slices"
-SLICE_PREFIX = "Razor::Slice::"
-
-#require "logging"
+$lib_path = File.dirname(__FILE__).sub(/\/bin$/,"/lib")
+$LOAD_PATH.unshift($lib_path)
+require "project_razor"
require "extlib"
-require "object"
require "json"
+require "colored"
+
+
+MODULE_PATH = "#{$lib_path}/project_razor/slices"
+SLICE_PREFIX = "ProjectRazor::Slice::"
# Dynamically loads Modules from $RAZOR_HOME/lib/slices
def load_slices
- @obj = Razor::Object.new
+ @obj = ProjectRazor::Object.new
@version = @obj.get_razor_version
@logger = @obj.get_logger
- Dir.glob("#{MODULE_PATH}/*.{rb}") do |file|
- require "#{file}"
- end
+ #Dir.glob("#{MODULE_PATH}/*.{rb}") do |file|
+ # require "#{file}"
+ #end
get_slices_loaded
end
@@ -40,7 +41,7 @@ def call_razor_slice
razor_module.slice_call
else
if @web_command
- p JSON.dump({"slice" => "Razor::Slice", "result" => "InvalidSlice"})
+ p JSON.dump({"slice" => "ProjectRazor::Slice", "result" => "InvalidSlice"})
else
print_header
print "\n [#{@namespace.capitalize}] ".red
@@ -72,7 +73,7 @@ end
def print_header
- puts "\nRazor - #{@version}".bold.green
+ puts "\nProjectRazor - #{@version}".bold.green
puts "EMC Corporation".green
puts "\nLoaded slices:"
@@ -87,15 +88,15 @@ def print_header
end
print "\n"
puts "\n\tUsage: ".bold
- print "\n\trazor "
+ print "\n\tproject_razor "
print "[slice name] [command argument] [command argument]...\n\n".red
end
# Detects if running from command line
if $0 == __FILE__
load_slices
- #cli.get_logger.debug ("Razor CLI launched")
+ #cli.get_logger.debug ("ProjectRazor CLI launched")
@web_command = false
if ARGV.count > 0
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -1,61 +0,0 @@
-# EMC Confidential Information, protected under EMC Bilateral Non-Disclosure Agreement.
-# Copyright © 2012 EMC Corporation, All Rights Reserved
-
-Dir.glob(ENV['RAZOR_HOME'] + '/lib/**/').each {|x| $LOAD_PATH << x} # adds Razor lib/dirs to load path
-
-
-require "utility"
-
-# Root Razor namespace
-# @author Nicholas Weaver
-module Razor
- # This class represents the Razor configuration. It is stored persistently in './conf/razor.conf' and editing by the user
- # @author Nicholas Weaver
- class Configuration
-
- include(Razor::Utility)
-
- # (Symbol) representing the database plugin mode to use defaults to (:mongo)
- attr_accessor :persist_mode
- attr_accessor :persist_host
- attr_accessor :persist_port
- attr_accessor :persist_timeout
-
- attr_accessor :admin_port
- attr_accessor :api_port
- attr_accessor :imagesvc_port
-
- attr_accessor :checkin_sleep
- attr_accessor :checkin_offset
- attr_accessor :register_timeout
-
- attr_accessor :base_mk
-
- # init
- def initialize
- use_defaults
- end
-
- # Set defaults
- def use_defaults
- @persist_mode = :mongo
- @persist_host = "127.0.0.1"
- @persist_port = 27017
- @persist_timeout = 10
-
- @admin_port = 8025
- @api_port = 8026
- @imagesvc_port = 8027
-
- @checkin_sleep = 60
- @checkin_offset = 5
- @register_timeout = 120
-
- @base_mk = "rz_mk_dev-image.0.1.3.0.iso"
- @razor_ip = "127.0.0.1"
-
- end
-
-
- end
-end
@@ -1,79 +0,0 @@
-# EMC Confidential Information, protected under EMC Bilateral Non-Disclosure Agreement.
-# Copyright © 2012 EMC Corporation, All Rights Reserved
-
-Dir.glob(ENV['RAZOR_HOME'] + '/lib/**/').each {|x| $LOAD_PATH << x} # adds Razor lib/dirs to load path
-
-
-require "data"
-require "logging"
-
-# Root Razor namespace
-# @author Nicholas Weaver
-module Razor
-
- # Used for all event-driven commands and policy resolution
- # @author Nicholas Weaver
- class Engine
- include(Razor::Logging)
-
- def initialize
- @data = Razor::Data.new
- end
-
- # TODO policy resolve
-
-
- # TODO tag rules resolve
-
-
- def get_boot(uuid)
- logger.debug "Getting boot for uuid:#{uuid}"
-
-
- # Run tagging policies
- node_tagging(uuid)
-
-
- boot_script = ""
- boot_script << "#!ipxe\n"
- boot_script << "initrd http://192.168.99.10:8027/razor/image/mk\n"
- boot_script << "chain http://192.168.99.10:8027/razor/image/memdisk iso\n"
- boot_script
- end
-
-
-
- # TODO Tagging
-
-
- def node_tagging(uuid)
- node = @data.fetch_object_by_uuid(:node, uuid)
- tag_policy = @data.fetch_all_objects(:tagpolicy)
-
- # Iterate over each tag rule and process against node
-
-
-
- end
-
-
-
-
- # TODO Policy
-
- def node_policy
-
-
- end
-
-
- def mk_boot
-
-
- end
-
-
-
-
- end
-end
Oops, something went wrong.

0 comments on commit 7dc44e0

Please sign in to comment.