Class: Chef::Knife::XapiVdiCreate
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::XapiVdiCreate
- Includes:
- XapiBase
- Defined in:
- lib/chef/knife/xapi_vdi_create.rb
Instance Attribute Summary
Attributes included from XapiBase
Instance Method Summary collapse
Methods included from XapiBase
#add_vif_by_name, #cleanup, #clear_vm_vifs, #color_kv, #create_vbd, #create_vdi, defaults, #destroy_vdi, #detach_vdi, #fail, #find_default_sr, #find_template, #generate_mac, #get_all_vdis, get_default, #get_guest_ip, #get_host_ref, #get_sr_by_name, #get_task_ref, #get_template, #get_vbd_by_uuid, #get_vbds_from_vdi, #get_vdi_by_name_label, #get_vdi_by_uuid, #h, included, #input_to_bytes, #locate_config_value, #print_record, #print_vdi_info, set_defaults, #start, #stop, #user_select, #wait_on_task, #xapi, #yes_no?
Instance Method Details
#run ⇒ Object
44 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 |
# File 'lib/chef/knife/xapi_vdi_create.rb', line 44 def run disk_name = @name_args[0] if disk_name.nil? puts "Error: No Disk Name specified..." puts "Usage: " + exit 1 end begin if locate_config_value(:xapi_sr) sr_ref = get_sr_by_name( locate_config_value(:xapi_sr) ) else sr_ref = find_default_sr end if sr_ref.nil? ui.error "SR specified not found or can't be used Aborting" end Chef::Log.debug "SR: #{h.color sr_ref, :cyan}" size = locate_config_value(:xapi_disk_size) vdi_record = { "name_label" => disk_name, "name_description" => "#{disk_name} created by #{ENV['USER']}", "SR" => sr_ref, "virtual_size" => input_to_bytes(size).to_s, "type" => "system", "sharable" => false, "read_only" => false, "other_config" => {}, } # Async create the VDI task = xapi.Async.VDI.create(vdi_record) ui.msg "waiting for VDI Create.." vdi_ref = get_task_ref(task) ui.msg "Disk Name: #{ h.color( disk_name, :bold, :cyan)}" ui.msg "Disk Size: #{ h.color( size.to_s, :bold, :cyan)}" end end |