Class: Chef::Knife::VcVmSetDisks

Inherits:
Chef::Knife show all
Includes:
VcCommon, VcVmCommon
Defined in:
lib/chef/knife/vm/vc_vm_set_disks.rb

Instance Method Summary collapse

Methods included from VcVmCommon

#get_vm, included, #sanitize_guest_name, #stop_if_running

Methods included from VcCommon

#connection, #deprecation_msg, #generate_key, #get_password, included, #locate_config_value, #locate_org_option, #notice_msg, #out_msg, #pretty_symbol, #sort_by_key, #store_config, #store_password, #wait_task

Instance Method Details

#runObject

Raises:

  • (ArgumentError)


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
# File 'lib/chef/knife/vm/vc_vm_set_disks.rb', line 47

def run
  $stdout.sync = true

  vm_arg = @name_args.shift

  new_disk = locate_config_value(:vm_add_disk)
  delete_disk = locate_config_value(:vm_delete_disk)
  disk_name = locate_config_value(:vm_disk_name)
  disk_size = locate_config_value(:vm_disk_size)

  raise ArgumentError, "Disk name is mandatory if using --no-add" if !new_disk && disk_name.nil?
  raise ArgumentError, "Disk size is mandatory if using --add" if new_disk && disk_size.nil?
  raise ArgumentError, "Disk name is mandatory if using --delete" if delete_disk && disk_name.nil?

  connection.
  vm = get_vm(vm_arg)

  if !delete_disk || ui.confirm("Do you really want to #{ui.color('DELETE', :red)} disk #{disk_name}")
    task_id = connection.set_vm_disk_info vm[:id], {
                                                  :add => new_disk,
                                                  :delete => delete_disk,
                                                  :disk_size => disk_size,
                                                  :disk_name => disk_name
                                                }
    ui.msg "VM setting Disks info..."
    wait_task(connection, task_id)
  end
  connection.logout
end