Class: Chef::Knife::VcVmSetInfo

Inherits:
Chef::Knife show all
Includes:
VcCommon, VcVmCommon
Defined in:
lib/chef/knife/vm/vc_vm_set_info.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

#rename_vm(connection, vm, vm_name) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/chef/knife/vm/vc_vm_set_info.rb', line 76

def rename_vm(connection, vm, vm_name)
  ui.msg "Renaming VM from #{vm[:vm_name]} to #{vm_name}"
  task_id = connection.rename_vm vm[:id], vm_name
  result = wait_task(connection, task_id)

  return unless result && locate_config_value(:override_guest_name)

  # Change also its guest computer name
  guest_config = {:enabled => true}

  # Inheriting admin_passwd if enabled
  if vm[:guest_customizations][:admin_passwd_enabled]
    guest_config[:admin_passwd] = vm[:guest_customizations][:admin_passwd]
  end

  stop_if_running(connection, vm)

  guest_name = sanitize_guest_name(vm_name)

  ui.msg "Renaming guest name to #{guest_name}..."
  task_id, response = connection.set_vm_guest_customization vm[:id], guest_name, guest_config

  wait_task(connection, task_id)

  ui.msg "Forcing Guest Customization..."
  task_id = connection.force_customization_vm vm[:id]
  wait_task(connection, task_id)
end

#runObject



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

def run
  $stdout.sync = true

  vm_arg = @name_args.first
  cpus = locate_config_value(:vm_cpus_number)
  ram = locate_config_value(:vm_ram)
  vm_name = locate_config_value(:vm_name)

  connection.

  vm = get_vm(vm_arg)

  if cpus
    task_id = connection.set_vm_cpus vm[:id], cpus
    ui.msg "VM setting CPUs info..."
    wait_task(connection, task_id)
  end

  if ram
    task_id = connection.set_vm_ram vm[:id], ram
    ui.msg "VM setting RAM info..."
    wait_task(connection, task_id)
  end

  if vm_name
    rename_vm(connection, vm, vm_name)
  end

  connection.logout
end