Permalink
Browse files

Last round of changes for initial release of the Microkernel that wil…

…l dynamically load extensions (and the kernel modules they contain, at least for the open_vm_tools extension) from a (Razor) server. Have tested this with an Apache server, now just need to finish the Razor server-side code to support this implementation.
  • Loading branch information...
Tom McSweeney
Tom McSweeney committed May 8, 2012
1 parent ebd70c3 commit 75e9de50b428a068dc026567bb9907512a8d733a
@@ -25,6 +25,9 @@ class RzMkConfigurationManager
# 'Logger::INFO', or 'Logger::DEBUG' (default is 'Logger::ERROR')
attr_reader :mk_log_level
attr_reader :default_mk_log_level
attr_reader :mk_ext_mirror_port
attr_reader :mk_ext_mirror_uri
attr_reader :mk_ext_list_uri
def initialize
@default_mk_log_level = Logger::INFO
@@ -76,6 +79,9 @@ def set_current_config(mk_conf)
else
@mk_log_level = default_mk_log_level
end
@mk_ext_mirror_port = mk_conf['mk_ext_mirror_port']
@mk_ext_mirror_uri = mk_conf['mk_ext_mirror_uri']
@mk_ext_list_uri = mk_conf['mk_ext_list_uri']
end
end
@@ -439,16 +439,19 @@ def parse_array_value_set(parse_array, start_idx)
# any characters that could cause problems later on...i.e. any characters from following
# string: "!@#\$%\^&*()=+\[\]\{\}"
def clean_fact_map_keys!(facts_map)
facts_map.each { |key|
facts_map.each { |key, value|
# search each key to see if there any offending characters
# (if so, we'll refer to the key as an "offending key", below)
if /[!@#\$%\^&*()=+\[\]\{\}]/ =~ key
key_str = key.to_s
if /[!@#\$%\^&*()=+\[\]\{\}]/ =~ key_str
# if there is a match, then we'll create a new entry in the map using a
# "cleansed" key (i.e. a key with all of the offending characters removed),
# store the old value under the new key, and and remove the old key-value pair
# that stored the same data under the offending key
facts_map[key.gsub(/[!@#\$%\^&*()=+\[\]\{\}]/,"")] = facts_map[key]
new_key = key_str.gsub(/[!@#\$%\^&*()=+\[\]\{\}]/,"")
facts_map[new_key.to_sym] = value
facts_map.delete(key)
logger.debug("offending key '#{key_str}' changed to #{new_key}")
end
}
end
View
@@ -13,6 +13,8 @@
require 'rubygems'
#require 'logger'
require 'net/http'
require 'uri'
require 'open-uri'
require 'json'
require 'yaml'
require 'facter'
@@ -21,6 +23,50 @@
require 'razor_microkernel/rz_mk_fact_manager'
require 'razor_microkernel/rz_mk_configuration_manager'
def load_tcl_extensions(config_manager)
# get the URI from the config that points to the YAML file containing
# the list of TCL extensions that we should load, if it doesn't exist,
# then just return (because we don't have any extensions to load)
tcl_ext_list_uri = config_manager.mk_ext_list_uri
return if !tcl_ext_list_uri || (tcl_ext_list_uri =~ URI::regexp).nil?
# and get the TCL mirror URI from the config, if it doesn't exist, then
# we just return (because we don't know where to get the extensions from)
tcl_ext_mirror_uri = config_manager.mk_ext_mirror_uri
return if !tcl_ext_mirror_uri || (tcl_ext_mirror_uri =~ URI::regexp).nil?
# modify the /opt/tcemirror file (so that it uses the mirror given in the
# configuration we just received from the Razor server)
File.open('/opt/tcemirror', 'w') { |file|
file.puts tcl_ext_mirror_uri
}
# get the list of 'TCL Extensions' that should be installed (these will)
# be obtained from a local 'mirror' containing the appropriate 'tcz' files)
begin
ext_list_array = YAML::load(open(tcl_ext_list_uri))
# each extension on that list, load that extension (using the tcl-load command)
has_kernel_modules = false
ext_list_array.each { |extension|
logger.debug "loading #{extension}"
t = %x[sudo -u tc tce-load -iw #{extension}]
has_kernel_modules = true if /open_vm_tools/.match(extension)
}
# if any of the extensions contained kernel modules, then load those kernel modules
%x[sudo /usr/local/bin/load_kernel_modules.rb] if has_kernel_modules
rescue => e
logger.error e.message
end
end
# set up a global variable that will be used in the RazorMicrokernel::Logging mixin
# to determine where to place the log messages from this script
RZ_MK_LOG_PATH = "/var/log/rz_mk_controller.log"
@@ -80,6 +126,9 @@
registration_manager = RazorMicrokernel::RzMkRegistrationManager.new(registration_uri,
exclude_pattern, fact_manager)
# and load the TCL extensions from the configuration file (if any exist)
load_tcl_extensions(config_manager)
else
checkin_uri = nil

0 comments on commit 75e9de5

Please sign in to comment.