knife-vsphere 2.1.1 → 2.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +5 -5
  2. data/lib/chef/knife/base_vsphere_command.rb +69 -70
  3. data/lib/chef/knife/customization_helper.rb +4 -4
  4. data/lib/chef/knife/search_helper.rb +16 -7
  5. data/lib/chef/knife/vsphere_cluster_list.rb +8 -8
  6. data/lib/chef/knife/vsphere_cpu_ratio.rb +4 -4
  7. data/lib/chef/knife/vsphere_customization_list.rb +3 -3
  8. data/lib/chef/knife/vsphere_datastore_file.rb +17 -17
  9. data/lib/chef/knife/vsphere_datastore_list.rb +11 -11
  10. data/lib/chef/knife/vsphere_datastore_maxfree.rb +14 -14
  11. data/lib/chef/knife/vsphere_datastorecluster_list.rb +7 -7
  12. data/lib/chef/knife/vsphere_datastorecluster_maxfree.rb +10 -10
  13. data/lib/chef/knife/vsphere_folder_list.rb +4 -4
  14. data/lib/chef/knife/vsphere_hosts_list.rb +10 -10
  15. data/lib/chef/knife/vsphere_pool_list.rb +5 -5
  16. data/lib/chef/knife/vsphere_pool_query.rb +7 -7
  17. data/lib/chef/knife/vsphere_pool_show.rb +8 -8
  18. data/lib/chef/knife/vsphere_template_list.rb +7 -7
  19. data/lib/chef/knife/vsphere_vlan_create.rb +8 -8
  20. data/lib/chef/knife/vsphere_vlan_list.rb +3 -3
  21. data/lib/chef/knife/vsphere_vm_cdrom.rb +27 -27
  22. data/lib/chef/knife/vsphere_vm_clone.rb +224 -214
  23. data/lib/chef/knife/vsphere_vm_config.rb +6 -6
  24. data/lib/chef/knife/vsphere_vm_delete.rb +17 -17
  25. data/lib/chef/knife/vsphere_vm_disk_extend.rb +11 -11
  26. data/lib/chef/knife/vsphere_vm_disk_list.rb +6 -6
  27. data/lib/chef/knife/vsphere_vm_execute.rb +14 -14
  28. data/lib/chef/knife/vsphere_vm_find.rb +87 -87
  29. data/lib/chef/knife/vsphere_vm_list.rb +12 -12
  30. data/lib/chef/knife/vsphere_vm_markastemplate.rb +5 -5
  31. data/lib/chef/knife/vsphere_vm_migrate.rb +20 -25
  32. data/lib/chef/knife/vsphere_vm_move.rb +17 -17
  33. data/lib/chef/knife/vsphere_vm_net.rb +8 -8
  34. data/lib/chef/knife/vsphere_vm_network_add.rb +22 -24
  35. data/lib/chef/knife/vsphere_vm_network_delete.rb +8 -8
  36. data/lib/chef/knife/vsphere_vm_network_list.rb +5 -5
  37. data/lib/chef/knife/vsphere_vm_network_set.rb +10 -10
  38. data/lib/chef/knife/vsphere_vm_property_get.rb +7 -7
  39. data/lib/chef/knife/vsphere_vm_property_set.rb +16 -16
  40. data/lib/chef/knife/vsphere_vm_show.rb +8 -8
  41. data/lib/chef/knife/vsphere_vm_snapshot.rb +35 -35
  42. data/lib/chef/knife/vsphere_vm_state.rb +31 -31
  43. data/lib/chef/knife/vsphere_vm_toolsconfig.rb +11 -11
  44. data/lib/chef/knife/vsphere_vm_vmdk_add.rb +32 -32
  45. data/lib/chef/knife/vsphere_vm_vnc_set.rb +15 -15
  46. data/lib/chef/knife/vsphere_vm_wait_sysprep.rb +10 -11
  47. data/lib/knife-vsphere/version.rb +1 -1
  48. metadata +5 -89
@@ -2,23 +2,23 @@
2
2
  # Author:: Ezra Pagel (<ezra@cpan.org>)
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
- require 'chef/knife'
6
- require 'chef/knife/base_vsphere_command'
5
+ require "chef/knife"
6
+ require "chef/knife/base_vsphere_command"
7
7
 
8
8
  # Lists all known virtual machines in the configured datacenter
9
9
  class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
10
- banner 'knife vsphere vm list'
10
+ banner "knife vsphere vm list"
11
11
 
12
12
  common_options
13
13
 
14
14
  option :recursive,
15
- long: '--recursive',
16
- short: '-r',
17
- description: 'Recurse into sub-folders'
15
+ long: "--recursive",
16
+ short: "-r",
17
+ description: "Recurse into sub-folders"
18
18
 
19
19
  option :onlyfolders,
20
- long: '--only-folders',
21
- description: 'List only the folders found',
20
+ long: "--only-folders",
21
+ description: "List only the folders found",
22
22
  boolean: false
23
23
 
24
24
  def traverse_folders(folder, is_top = false, recurse = false, only_folders = false)
@@ -44,11 +44,11 @@ class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
44
44
  def print_vm(vm)
45
45
  state = case vm.runtime.powerState
46
46
  when PS_ON
47
- ui.color('on', :green)
47
+ ui.color("on", :green)
48
48
  when PS_OFF
49
- ui.color('off', :red)
49
+ ui.color("off", :red)
50
50
  when PS_SUSPENDED
51
- ui.color('suspended', :yellow)
51
+ ui.color("suspended", :yellow)
52
52
  end
53
53
  puts "\t#{ui.color('VM Name:', :cyan)} #{vm.name}"
54
54
  puts "\t\t#{ui.color('IP:', :magenta)} #{vm.guest.ipAddress}"
@@ -57,7 +57,7 @@ class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
57
57
  end
58
58
 
59
59
  def print_folder(folder)
60
- puts "#{ui.color('Folder', :cyan)}: " + (folder.path[3..-1].map { |x| x[1] }.* '/')
60
+ puts "#{ui.color('Folder', :cyan)}: " + (folder.path[3..-1].map { |x| x[1] }.* "/")
61
61
  end
62
62
 
63
63
  def run
@@ -6,9 +6,9 @@
6
6
  # License:: Apache License, Version 2.0
7
7
  #
8
8
 
9
- require 'chef/knife'
10
- require 'chef/knife/base_vsphere_command'
11
- require 'chef/knife/search_helper'
9
+ require "chef/knife"
10
+ require "chef/knife/base_vsphere_command"
11
+ require "chef/knife/search_helper"
12
12
 
13
13
  # Clone an existing template into a new VM, optionally applying a customization specification.
14
14
  # usage:
@@ -16,7 +16,7 @@ require 'chef/knife/search_helper'
16
16
  # Vspherevmmarkastemplate extends the Basevspherecommand
17
17
  class Chef::Knife::VsphereVmMarkastemplate < Chef::Knife::BaseVsphereCommand
18
18
  include SearchHelper
19
- banner 'knife vsphere vm markastemplate VMNAME'
19
+ banner "knife vsphere vm markastemplate VMNAME"
20
20
 
21
21
  common_options
22
22
 
@@ -28,7 +28,7 @@ class Chef::Knife::VsphereVmMarkastemplate < Chef::Knife::BaseVsphereCommand
28
28
  vmname = @name_args[0]
29
29
  if vmname.nil?
30
30
  show_usage
31
- fatal_exit('You must specify a virtual machine name')
31
+ fatal_exit("You must specify a virtual machine name")
32
32
  end
33
33
 
34
34
  vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
@@ -2,58 +2,53 @@
2
2
  # Author:: Raducu Deaconu (<rhadoo_io@yahoo.com>)
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
- require 'chef/knife'
6
- require 'chef/knife/base_vsphere_command'
7
- require 'chef/knife/search_helper'
5
+ require "chef/knife"
6
+ require "chef/knife/base_vsphere_command"
7
+ require "chef/knife/search_helper"
8
8
 
9
9
  # migrate vm to specified resource pool , datastore and host
10
10
  class Chef::Knife::VsphereVmMigrate < Chef::Knife::BaseVsphereCommand
11
11
  include SearchHelper
12
12
  # migrate --resource-pool --dest-host --dest-datastore
13
- banner 'knife vsphere vm migrate (options)'
13
+ banner "knife vsphere vm migrate VMNAME (options)"
14
14
 
15
15
  common_options
16
16
 
17
17
  option :dest_host,
18
- long: '--dest-host HOST',
19
- description: 'Destination host for the VM or template'
18
+ long: "--dest-host HOST",
19
+ description: "Destination host for the VM or template"
20
20
 
21
21
  option :dest_datastore,
22
- long: '--dest-datastore DATASTORE',
23
- description: 'The destination datastore'
22
+ long: "--dest-datastore DATASTORE",
23
+ description: "The destination datastore"
24
24
 
25
25
  option :priority,
26
- long: '--priority PRIORITY',
27
- description: 'migration priority'
26
+ long: "--priority PRIORITY",
27
+ description: "migration priority"
28
28
 
29
29
  option :resource_pool,
30
- long: '--resource-pool POOL',
31
- description: 'The resource pool into which to put the VM'
32
-
33
- def find_host_folder(folder, name)
34
- folder.childEntity.each do |cluster|
35
- cluster.host.each do |host|
36
- return host if host.name == name
37
- end
38
- end
39
- nil
40
- end
30
+ long: "--resource-pool POOL",
31
+ description: "The resource pool into which to put the VM"
41
32
 
42
33
  def run
43
34
  $stdout.sync = true
44
35
  vmname = @name_args[0]
45
36
  if vmname.nil?
46
37
  show_usage
47
- fatal_exit('You must specify a virtual machine name')
38
+ fatal_exit("You must specify a virtual machine name")
48
39
  end
49
40
 
50
41
  vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
51
42
 
52
43
  priority = config[:priority]
53
- dest_host = config[:dest_host]
54
- ndc = find_datastore(config[:dest_datastore]) || abort('dest-datastore not found')
44
+ dest_host = get_vm_host_by_name(config[:dest_host]) if config[:dest_host]
45
+ ndc = find_datastore(config[:dest_datastore]) if config[:dest_datastore]
55
46
  pool = find_pool(config[:resource_pool]) if config[:resource_pool]
56
- dest_host = find_host_folder(datacenter.hostFolder, dest_host)
47
+
48
+ unless dest_host || ndc || pool
49
+ fatal_exit("You need to specify one or more of --dest-host, --dest-datastore, or --resource-pool")
50
+ end
51
+
57
52
  migrate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(datastore: ndc, pool: pool, host: dest_host)
58
53
  vm.RelocateVM_Task(spec: migrate_spec, priority: priority).wait_for_completion
59
54
  end
@@ -2,39 +2,39 @@
2
2
  # Author:: Brian Dupras (<bdupras@rallydev.com>)
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
- require 'chef/knife'
6
- require 'chef/knife/base_vsphere_command'
7
- require 'chef/knife/search_helper'
5
+ require "chef/knife"
6
+ require "chef/knife/base_vsphere_command"
7
+ require "chef/knife/search_helper"
8
8
 
9
- # Lists all known virtual machines in the configured datacenter
9
+ # Moves the VM to another folder or datastore
10
10
  # VsphereVmMove extends the BaseVspherecommand
11
11
  class Chef::Knife::VsphereVmMove < Chef::Knife::BaseVsphereCommand
12
12
  include SearchHelper
13
- banner 'knife vsphere vm move'
13
+ banner "knife vsphere vm move VMNAME"
14
14
 
15
15
  common_options
16
16
 
17
17
  option :dest_name,
18
- long: '--dest-name NAME',
19
- short: '-r',
20
- description: 'Destination name of the VM or template'
18
+ long: "--dest-name NAME",
19
+ short: "-r",
20
+ description: "Destination name of the VM or template"
21
21
 
22
22
  option :dest_folder,
23
- long: '--dest-folder FOLDER',
24
- description: 'The destination folder into which the VM or template should be moved'
23
+ long: "--dest-folder FOLDER",
24
+ description: "The destination folder into which the VM or template should be moved"
25
25
 
26
26
  option :datastore,
27
- long: '--datastore STORE',
28
- description: 'The datastore into which to put the cloned VM'
27
+ long: "--datastore STORE",
28
+ description: "The datastore into which to put the cloned VM"
29
29
 
30
30
  option :thin_provision,
31
- long: '--thin-provision',
32
- description: 'Indicates whether disk should be thin provisioned.',
31
+ long: "--thin-provision",
32
+ description: "Indicates whether disk should be thin provisioned.",
33
33
  boolean: true
34
34
 
35
35
  option :thick_provision,
36
- long: '--thick-provision',
37
- description: 'Indicates whether disk should be thick provisioned.',
36
+ long: "--thick-provision",
37
+ description: "Indicates whether disk should be thick provisioned.",
38
38
  boolean: true
39
39
 
40
40
  # Convert VM
@@ -78,7 +78,7 @@ class Chef::Knife::VsphereVmMove < Chef::Knife::BaseVsphereCommand
78
78
  vmname = @name_args[0]
79
79
  if vmname.nil?
80
80
  show_usage
81
- fatal_exit('You must specify a virtual machine name')
81
+ fatal_exit("You must specify a virtual machine name")
82
82
  end
83
83
 
84
84
  vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
@@ -2,15 +2,15 @@
2
2
  # Author:: Raducu Deaconu (<rhadoo_io@yahoo.com>)
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
- require 'chef/knife'
6
- require 'chef/knife/base_vsphere_command'
7
- require 'chef/knife/search_helper'
5
+ require "chef/knife"
6
+ require "chef/knife/base_vsphere_command"
7
+ require "chef/knife/search_helper"
8
8
 
9
9
  # Switch VM networking state up/down (on all network interfaces)
10
10
  # VsphereVmNet extends the BaseVspherecommand
11
11
  class Chef::Knife::VsphereVmNet < Chef::Knife::BaseVsphereCommand
12
12
  include SearchHelper
13
- banner 'knife vsphere vm net STATE VMNAME'
13
+ banner "knife vsphere vm net STATE VMNAME"
14
14
  common_options
15
15
 
16
16
  # The main run method for vm_net
@@ -20,18 +20,18 @@ class Chef::Knife::VsphereVmNet < Chef::Knife::BaseVsphereCommand
20
20
  vmname = @name_args[1]
21
21
  if vmname.nil?
22
22
  show_usage
23
- fatal_exit('You must specify a virtual machine name')
23
+ fatal_exit("You must specify a virtual machine name")
24
24
  end
25
25
 
26
26
  state = @name_args[0]
27
27
  if state.nil?
28
28
  show_usage
29
- fatal_exit('You must specify networking state up/down')
29
+ fatal_exit("You must specify networking state up/down")
30
30
  end
31
31
 
32
- if state == 'up'
32
+ if state == "up"
33
33
  if_state = true
34
- elsif state == 'down'
34
+ elsif state == "down"
35
35
  if_state = false
36
36
  end
37
37
 
@@ -2,50 +2,48 @@
2
2
  # Author:: Scott Williams (<scott@backups.net.au>)
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
- require 'chef/knife'
6
- require 'chef/knife/base_vsphere_command'
7
- require 'chef/knife/search_helper'
8
- require 'netaddr'
5
+ require "chef/knife"
6
+ require "chef/knife/base_vsphere_command"
7
+ require "chef/knife/search_helper"
8
+ require "netaddr"
9
9
 
10
10
  class Chef::Knife::VsphereVmNetworkAdd < Chef::Knife::BaseVsphereCommand
11
11
  include SearchHelper
12
- banner 'knife vsphere vm network add VMNAME NETWORKNAME'
12
+ banner "knife vsphere vm network add VMNAME NETWORKNAME"
13
13
 
14
14
  option :adapter_type,
15
- long: '--adapter-type STRING',
16
- description: 'Adapter type eg e1000,vmxnet3',
15
+ long: "--adapter-type STRING",
16
+ description: "Adapter type eg e1000,vmxnet3",
17
17
  required: true
18
18
 
19
19
  option :mac_address,
20
- long: '--mac-address STRING',
21
- description: 'Adapter MAC address eg. AA:BB:CC:DD:EE:FF',
20
+ long: "--mac-address STRING",
21
+ description: "Adapter MAC address eg. AA:BB:CC:DD:EE:FF",
22
22
  required: false
23
23
 
24
24
  common_options
25
25
 
26
-
27
26
  def run
28
27
  $stdout.sync = true
29
28
  vmname = @name_args[0]
30
29
  if vmname.nil?
31
30
  show_usage
32
- fatal_exit('You must specify a virtual machine name')
31
+ fatal_exit("You must specify a virtual machine name")
33
32
  end
34
33
 
35
34
  networkname = @name_args[1]
36
35
  if networkname.nil?
37
36
  show_usage
38
- fatal_exit('You must specify the network name')
37
+ fatal_exit("You must specify the network name")
39
38
  end
40
39
 
41
-
42
40
  vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
43
41
 
44
42
  network = find_network(networkname)
45
43
 
46
44
  case network
47
45
  when RbVmomi::VIM::DistributedVirtualPortgroup
48
- switch, pg_key = network.collect 'config.distributedVirtualSwitch', 'key'
46
+ switch, pg_key = network.collect "config.distributedVirtualSwitch", "key"
49
47
  port = RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
50
48
  switchUuid: switch.uuid,
51
49
  portgroupKey: pg_key
@@ -55,23 +53,23 @@ class Chef::Knife::VsphereVmNetworkAdd < Chef::Knife::BaseVsphereCommand
55
53
  when RbVmomi::VIM::Network
56
54
  summary = network.name
57
55
  backing = RbVmomi::VIM.VirtualEthernetCardNetworkBackingInfo(deviceName: network.name)
58
- else fail
56
+ else raise
59
57
  end
60
58
 
61
59
  device_type = case get_config(:adapter_type)
62
- when 'e1000'
60
+ when "e1000"
63
61
  :VirtualE1000
64
- when 'vmxnet3'
62
+ when "vmxnet3"
65
63
  :VirtualVmxnet3
66
64
  when *
67
- fatal_exit('The adapter must be either e1000 or vmxnet3')
65
+ fatal_exit("The adapter must be either e1000 or vmxnet3")
68
66
  end
69
67
 
70
68
  if get_config(:mac_address).nil?
71
- address_type = 'generated'
72
- mac_address = ''
69
+ address_type = "generated"
70
+ mac_address = ""
73
71
  else
74
- address_type = 'manual'
72
+ address_type = "manual"
75
73
  mac_address = get_config(:mac_address)
76
74
  end
77
75
 
@@ -82,12 +80,12 @@ class Chef::Knife::VsphereVmNetworkAdd < Chef::Knife::BaseVsphereCommand
82
80
  fileOperation: nil,
83
81
  device: RbVmomi::VIM.send(device_type,
84
82
  key: -1,
85
- deviceInfo: { summary: summary, label: '' },
83
+ deviceInfo: { summary: summary, label: "" },
86
84
  backing: backing,
87
85
  addressType: address_type,
88
86
  macAddress: mac_address
89
- )
90
- }]
87
+ ),
88
+ }],
91
89
  }
92
90
  ).wait_for_completion
93
91
  end
@@ -2,13 +2,13 @@
2
2
  # Author:: Scott Williams (<scott@backups.net.au>)
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
- require 'chef/knife'
6
- require 'chef/knife/base_vsphere_command'
7
- require 'chef/knife/search_helper'
5
+ require "chef/knife"
6
+ require "chef/knife/base_vsphere_command"
7
+ require "chef/knife/search_helper"
8
8
 
9
9
  class Chef::Knife::VsphereVmNetworkDelete < Chef::Knife::BaseVsphereCommand
10
10
  include SearchHelper
11
- banner 'knife vsphere vm network delete VMNAME NICNAME'
11
+ banner "knife vsphere vm network delete VMNAME NICNAME"
12
12
 
13
13
  common_options
14
14
 
@@ -18,13 +18,13 @@ class Chef::Knife::VsphereVmNetworkDelete < Chef::Knife::BaseVsphereCommand
18
18
  vmname = @name_args[0]
19
19
  if vmname.nil?
20
20
  show_usage
21
- fatal_exit('You must specify a virtual machine name')
21
+ fatal_exit("You must specify a virtual machine name")
22
22
  end
23
23
 
24
24
  nicname = @name_args[1]
25
25
  if nicname.nil?
26
26
  show_usage
27
- fatal_exit('You must specify the name of the NIC to delete')
27
+ fatal_exit("You must specify the name of the NIC to delete")
28
28
  end
29
29
 
30
30
  vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")
@@ -32,13 +32,13 @@ class Chef::Knife::VsphereVmNetworkDelete < Chef::Knife::BaseVsphereCommand
32
32
  cards = vm.config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard)
33
33
  card = cards.detect { |c| c.deviceInfo.label == nicname }
34
34
  if card.nil?
35
- found = cards.map { |c| c.deviceInfo.label }.join ', '
35
+ found = cards.map { |c| c.deviceInfo.label }.join ", "
36
36
  fatal_exit "Could not find #{nicname}. I did find #{found}."
37
37
  else
38
38
  spec = RbVmomi::VIM.VirtualMachineConfigSpec(
39
39
  deviceChange: [{
40
40
  operation: :remove,
41
- device: card
41
+ device: card,
42
42
  }]
43
43
  )
44
44
 
@@ -2,14 +2,14 @@
2
2
  # Author:: Scott Williams (<scott@backups.net.au>)
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
- require 'chef/knife'
6
- require 'chef/knife/base_vsphere_command'
7
- require 'chef/knife/search_helper'
5
+ require "chef/knife"
6
+ require "chef/knife/base_vsphere_command"
7
+ require "chef/knife/search_helper"
8
8
 
9
9
  # VsphereVmNetworklist extends the BaseVspherecommand
10
10
  class Chef::Knife::VsphereVmNetworkList < Chef::Knife::BaseVsphereCommand
11
11
  include SearchHelper
12
- banner 'knife vsphere vm network list VMNAME'
12
+ banner "knife vsphere vm network list VMNAME"
13
13
 
14
14
  common_options
15
15
 
@@ -21,7 +21,7 @@ class Chef::Knife::VsphereVmNetworkList < Chef::Knife::BaseVsphereCommand
21
21
  vmname = @name_args[0]
22
22
  if vmname.nil?
23
23
  show_usage
24
- fatal_exit('You must specify a virtual machine name')
24
+ fatal_exit("You must specify a virtual machine name")
25
25
  end
26
26
 
27
27
  vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}")