Class: Chef::Knife::XenserverSrCreate
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::XenserverSrCreate
- Includes:
- XenserverBase
- Defined in:
- lib/chef/knife/xenserver_sr_create.rb
Instance Method Summary collapse
Methods included from XenserverBase
#bytes_to_megabytes, #connection, included, #locate_config_value
Instance Method Details
#run ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/chef/knife/xenserver_sr_create.rb', line 45 def run sr_name = config[:sr_name] if not sr_name ui.error("Invalid Storage Repository name (--sr-name)") exit 1 end sr_type = config[:sr_type] if not sr_type ui.error("Invalid Storage Repository type (--sr-type)") exit 1 end sr_device = config[:sr_device] if not sr_device ui.error("Invalid Storage Repository device (--sr-device)") exit 1 end hosts = connection.hosts sr_host = config[:sr_host] if sr_host.nil? and hosts.size > 1 if not sr_host ui.error("More than one host found in the pool.") ui.error("--sr-host parameter is mandatory") exit 1 end end if sr_host # Find the host in the pool host = connection.hosts.find { |h| h.uuid == sr_host } else # We only have one hosts host = hosts.first end # The given host was not found in the pool if host.nil? ui.error "Host #{sr_host} not found in the pool" exit 1 end dconfig = { :device => sr_device } puts "Creating SR #{sr_name.yellow} in host #{host.name} (#{sr_type}, #{sr_device})..." vm = connection.storage_repositories.create :name => sr_name, :host => host, :device_config => dconfig, :type => sr_type end |