diff options
| author | Greg Blomquist <gblomqui@redhat.com> | 2008-06-19 11:26:41 -0400 |
|---|---|---|
| committer | Greg Blomquist <gblomqui@redhat.com> | 2008-06-19 11:26:41 -0400 |
| commit | 4f244d65c5c2e4ffb4b38e00baa5f83de89c20d8 (patch) | |
| tree | 3766d2acc9bab1e67f59265ddf65eaf11524b0eb /cloud/lib | |
| parent | 6589df757f98b386afda6bbb1b076577b96b8ae2 (diff) | |
| download | tools-4f244d65c5c2e4ffb4b38e00baa5f83de89c20d8.tar.gz tools-4f244d65c5c2e4ffb4b38e00baa5f83de89c20d8.tar.xz tools-4f244d65c5c2e4ffb4b38e00baa5f83de89c20d8.zip | |
Creating a "cloud controller" daemon to run on cloud machines and provision virtual machines within the cloud.
Updated everest-bootstrap to call the cloud controller when provisioning machines
Removed "koan" operations from everestd. Now everestd only knows how to register machines with everest and cobbler. Basically a rollback to its previous version.
Diffstat (limited to 'cloud/lib')
| -rw-r--r-- | cloud/lib/cloud.rb | 166 | ||||
| -rw-r--r-- | cloud/lib/cloud/version.rb | 9 |
2 files changed, 175 insertions, 0 deletions
diff --git a/cloud/lib/cloud.rb b/cloud/lib/cloud.rb new file mode 100644 index 0000000..70b4e19 --- /dev/null +++ b/cloud/lib/cloud.rb @@ -0,0 +1,166 @@ +$: << File.dirname(File.expand_path(__FILE__)) + +gem 'reststop', '~> 0.2' + +require 'yaml' +require 'fileutils' +require 'rubygems' +require 'picnic' +require 'reststop' +require 'everest' +require 'restr' +require 'xmlrpc/client' + +Camping.goes :Cloud +Cloud.picnic! + +module Cloud::Helpers + class Cobblerd + def initialize(repo) + @repo = repo + @xmlrpc = XMLRPC::Client.new2("http://#{@repo}:25152") + @token = @xmlrpc.call2("login", "cobbler", "password")[1] + end + + def _call(method, *args) + return @xmlrpc.call2(method, *args)[1] + end + + def distros + _call("get_distros", @token) + end + + def profiles + _call("get_profiles", @token) + end + + def systems + _call("get_systems", @token) + end + + def repos + _call("get_repos", @token) + end + + def distro(name) + _call("get_distro", name, @token) + end + + def distro_for_koan(name) + _call("get_distro_for_koan", name, @token) + end + + def profile(name) + _call("get_profile", name, @token) + end + + def profile_for_koan(name) + _call("get_profile_for_koan", name, @token) + end + + def system(name) + _call("get_system", name, @token) + end + + def system_for_koan(name) + _call("get_system_for_koan", name, @token) + end + + def repo(name) + _call("get_repo", name, @token) + end + + def repo_for_koan(name) + _call("get_repo_for_koan", name, @token) + end + + end +end + +module Cloud::Controllers + class Koan < REST 'koan' + # Retrieve the cobbler profile for the given profile name + def _get_cobbler_profile(system_name, repo) + cobblerd = Cloud::Helpers::Cobblerd.new(repo) + cobbler_system = cobblerd.system(system_name) + return cobblerd.profile(cobbler_system["profile"]) + end + + # Find the best host on which to create a VM that requires + # the given "disk_size" and "ram" + def _get_best_host(disk_size, ram) + return `func-find-resources -m #{ram} -d #{disk_size}`.split(':') + end + + # run the appropriate koan command to create the given "fqdn" + # on the given "host" and "vol_group" + def _koan(host, vol_group, fqdn, repo) + # Run the koan process + func_cmd = "func \"#{host}\" call virt install #{repo} #{fqdn} True #{fqdn.split('.')[0]} #{vol_group}" + puts `#{func_cmd}` + + # Make the new host autostart + func_cmd = "func \"#{host}\" call command run \"ln -s /etc/xen/#{fqdn.split('.')[0]} /etc/xen/auto/\"" + puts `#{func_cmd}` + end + + # POST /koan + def create + machine_fqdn = input.machine_fqdn + repo = input.repo + + cobbler_profile = _get_cobbler_profile(machine_fqdn, repo) + @host, vol_group = _get_best_host(cobbler_profile["virt_file_size"], cobbler_profile["virt_ram"]) + _koan(@host, vol_group, machine_fqdn, repo) + render :_koan + end + end +end + +module Cloud::Views + def initialize(*args) + super(*args) + @x = Builder::XmlMarkup.new(:indent => 1) + end + + module HTML + def layout + html do + head do + title 'Everest Cloud Controller' + #link :rel => 'stylesheet', :type => 'text/css', + #:href => self/'/styles.css', :media => 'screen' + end + body do + div.content do + self << yield + end + end + end + end + + def _koan + @host + end + end + default_format :HTML + + module YAML + CONTENT_TYPE = 'text/plain' + + def layout + yield + end + end + + module XML + def layout + yield + end + end +end + +# Required by picnic +def Cloud.create; end + +Cloud.start_picnic diff --git a/cloud/lib/cloud/version.rb b/cloud/lib/cloud/version.rb new file mode 100644 index 0000000..cf75a7b --- /dev/null +++ b/cloud/lib/cloud/version.rb @@ -0,0 +1,9 @@ +module Cloud #:nodoc: + module VERSION #:nodoc: + MAJOR = 0 + MINOR = 1 + TINY = 1 + + STRING = [MAJOR, MINOR, TINY].join('.') + end +end |
