Permalink
Browse files

Refactored the previous version of the Microkernel to add a new WEBri…

…ck instance that supports local loading of TCL extensions. Also removed the script that was previously used to load the kernel modules that might be contained in these extensions to support the loading of a list of kernel modules from the same WEBrick instance (this functionality is now provided by the RazorMicrokernel::RzMkKernelModuleManager class instead) and added the WEBrick instance itself (via the rz_mk_tce_mirror.rb script).
  • Loading branch information...
Tom McSweeney
Tom McSweeney committed May 9, 2012
1 parent 7c0f1bc commit d635b171004d80cb672cb946f5208a8f0266abaf
View

This file was deleted.

Oops, something went wrong.
View
@@ -1,8 +1,12 @@
---
mk_kmod_install_list_uri: http://localhost:2157/tinycorelinux/kmod-install-list
mk_register_path: /razor/api/node/register
mk_tce_mirror_uri: http://localhost:2157/tinycorelinux
mk_uri: http://RAZOR_URI_IP_ADDR:8026
mk_tce_mirror_port: 2157
mk_checkin_interval: 60
mk_checkin_path: /razor/api/node/checkin
mk_tce_install_list_uri: http://localhost:2157/tinycorelinux/tce-install-list
mk_checkin_skew: 5
mk_fact_excl_pattern: (^uptime.*$)|(^memory.*$)
mk_register_path: /razor/api/node/register
mk_uri: http://RAZOR_URI_IP_ADDR:8026
mk_fact_excl_pattern: (^facter.*$)|(^id$)|(^kernel.*$)|(^memoryfree$)|(^operating.*$)|(^osfamily$)|(^path$)|(^ps$)|(^ruby.*$)|(^selinux$)|(^ssh.*$)|(^swap.*$)|(^timezone$)|(^uniqueid$)|(^uptime.*$)|(.*json_str$)
mk_log_level: Logger::INFO
View
@@ -4,4 +4,3 @@
sudo /usr/local/etc/init.d/openssh start
sudo gem install --no-ri --no-rdoc /opt/gems/bundler-1.0.21.gem
sudo /usr/local/bin/rz_mk_init.rb
#sudo /usr/local/bin/load_kernel_modules.rb
@@ -25,9 +25,10 @@ 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
attr_reader :mk_tce_mirror_port
attr_reader :mk_tce_mirror_uri
attr_reader :mk_tce_install_list_uri
attr_reader :mk_kmod_install_list_uri
def initialize
@default_mk_log_level = Logger::INFO
@@ -79,9 +80,10 @@ 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']
@mk_tce_mirror_port = mk_conf['mk_tce_mirror_port']
@mk_tce_mirror_uri = mk_conf['mk_tce_mirror_uri']
@mk_tce_install_list_uri = mk_conf['mk_tce_install_list_uri']
@mk_kmod_install_list_uri = mk_conf['mk_kmod_install_list_uri']
end
end
@@ -0,0 +1,97 @@
# this is the RzMkKernelModuleManager class
#
# it manages the process of loading the appropriate kernel modules when the
# Microkernel boots. It uses the facts gathered by Facter to determine what sort
# of environment the Microkernel has been loaded into (virtual or not? if virtual,
# what sort of virtual environment is it?) to determine what, if any, additional
# kernel modules should be loaded when the system boots and loads those kernel
# modules. This script will be placed in the '/usr/local/bin' directory within
# the Microkernel and invoked from the '/opt/bootlocal.sh' script when the system
# boots
#
# EMC Confidential Information, protected under EMC Bilateral Non-Disclosure Agreement.
# Copyright © 2012 EMC Corporation, All Rights Reserved
#
# @author Tom McSweeney
require 'rubygems'
require 'facter'
require 'json'
require 'open-uri'
require 'singleton'
require 'razor_microkernel/logging'
require 'razor_microkernel/rz_mk_configuration_manager'
# 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 (will be combined
# with the other log messages for the Razor Microkernel Controller)
RZ_MK_LOG_PATH = "/var/log/rz_mk_controller.log"
module RazorMicrokernel
class RzMkKernelModuleManager
include Singleton
# include the RazorMicrokernel::Logging mixin (which enables logging)
include RazorMicrokernel::Logging
def initialize
@vmware_open_vm_tools_mods = %W[vmblock vmsync vmci vmxnet vmhgfs]
end
def load_kernel_modules
# get a reference to the Configuration Manager instance (a singleton)
config_manager = (RazorMicrokernel::RzMkConfigurationManager).instance
# if the config file exists and if the kmod_install_list_uri property exists in the configuration,
# and if that property actually is a URI, then continue
kmod_install_list_uri = config_manager.mk_kmod_install_list_uri
if config_manager.config_file_exists? && kmod_install_list_uri && !(kmod_install_list_uri =~ URI::regexp).nil?
kernel_module_root = "/lib/modules/#{%x[uname -r].strip}/kernel/"
install_list_uri = URI.parse(kmod_install_list_uri)
vm_kernel_module_map = {}
begin
vm_kernel_module_map = JSON::parse(install_list_uri.read)
logger.debug "received a TCE install list of '#{vm_kernel_module_map.inspect}'"
rescue => e
logger.debug "error while reading from '#{install_list_uri}' => #{e.message}"
return
end
vm_kernel_modules = vm_kernel_module_map['kmod_list']
#vm_kernel_modules = %W[fs/vmblock/vmblock.ko drivers/misc/vmsync.ko
# drivers/misc/vmci.ko drivers/net/vmxnet.ko fs/vmhgfs/vmhgfs.ko]
modules_changed = false
changed_modules = []
lsmod_output = %x[sudo lsmod]
vm_kernel_modules.each { |module_subpath|
module_name = module_subpath.split("/")[-1].split('.')[0]
name_plus_path = kernel_module_root + module_subpath
module_regexp = Regexp.new(module_name)
module_loaded = module_regexp.match(lsmod_output)
is_open_vm_mod = @vmware_open_vm_tools_mods.include?(module_name)
# if it's an open-vm-tools module but it's not a VMware-based virtual
# environment, then remove that kernel module from the kernel, otherwise
# install the module
if is_open_vm_mod && (!Facter.is_virtual || !Facter.virtual == 'vmware')
if module_loaded
logger.debug "Removing module: #{module_name}"
%x[sudo rmmod #{name_plus_path}] unless !mod_info || mod_info.length == 0
changed_modules << module_name + "-"
modules_changed = true unless modules_changed
end
else
logger.debug "Installing module: #{module_name}"
%x[sudo insmod #{name_plus_path}]
changed_modules << module_name + "+"
modules_changed = true unless modules_changed
end
}
if modules_changed
logger.info "Modules changed: #{changed_modules.join(", ")}"
%x[sudo depmod -a]
end
end
end
end
end
View
@@ -13,7 +13,6 @@
require 'rubygems'
#require 'logger'
require 'net/http'
require 'uri'
require 'open-uri'
require 'json'
require 'yaml'
@@ -22,6 +21,7 @@
require 'razor_microkernel/rz_mk_registration_manager'
require 'razor_microkernel/rz_mk_fact_manager'
require 'razor_microkernel/rz_mk_configuration_manager'
require 'razor_microkernel/rz_mk_kernel_module_manager'
# this method is used to load a list of Tiny Core Linux extensions
# as the Microkernel Controller is starting up (or restarting).
@@ -35,21 +35,21 @@
# extensions (those already installed) should be overwritten with new versions
# from the mirror (defaults to false, which skips the installation of any
# extensions that are already installed)
def load_tcl_extensions(tcl_ext_list_uri, tcl_ext_mirror_uri, force_reinstall = false)
def load_tcl_extensions(tce_install_list_uri, tce_mirror_uri, force_reinstall = false)
# 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)
return if !tcl_ext_list_uri || (tcl_ext_list_uri =~ URI::regexp).nil?
# get the URI from the config that will return 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)
return if !tce_install_list_uri || (tce_install_list_uri =~ URI::regexp).nil?
# and get the TCL mirror URI from the config, if it doesn't exist, then
# and get the TCE 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)
return if !tcl_ext_mirror_uri || (tcl_ext_mirror_uri =~ URI::regexp).nil?
return if !tce_mirror_uri || (tce_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
file.puts tce_mirror_uri
}
# get a list of the Tiny Core Extensions that are already installed in the
@@ -61,7 +61,17 @@ def load_tcl_extensions(tcl_ext_list_uri, tcl_ext_mirror_uri, force_reinstall =
# be obtained from a local 'mirror' containing the appropriate 'tcz' files)
begin
# load the list of extensions to install from the URI
ext_list_array = YAML::load(open(tcl_ext_list_uri))
install_list_uri = URI.parse(tce_install_list_uri)
tce_install_list_map = {}
begin
tce_install_list_map = JSON::parse(install_list_uri.read)
logger.debug("received a TCE install list of '#{tce_install_list_map.inspect}'")
rescue => e
logger.debug("error while reading from '#{install_list_uri}' => #{e.message}")
return
end
ext_list_array = tce_install_list_map['extension_list']
logger.debug("TCE install list: '#{ext_list_array.inspect}'")
# for each extension on that list, load that extension (using the
# 'tcl-load' command)
@@ -71,11 +81,12 @@ def load_tcl_extensions(tcl_ext_list_uri, tcl_ext_mirror_uri, force_reinstall =
next if !force_reinstall && installed_extensions.include?(extension.gsub(/.tcz$/,''))
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
# and load the kernel modules (if any), first get a reference to the Configuration
# Manager instance (a singleton)
kernel_mod_manager = (RazorMicrokernel::RzMkKernelModuleManager).instance
kernel_mod_manager.load_kernel_modules
rescue => e
@@ -145,7 +156,7 @@ def load_tcl_extensions(tcl_ext_list_uri, tcl_ext_mirror_uri, force_reinstall =
exclude_pattern, fact_manager)
# and load the TCL extensions from the configuration file (if any exist)
load_tcl_extensions(config_manager.mk_ext_list_uri, config_manager.mk_ext_mirror_uri)
load_tcl_extensions(config_manager.mk_tce_install_list_uri, config_manager.mk_tce_mirror_uri)
else
View
@@ -65,9 +65,10 @@
rz_host_util = RazorMicrokernel::RzHostUtils.new
rz_host_util.set_host_name
# next, start the rz_mk_web_server and rz_mk_controller scripts
# next, start the rz_mk_web_server, rz_mk_tce_mirror and rz_mk_controller scripts
%x[sudo usr/local/bin/rz_mk_web_server.rb 2>&1 > /tmp/rz_web_server.out]
%x[sudo usr/local/bin/rz_mk_tce_mirror.rb 2>&1 > /tmp/rz_mk_tce_mirror.out]
%x[sudo /usr/local/bin/rz_mk_controller.rb start]
# and start up the MCollective daemon
View
@@ -0,0 +1,82 @@
#!/usr/bin/env ruby
# this is rz_mk_control_server.rb
# it starts up a WEBrick server that can be used to control the Microkernel
# (commands to the Microkernel are invoked using Servlets running in the
# WEBrick instance)
#
# EMC Confidential Information, protected under EMC Bilateral Non-Disclosure Agreement.
# Copyright © 2012 EMC Corporation, All Rights Reserved
#
# @author Tom McSweeney
require 'rubygems'
require 'yaml'
require 'net/http'
require 'cgi'
require 'json'
require 'webrick'
require 'webrick/httpstatus'
require 'razor_microkernel/logging'
# include the WEBrick mixin (makes this into a WEBrick server instance)
include WEBrick
# next, define our actions (as servlets)...
class TceInstallListServlet < HTTPServlet::AbstractServlet
def do_GET(req, res)
# create a new HTTP Response
config = WEBrick::Config::HTTP
extension_list = YAML::load(File.open('/tmp/tinycorelinux/tce-install-list.yaml'))
return_str = JSON.generate({:extension_list => extension_list})
logger.info "Returning JSON string '#{return_str}' to user"
res.content_type = 'application/json'
res.content_length = return_str.length
res.body = return_str
res.status = 200
end
end
class KmodInstallListServlet < HTTPServlet::AbstractServlet
def do_GET(req, res)
# create a new HTTP Response
config = WEBrick::Config::HTTP
kmod_list = YAML::load(File.open('/tmp/tinycorelinux/kmod-install-list.yaml'))
return_str = JSON.generate({:kmod_list => kmod_list})
logger.info "Returning JSON string '#{return_str}' to user"
res.content_type = 'application/json'
res.content_length = return_str.length
res.body = return_str
res.status = 200
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_tce_mirror.log"
# include the RazorMicrokernel::Logging mixin (which enables logging)
include RazorMicrokernel::Logging
# Now, create an HTTP Server instance (and Daemonize it)
s = HTTPServer.new(:Port => 2157, :Logger => logger, :ServerType => WEBrick::Daemon)
# mount our servlets as directories under our HTTP server's URI
s.mount("/tinycorelinux/4.x/x86/tcz", HTTPServlet::FileHandler, "/tmp/tinycorelinux/4.x/x86/tcz")
s.mount("/tinycorelinux/tce-install-list", TceInstallListServlet)
s.mount("/tinycorelinux/kmod-install-list", KmodInstallListServlet)
# setup the server to shut down if the process is shut down
trap("INT"){ s.shutdown }
# and start out server
s.start
Oops, something went wrong.

0 comments on commit d635b17

Please sign in to comment.