diff options
| author | Greg Blomquist <gblomqui@redhat.com> | 2008-06-17 14:14:57 -0400 |
|---|---|---|
| committer | Greg Blomquist <gblomqui@redhat.com> | 2008-06-17 20:59:26 -0400 |
| commit | f0fa62e2d9cf46f8d2a972f63abfb3e00f040018 (patch) | |
| tree | 3d617bd81fe1d59d28827df40c62e4c73b5dc620 | |
| parent | 23b97b41b443457f875d504087571f8a01524540 (diff) | |
| download | tools-f0fa62e2d9cf46f8d2a972f63abfb3e00f040018.tar.gz tools-f0fa62e2d9cf46f8d2a972f63abfb3e00f040018.tar.xz tools-f0fa62e2d9cf46f8d2a972f63abfb3e00f040018.zip | |
Adding support for a "cloud" mode in everest-bootstrap
------------------------------------------------------
The "cloud" mode acts like the "wizard" in the standard mode of everest-bootstrap in that it asks relevant questions for provisioning a new machine.
After collecting the standard information, it registers the new system with cobbler and with everestd. It then asks everestd to koan the new machine.
Adding support to everestd to call func to koan a requested machine on the most suitable everest host
-----------------------------------------------------------------------------------------------------
Now everestd asks "cloud-inventory" which host/vol_group combination is the best fit for a particular machine. Then, everestd will delegate to
func to koan the new machine on the host/vol_group combination.
| -rw-r--r-- | everest-bootstrap/bin/everest-bootstrap | 118 | ||||
| -rw-r--r-- | everest-bootstrap/lib/everest-bootstrap/core.rb | 15 | ||||
| -rw-r--r-- | everest-bootstrap/lib/everest-bootstrap/version.rb | 2 | ||||
| -rw-r--r-- | everestd/config.example.yml | 2 | ||||
| -rw-r--r-- | everestd/lib/everestd.rb | 42 | ||||
| -rw-r--r-- | everestd/lib/everestd/version.rb | 2 |
6 files changed, 178 insertions, 3 deletions
diff --git a/everest-bootstrap/bin/everest-bootstrap b/everest-bootstrap/bin/everest-bootstrap index f76bd5a..7c00de7 100644 --- a/everest-bootstrap/bin/everest-bootstrap +++ b/everest-bootstrap/bin/everest-bootstrap @@ -178,4 +178,122 @@ Main { e.koan(params['virt-path'].value) if params["virt-path"].given? end end + + mode 'cloud' do + def collect_input + unless ENV['USER'] == 'root' || params["config-only"].given? + raise "You must run this command as root unless " + + "you specify the '--config-only' option" + end + + @facts = Hash.new + + @repo = ask("Enter your Everest repo machine name (leave off the '-repo'): ") + @user = ask("Enter your kerberos username: ") + + say_red("Your machine name is the part right before the Everest type.") + say_red("For example, 'sso1-build.usersys.redhat.com' has a machine name of 'sso1'.") + say_red("If you do not specify a machine name it will default to your kerberos name.") + + if agree("Enter machine name? (y/n)", true) + @machine_name = ask("Machine name: ") + else + @machine_name = @user + end + + # Once we know the repo we can fetch the supported machines + @everest_repo = EverestRepo.new(@repo) + say_red("To see a description of these machine types visit: " + + "#{@everest_repo.machine_types_url}") + + @machine_type = choose do |menu| + menu.prompt = "Select your machine type: " + menu.choices(*@everest_repo.machines.map{|m| m.name}) + end + + # This might be useful is we stop using DDNS + @facts["everest_machine_type"] = @machine_type + + if agree("Configure this machine with Red Hat DDNS? (y/n)", true) + # Our naming convention + hostname = @machine_name + "-" + @machine_type + @fqdn = hostname + ".usersys.redhat.com" + + if agree("Do you know the DDNS hash for this machine? (y/n)", true) + @facts["rh_ddns_hash"] = ask("Enter Red Hat DDNS hash: ") + else + @password = ask("Enter your kerberos password to setup DDNS: ") { |q| q.echo = "*" } + @facts["rh_ddns_hash"] = RedHatDDNS::DDNS.new(@user, @password, hostname).ddns_hash + end + else + @fqdn = ask("Enter fully qualified domain name for this machine: ") + end + + @facts["cobbler_profile"] = choose do |menu| + menu.prompt = "Select your cobbler profile (This determines the OS): " + menu.choices(*@everest_repo.cobbler_profiles) + end + + say_red("Now you need to enter some parameters what will be used to configure this machine.") + say_red("Most of the defaults will work out fine for development.") + + @everest_repo.facts_for(@machine_type, @machine_name).each do |f| + say_red("Description: #{f.desc}") unless f.desc.empty? + @facts[f.name] = ask("Enter value for #{f.name}: ") do |q| + q.default = f.default + end + end + + if agree("Enter addition facts? (y/n)", true) + begin + name = ask("Enter fact name: ") + value = ask("Enter fact value: ") + @facts[name] = value + end while agree("Enter another? ", true) + end + + say_red("The Koan process will start on the repo you selected.") + end + + def run + collect_input + + classes = @everest_repo.classes_for(@machine_type) + config = {"classes" => classes, "parameters" => @facts} + + @everest_repo.create_machine(@fqdn, config) + end + end + + mode 'cloud-advanced' do + option('fqdn', 'f'){ + required + description "Fully qualified domain name of machine to be provisioned" + argument_required + } + + option('repo', '-r'){ + required + description "Fully qualified domain name for the Everest repo machine to use for provisioning" + argument_required + } + + option('yaml', 'y'){ + description "YAML configuration for this machine" + argument_required + validate {|f| File.exist?(f)} + } + + def run + config = if params['yaml'].given? + YAML.load(File.read(params['yaml'].value)) + else + YAML.load($stdin.read) + end + + everest_repo = EverestRepo.new(params['repo'].value) + everest_repo.create_machine(params['fqdn'].value, config) + end + + end } diff --git a/everest-bootstrap/lib/everest-bootstrap/core.rb b/everest-bootstrap/lib/everest-bootstrap/core.rb index 6b380c8..c3f4c7c 100644 --- a/everest-bootstrap/lib/everest-bootstrap/core.rb +++ b/everest-bootstrap/lib/everest-bootstrap/core.rb @@ -88,6 +88,21 @@ module EverestBootstrap @cobblerd.call2('modify_system', system_id, 'ksmeta', ksmeta, @token) @cobblerd.call2('save_system', system_id, @token) end + + def koan(machine_fqdn) + Restr.post("#{@everestd}/koan", :machine_fqdn => machine_fqdn) + end + + def create_machine(machine_fqdn, config) + # 1. post the configuration + # 2. add system to cobbler + # 3. ask everestd to koan the machine + + machine_type = config["parameters"]["everest_machine_type"] + post_yaml(machine_fqdn, machine_type, YAML.dump(config)) + add_system_to_cobbler(machine_fqdn, config["parameters"]) + koan(machine_fqdn) + end end class EverestMachine diff --git a/everest-bootstrap/lib/everest-bootstrap/version.rb b/everest-bootstrap/lib/everest-bootstrap/version.rb index 95162e1..31f0f85 100644 --- a/everest-bootstrap/lib/everest-bootstrap/version.rb +++ b/everest-bootstrap/lib/everest-bootstrap/version.rb @@ -2,7 +2,7 @@ module EverestBootstrap module Version MAJOR = 0 MINOR = 4 - BUILD = 1 + BUILD = 2 STRING = [MAJOR, MINOR, BUILD].join(".") end diff --git a/everestd/config.example.yml b/everestd/config.example.yml index c03d8bb..e8287ae 100644 --- a/everestd/config.example.yml +++ b/everestd/config.example.yml @@ -84,5 +84,5 @@ port: 8106 log: level: DEBUG - file: /var/log/blog.log + file: /var/log/everestd.log # level: INFO diff --git a/everestd/lib/everestd.rb b/everestd/lib/everestd.rb index a357cc2..d763445 100644 --- a/everestd/lib/everestd.rb +++ b/everestd/lib/everestd.rb @@ -8,6 +8,7 @@ require 'rubygems' require 'picnic' require 'reststop' require 'everest' +require 'xmlrpc/client' Camping.goes :Everestd Everestd.picnic! @@ -105,6 +106,47 @@ module Everestd::Controllers redirect R(Nodes) end end + + class Koan < REST 'koan' + def _get_repo_fqdn + ENV['HOSTNAME'] + end + + # Retrieve the cobbler profile for the given profile name + def _get_cobbler_profile(name) + repo = _get_repo_fqdn + cobblerd = XMLRPC::Client.new2("http://#{repo}:25152") + token = cobblerd.call2("login", "cobbler", "password")[1] + return cobblerd.call2("get_profile", name, token)[1] + 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 `cloud-inventory -m #{ram} -d #{disk_size}`.split(':') + end + + def _get_machine_yaml(fqdn) + YAML.load_file("/etc/everest/nodes/#{fqdn}/node.yaml") + 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 = _get_repo_fqdn + `func \"#{host}\" call virt install #{repo} #{fqdn} True #{fqdn.split('.')[0]} #{vol_group}` + end + + # POST /koan + def create + machine_fqdn = input.machine_fqdn + yaml = _get_machine_yaml(machine_fqdn) + cobbler_profile = _get_cobbler_profile(yaml["parameters"]["cobbler_profile"]) + + host, vol_group = _get_best_host(cobbler_profile["virt_file_size"], cobbler_profile["virt_ram"]) + _koan(host, vol_group, machine_fqdn) + end + end end module Everestd::Views diff --git a/everestd/lib/everestd/version.rb b/everestd/lib/everestd/version.rb index e7a6c3a..9f493ff 100644 --- a/everestd/lib/everestd/version.rb +++ b/everestd/lib/everestd/version.rb @@ -2,7 +2,7 @@ module Everestd #:nodoc: module VERSION #:nodoc: MAJOR = 0 MINOR = 1 - TINY = 0 + TINY = 1 STRING = [MAJOR, MINOR, TINY].join('.') end |
