knife-vsphere 1.2.11 → 1.2.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef/knife/vsphere_vm_clone.rb +60 -17
- data/lib/chef/knife/vsphere_vm_find.rb +10 -1
- data/lib/knife-vsphere/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c9f4f89524d9eb9369efb020a0973a599cb4f00
|
4
|
+
data.tar.gz: 8eaafefad58bb40dc078adf77788bf0f4f890c08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e388e12fea69231ef285d14065784c4160c261b02764f97d24bd96c5637f5c5ba2fd6942b0db18892f3c9503b4593e409472c9859ab8ada4b0b8fa507fa9808b
|
7
|
+
data.tar.gz: af9b568e85cfba7d464b140e4dee71e8810687d4bfcca966468171ebb375f959c4d8c77d416d2662af443bc6b4ef5a7adcad37b49be9a0fa257c686116014f9d
|
@@ -84,6 +84,14 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
84
84
|
long: '--cvlan CUST_VLANS',
|
85
85
|
description: 'Comma-delimited list of VLAN names for network adapters to join'
|
86
86
|
|
87
|
+
option :customization_sw_uuid,
|
88
|
+
long: '--sw-uuid SWITCH_UUIDS',
|
89
|
+
description: "Comma-delimited list of distributed virtual switch UUIDs for network adapter to connect, use 'auto' to automatically assign"
|
90
|
+
|
91
|
+
option :customization_macs,
|
92
|
+
long: '--cmacs CUST_MACS',
|
93
|
+
description: 'Comma-delimited list of MAC addresses for network adapters'
|
94
|
+
|
87
95
|
option :customization_ips,
|
88
96
|
long: '--cips CUST_IPS',
|
89
97
|
description: 'Comma-delimited list of CIDR IPs for customization'
|
@@ -375,13 +383,14 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
375
383
|
# Multiple reboots occur during guest customization in which a link-local
|
376
384
|
# address is assigned. As such, we need to wait until a routable IP address
|
377
385
|
# becomes available. This is most commonly an issue with Windows instances.
|
378
|
-
sleep 2 while vm.guest.net[
|
379
|
-
vm.guest.net[
|
386
|
+
sleep 2 while vm.guest.net[bootstrap_nic_index].ipConfig.ipAddress.detect { |addr| IPAddr.new(addr.ipAddress).ipv4? }.origin == 'linklayer'
|
387
|
+
vm.guest.net[bootstrap_nic_index].ipAddress.detect { |addr| IPAddr.new(addr).ipv4? }
|
380
388
|
end
|
381
389
|
|
382
390
|
def guest_address(vm)
|
383
391
|
puts 'Waiting for network interfaces to become available...'
|
384
|
-
sleep 2 while vm.guest.net.empty?
|
392
|
+
sleep 2 while vm.guest.net.empty? || !vm.guest.ipAddress
|
393
|
+
ui.info "Found address #{vm.guest.ipAddress}" if log_verbose?
|
385
394
|
guest_address ||=
|
386
395
|
config[:fqdn] = if config[:bootstrap_ipv4]
|
387
396
|
ipv4_address(vm)
|
@@ -391,7 +400,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
391
400
|
# Use the first IP which is not a link-local address.
|
392
401
|
# This is the closest thing to vm.guest.ipAddress but
|
393
402
|
# allows specifying a NIC.
|
394
|
-
vm.guest.net[
|
403
|
+
vm.guest.net[bootstrap_nic_index].ipConfig.ipAddress.detect do |addr|
|
395
404
|
addr.origin != 'linklayer'
|
396
405
|
end.ipAddress
|
397
406
|
end
|
@@ -524,6 +533,28 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
524
533
|
clone_spec.config.memoryMB = Integer(get_config(:customization_memory)) * 1024
|
525
534
|
end
|
526
535
|
|
536
|
+
if get_config(:customization_macs)
|
537
|
+
unless get_config(:customization_ips)
|
538
|
+
abort('Must specify IP numbers with --cips when specifying MAC addresses with --cmacs, can use "dhcp" as placeholder')
|
539
|
+
end
|
540
|
+
mac_list = if get_config(:customization_macs) == 'auto'
|
541
|
+
['auto'] * get_config(:customization_ips).split(',').length
|
542
|
+
else
|
543
|
+
get_config(:customization_macs).split(',')
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
if get_config(:customization_sw_uuid)
|
548
|
+
unless get_config(:customization_vlan)
|
549
|
+
abort('Must specify VLANs with --cvlan when specifying switch UUIDs with --sw-uuids')
|
550
|
+
end
|
551
|
+
swuuid_list = if get_config(:customization_sw_uuid) == 'auto'
|
552
|
+
['auto'] * get_config(customization_ips).split(',').length
|
553
|
+
else
|
554
|
+
get_config(:customization_sw_uuid).split(',').map { |swuuid| swuuid.gsub(/((\w+\s+){7})(\w+)\s+(.+)/, '\1\3-\4') }
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
527
558
|
if get_config(:customization_vlan)
|
528
559
|
vlan_list = get_config(:customization_vlan).split(',')
|
529
560
|
networks = vlan_list.map { |vlan| find_network(vlan) }
|
@@ -533,12 +564,21 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
533
564
|
networks.each_with_index do |network, index|
|
534
565
|
card = cards[index] || abort("Can't find source network card to customize for vlan #{vlan_list[index]}")
|
535
566
|
begin
|
536
|
-
|
567
|
+
if get_config(:customization_sw_uuid) && (swuuid_list[index] != 'auto')
|
568
|
+
switch_port = RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
|
569
|
+
switchUuid: swuuid_list[index], portgroupKey: network.key
|
570
|
+
)
|
571
|
+
else
|
572
|
+
switch_port = RbVmomi::VIM.DistributedVirtualSwitchPortConnection(
|
573
|
+
switchUuid: network.config.distributedVirtualSwitch.uuid, portgroupKey: network.key
|
574
|
+
)
|
575
|
+
end
|
537
576
|
card.backing.port = switch_port
|
538
577
|
rescue
|
539
578
|
# not connected to a distibuted switch?
|
540
579
|
card.backing = RbVmomi::VIM::VirtualEthernetCardNetworkBackingInfo(network: network, deviceName: network.name)
|
541
580
|
end
|
581
|
+
card.macAddress = mac_list[index] if mac_list[index] != 'auto'
|
542
582
|
dev_spec = RbVmomi::VIM.VirtualDeviceConfigSpec(device: card, operation: 'edit')
|
543
583
|
clone_spec.config.deviceChange.push dev_spec
|
544
584
|
end
|
@@ -564,15 +604,13 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
564
604
|
end
|
565
605
|
|
566
606
|
if config[:customization_ips]
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
cust_spec.nicSettingMap = config[:customization_ips].split(',').map { |i| generate_adapter_map(i) }
|
571
|
-
end
|
607
|
+
cust_spec.nicSettingMap = config[:customization_ips].split(',').map.with_index { |cust_ip, index|
|
608
|
+
generate_adapter_map(cust_ip, get_config(:customization_gw), mac_list[index])
|
609
|
+
}
|
572
610
|
end
|
573
611
|
|
574
612
|
if get_config(:disable_customization)
|
575
|
-
clone_spec.customization = cust_spec
|
613
|
+
clone_spec.customization = cust_spec
|
576
614
|
else
|
577
615
|
use_ident = !config[:customization_hostname].nil? || !get_config(:customization_domain).nil? || cust_spec.identity.nil?
|
578
616
|
|
@@ -620,11 +658,11 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
620
658
|
ident = RbVmomi::VIM.CustomizationLinuxPrep
|
621
659
|
ident.hostName = RbVmomi::VIM.CustomizationFixedName(name: hostname)
|
622
660
|
|
623
|
-
if get_config(:customization_domain)
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
661
|
+
ident.domain = if get_config(:customization_domain)
|
662
|
+
get_config(:customization_domain)
|
663
|
+
else
|
664
|
+
''
|
665
|
+
end
|
628
666
|
cust_spec.identity = ident
|
629
667
|
else
|
630
668
|
ui.error('Customization only supports Linux and Windows currently.')
|
@@ -684,7 +722,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
684
722
|
# @param ip [String] Any static IP address to use, or "dhcp" for DHCP
|
685
723
|
# @param gw [String] If static, the gateway for the interface, otherwise network address + 1 will be used
|
686
724
|
# @return [RbVmomi::VIM::CustomizationIPSettings]
|
687
|
-
def generate_adapter_map(ip = nil, gw = nil)
|
725
|
+
def generate_adapter_map(ip = nil, gw = nil, mac = nil)
|
688
726
|
settings = RbVmomi::VIM.CustomizationIPSettings
|
689
727
|
|
690
728
|
if ip.nil? || ip.downcase == 'dhcp'
|
@@ -707,6 +745,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
707
745
|
end
|
708
746
|
|
709
747
|
adapter_map = RbVmomi::VIM.CustomizationAdapterMapping
|
748
|
+
adapter_map.macAddress = mac if !mac.nil? && (mac != 'auto')
|
710
749
|
adapter_map.adapter = settings
|
711
750
|
adapter_map
|
712
751
|
end
|
@@ -872,4 +911,8 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
872
911
|
def random_hostname
|
873
912
|
@random_hostname ||= config[:random_vmname_prefix] + SecureRandom.hex(4)
|
874
913
|
end
|
914
|
+
|
915
|
+
def bootstrap_nic_index
|
916
|
+
Integer(get_config(:bootstrap_nic))
|
917
|
+
end
|
875
918
|
end
|
@@ -45,7 +45,11 @@ class Chef::Knife::VsphereVmFind < Chef::Knife::BaseVsphereCommand
|
|
45
45
|
|
46
46
|
option :ip,
|
47
47
|
long: '--ip',
|
48
|
-
description: 'Show ip'
|
48
|
+
description: 'Show primary ip'
|
49
|
+
|
50
|
+
option :ips,
|
51
|
+
long: '--ips',
|
52
|
+
description: 'Show all ips, with networks'
|
49
53
|
|
50
54
|
option :soff,
|
51
55
|
long: '--powered-off',
|
@@ -189,6 +193,11 @@ class Chef::Knife::VsphereVmFind < Chef::Knife::BaseVsphereCommand
|
|
189
193
|
if get_config(:ip)
|
190
194
|
print "#{ui.color("IP:", :cyan)} #{vmc.guest.ipAddress}\t"
|
191
195
|
end
|
196
|
+
if get_config(:ips)
|
197
|
+
ipregex = /^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/
|
198
|
+
networks = vmc.guest.net.map { |net| "#{net.network}:" + net.ipConfig.ipAddress.select { |i| i.ipAddress[ipregex] }[0].ipAddress }
|
199
|
+
print "#{ui.color("IPS:", :cyan)} #{networks.join(",")}\t"
|
200
|
+
end
|
192
201
|
if get_config(:os)
|
193
202
|
print "#{ui.color("OS:", :cyan)} #{vmc.guest.guestFullName}\t"
|
194
203
|
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.
|
4
|
+
version: 1.2.12
|
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
|
+
date: 2016-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: filesize
|