knife-vsphere 1.2.19 → 1.2.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c25fd6b8d92bd7e275f83b51cf56547e11c40bc
4
- data.tar.gz: fa0e605b6779e90693077b4505648ea123e9365d
3
+ metadata.gz: e13ce28b3bdc4b2b9bb0dbcc5d4d3d8bda496eed
4
+ data.tar.gz: 6f02adc6815fee8cb34417e860b6d4afce3ea17a
5
5
  SHA512:
6
- metadata.gz: e82afdd76191d93c17ac79a3f349bf2fcf5225b50bc1bc97535ee7a1c017a50fe1528eb6bd83d5283f8cbe7912f458d346a7cafe482b4411c2bdf2f26ec02c24
7
- data.tar.gz: 6ba7c5d6f7923ed5bbcb5d12b5de0855a8cfaa06656ed8b73d510bc1979c534037e6531eb294e6a2a2f9a182da62c8fe18ecd76b4deb78f94e74cdab73fa23ac
6
+ metadata.gz: eda8d5d50c86e096e4654cb33e7b42372f46192a42eea351ee722ecc3e29538b0ffa27fdbdbe9c2a86f99c89d28bb14c3f00a7f477d4c7357bf945588a151dd6
7
+ data.tar.gz: afe13ef5403727e774eab7a94901c99a76f0db13c8f999b4cac2228958a2111e87bf4cb6a3bf53443ff5254b261f4a9b5ad5278d5ab53f6558076045960be4fc
@@ -8,6 +8,8 @@ require 'netaddr'
8
8
  class Chef::Knife::VsphereVmCdrom < Chef::Knife::BaseVsphereCommand
9
9
  banner 'knife vsphere vm cdrom VMNAME (options)'
10
10
 
11
+ EMPTY_DEVICE_NAME = ''.freeze
12
+
11
13
  common_options
12
14
 
13
15
  option :datastore,
@@ -21,11 +23,13 @@ class Chef::Knife::VsphereVmCdrom < Chef::Knife::BaseVsphereCommand
21
23
  option :attach,
22
24
  short: '-a',
23
25
  long: '--attach',
24
- description: 'Attach the virtual cdrom to the VM'
26
+ description: 'Attach the virtual cdrom to the VM',
27
+ boolean: true
25
28
 
26
29
  option :disconnect,
27
30
  long: '--disconnect',
28
- description: 'Disconnect the virtual cdrom from the VM'
31
+ description: 'Disconnect the virtual cdrom from the VM',
32
+ boolean: true
29
33
 
30
34
  option :on_boot,
31
35
  long: '--on_boot ONBOOT',
@@ -46,65 +50,68 @@ class Chef::Knife::VsphereVmCdrom < Chef::Knife::BaseVsphereCommand
46
50
  vmname = @name_args[0]
47
51
  if vmname.nil?
48
52
  show_usage
49
- ui.fatal('You must specify a virtual machine name')
50
- exit 1
53
+ fatal_exit('You must specify a virtual machine name')
54
+ end
55
+
56
+ unless get_config(:attach) ^ get_config(:disconnect)
57
+ fatal_exit('You must specify one of --attach or --disconnect')
51
58
  end
52
59
 
60
+ fatal_exit 'You must specify the name and path of an ISO with --iso' if get_config(:attach) && !get_config(:iso)
61
+ fatal_exit 'You must specify the datastore containing the ISO with --datastore' if get_config(:attach) && !get_config(:datastore)
62
+
53
63
  vim_connection
54
64
 
55
65
  if get_config(:recursive)
56
66
  vms = get_vms(vmname)
57
67
  if vms.length > 1
58
- abort "More than one VM with name #{vmname} found:\n" + vms.map { |vm| get_path_to_object(vm) }.join("\n")
68
+ fatal_exit "More than one VM with name #{vmname} found:\n" + vms.map { |vm| get_path_to_object(vm) }.join("\n")
59
69
  end
60
- abort "VM #{vmname} not found" if vms.length == 0
70
+ fatal_exit "VM #{vmname} not found" if vms.empty?
61
71
  vm = vms[0]
62
72
  else
63
73
  base_folder = find_folder(get_config(:folder))
64
74
 
65
- vm = find_in_folder(base_folder, RbVmomi::VIM::VirtualMachine, vmname) || abort("VM #{vmname} not found")
75
+ vm = find_in_folder(base_folder, RbVmomi::VIM::VirtualMachine, vmname) || fatal_exit("VM #{vmname} not found")
66
76
  end
67
77
 
68
- if get_config(:iso)
69
- cdrom_obj = vm.config.hardware.device.find { |hw| hw.class == RbVmomi::VIM::VirtualCdrom }
70
- machine_conf_spec = RbVmomi::VIM::VirtualMachineConfigSpec(
71
- deviceChange: [{
72
- operation: :edit,
73
- device: RbVmomi::VIM::VirtualCdrom(
74
- backing: RbVmomi::VIM::VirtualCdromIsoBackingInfo(
75
- fileName: "[#{get_config(:datastore)}] #{get_config(:iso)}"
76
- ),
77
- key: cdrom_obj.key,
78
- controllerKey: cdrom_obj.controllerKey,
79
- connectable: RbVmomi::VIM::VirtualDeviceConnectInfo(
80
- startConnected: get_config(:on_boot) || false,
81
- connected: get_config(:attach) || false,
82
- allowGuestControl: true
83
- )
84
- )
85
- }]
86
- )
87
- vm.ReconfigVM_Task(spec: machine_conf_spec).wait_for_completion
88
- elsif get_config(:disconnect)
89
- cdrom_obj = vm.config.hardware.device.find { |hw| hw.class == RbVmomi::VIM::VirtualCdrom }
90
- machine_conf_spec = RbVmomi::VIM::VirtualMachineConfigSpec(
91
- deviceChange: [{
92
- operation: :edit,
93
- device: RbVmomi::VIM::VirtualCdrom(
94
- backing: RbVmomi::VIM::VirtualCdromRemoteAtapiBackingInfo(
95
- deviceName: ''),
96
- key: cdrom_obj.key,
97
- controllerKey: cdrom_obj.controllerKey,
98
- connectable: RbVmomi::VIM::VirtualDeviceConnectInfo(
99
- startConnected: false,
100
- connected: false,
101
- allowGuestControl: true
102
- )
78
+ cdrom_obj = vm.config.hardware.device.find { |hw| hw.class == RbVmomi::VIM::VirtualCdrom }
79
+ fatal_exit 'Could not find a cd drive' unless cdrom_obj
80
+
81
+ backing = if get_config(:attach)
82
+ RbVmomi::VIM::VirtualCdromIsoBackingInfo(
83
+ fileName: iso_path
84
+ )
85
+ else
86
+ RbVmomi::VIM::VirtualCdromRemoteAtapiBackingInfo(deviceName: EMPTY_DEVICE_NAME)
87
+ end
88
+
89
+ vm.ReconfigVM_Task(
90
+ spec: spec(cdrom_obj, backing)
91
+ ).wait_for_completion
92
+ end
93
+
94
+ private
95
+
96
+ def spec(cd_device, backing)
97
+ RbVmomi::VIM::VirtualMachineConfigSpec(
98
+ deviceChange: [{
99
+ operation: :edit,
100
+ device: RbVmomi::VIM::VirtualCdrom(
101
+ backing: backing,
102
+ key: cd_device.key,
103
+ controllerKey: cd_device.controllerKey,
104
+ connectable: RbVmomi::VIM::VirtualDeviceConnectInfo(
105
+ startConnected: get_config(:on_boot) || false,
106
+ connected: get_config(:attach) || false,
107
+ allowGuestControl: true
103
108
  )
104
- }]
105
- )
106
- puts 'attempting to reconfigure the vm'
107
- vm.ReconfigVM_Task(spec: machine_conf_spec).wait_for_completion
108
- end
109
+ )
110
+ }]
111
+ )
112
+ end
113
+
114
+ def iso_path
115
+ "[#{get_config(:datastore)}] #{get_config(:iso)}"
109
116
  end
110
117
  end
@@ -26,7 +26,7 @@ class Chef::Knife::VsphereVmDiskList < Chef::Knife::BaseVsphereCommand
26
26
  disks.each do |disk|
27
27
  puts '%3d %20s %s' % [disk.unitNumber,
28
28
  disk.deviceInfo.label,
29
- Filesize.from("#{disk.capacityInKB} KB").pretty]
29
+ Filesize.from("#{disk.capacityInKB} KiB").pretty]
30
30
  end
31
31
  end
32
32
  end
@@ -0,0 +1,50 @@
1
+ #
2
+ # Author:: Scott Williams (<scott@backups.net.au>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ require 'chef/knife'
6
+ require 'chef/knife/base_vsphere_command'
7
+ require 'rbvmomi'
8
+ require 'netaddr'
9
+
10
+ class Chef::Knife::VsphereVmNetworkDelete < Chef::Knife::BaseVsphereCommand
11
+ banner 'knife vsphere vm network delete VMNAME NICNAME'
12
+
13
+ common_options
14
+
15
+ def run
16
+ $stdout.sync = true
17
+
18
+ vmname = @name_args[0]
19
+ if vmname.nil?
20
+ show_usage
21
+ fatal_exit('You must specify a virtual machine name')
22
+ end
23
+
24
+ nicname = @name_args[1]
25
+ if nicname.nil?
26
+ show_usage
27
+ fatal_exit('You must specify the name of the NIC to delete')
28
+ end
29
+
30
+ vim_connection
31
+ vm = get_vm(vmname) || abort('VM not found')
32
+
33
+ cards = vm.config.hardware.device.grep(RbVmomi::VIM::VirtualEthernetCard)
34
+ card = cards.detect { |c| c.deviceInfo.label == nicname }
35
+ if card.nil?
36
+ found = cards.map { |c| c.deviceInfo.label }.join ', '
37
+ fatal_exit "Could not find #{nicname}. I did find #{found}."
38
+ else
39
+ spec = RbVmomi::VIM.VirtualMachineConfigSpec(
40
+ deviceChange: [{
41
+ operation: :remove,
42
+ device: card
43
+ }]
44
+ )
45
+
46
+ vm.ReconfigVM_Task(spec: spec).wait_for_completion
47
+ puts "#{ui.color('NIC', :red)}: #{card.deviceInfo.label} was deleted"
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,37 @@
1
+ #
2
+ # Author:: Scott Williams (<scott@backups.net.au>)
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ require 'chef/knife'
6
+ require 'chef/knife/base_vsphere_command'
7
+ require 'rbvmomi'
8
+ require 'netaddr'
9
+
10
+ class Chef::Knife::VsphereVmNetworkList < Chef::Knife::BaseVsphereCommand
11
+ banner 'knife vsphere vm network list VMNAME'
12
+
13
+ common_options
14
+
15
+ def run
16
+ $stdout.sync = true
17
+
18
+ vmname = @name_args[0]
19
+ if vmname.nil?
20
+ show_usage
21
+ fatal_exit('You must specify a virtual machine name')
22
+ end
23
+
24
+ vim_connection
25
+ dc = datacenter
26
+ folder = find_folder(get_config(:folder)) || dc.vmFolder
27
+ vm = traverse_folders_for_vm(folder, vmname) || abort("VM #{vmname} not found")
28
+
29
+ vm.config.hardware.device.each.grep(RbVmomi::VIM::VirtualEthernetCard).map do |nic|
30
+ dc.network.each.grep(RbVmomi::VIM::DistributedVirtualPortgroup) do |net|
31
+ if nic.backing.port.portgroupKey.eql?(net.key)
32
+ puts "NIC: #{nic.deviceInfo.label} VLAN: #{net.name}"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module KnifeVsphere
2
- VERSION = '1.2.19'
2
+ VERSION = '1.2.20'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-vsphere
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.19
4
+ version: 1.2.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ezra Pagel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-14 00:00:00.000000000 Z
11
+ date: 2016-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: filesize
@@ -160,6 +160,8 @@ files:
160
160
  - lib/chef/knife/vsphere_vm_move.rb
161
161
  - lib/chef/knife/vsphere_vm_net.rb
162
162
  - lib/chef/knife/vsphere_vm_network_add.rb
163
+ - lib/chef/knife/vsphere_vm_network_delete.rb
164
+ - lib/chef/knife/vsphere_vm_network_list.rb
163
165
  - lib/chef/knife/vsphere_vm_network_set.rb
164
166
  - lib/chef/knife/vsphere_vm_property_get.rb
165
167
  - lib/chef/knife/vsphere_vm_property_set.rb
@@ -192,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
194
  version: '0'
193
195
  requirements: []
194
196
  rubyforge_project:
195
- rubygems_version: 2.5.1
197
+ rubygems_version: 2.6.7
196
198
  signing_key:
197
199
  specification_version: 4
198
200
  summary: vSphere Support for Knife