knife-vsphere 1.2.3 → 1.2.4
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_datastore_file.rb +51 -0
- data/lib/chef/knife/vsphere_vm_cdrom.rb +110 -0
- data/lib/chef/knife/vsphere_vm_clone.rb +8 -4
- data/lib/chef/knife/vsphere_vm_list.rb +24 -10
- data/lib/chef/knife/vsphere_vm_markastemplate.rb +2 -1
- data/lib/knife-vsphere/version.rb +1 -1
- metadata +18 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b99f48fa873d629a1882d1f8f269fa314014fea
|
4
|
+
data.tar.gz: 980c7c2071e841eb6008515308d4241f9196dc94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77f5f85d54f7e1df223cba68410c076ff732bb3a7e5379bed7e331c45e307f7911f7ea68e26662dc6857e7bead771a43436442636bed9a9c98a6b38bf54b1a37
|
7
|
+
data.tar.gz: cfc52c14fff451c70b0f0878fef47ce45bac4a41c74089dba8315ada86ad62329456be23fb723282447e7fff706d2ee6a804724308bc30a435700d73d22a953e
|
@@ -0,0 +1,51 @@
|
|
1
|
+
|
2
|
+
require 'chef/knife'
|
3
|
+
require 'chef/knife/base_vsphere_command'
|
4
|
+
|
5
|
+
# Upload or download a file from a datastore
|
6
|
+
class Chef::Knife::VsphereDatastoreFile < Chef::Knife::BaseVsphereCommand
|
7
|
+
banner 'knife vsphere datastore file'
|
8
|
+
|
9
|
+
common_options
|
10
|
+
|
11
|
+
option :local_file,
|
12
|
+
long: '--local-file FILE',
|
13
|
+
short: '-f',
|
14
|
+
description: 'Local file and path'
|
15
|
+
|
16
|
+
option :remote_file,
|
17
|
+
long: '--remote-file FILE',
|
18
|
+
short: '-r',
|
19
|
+
description: 'Remote file and path'
|
20
|
+
|
21
|
+
option :upload,
|
22
|
+
long: '--upload-file',
|
23
|
+
short: '-u',
|
24
|
+
description: 'Upload local file to remote'
|
25
|
+
|
26
|
+
option :download,
|
27
|
+
long: '--download-file',
|
28
|
+
short: '-D',
|
29
|
+
description: 'Download remote file to local'
|
30
|
+
|
31
|
+
def run
|
32
|
+
$stdout.sync = true
|
33
|
+
|
34
|
+
unless get_config(:upload) || get_config(:download)
|
35
|
+
show_usage
|
36
|
+
fatal_exit('You must specify either upload or download')
|
37
|
+
end
|
38
|
+
unless get_config(:local_file) && get_config(:remote_file)
|
39
|
+
show_usage
|
40
|
+
fatal_exit('You must specify both local-file and remote-file')
|
41
|
+
end
|
42
|
+
|
43
|
+
vim_connection
|
44
|
+
datastore = find_datastore(@name_args[0])
|
45
|
+
if get_config(:upload)
|
46
|
+
datastore.upload(get_config(:remote_file), get_config(:local_file))
|
47
|
+
elsif get_config(:download)
|
48
|
+
datastore.download(get_config(:remote_file), get_config(:local_file))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# License:: Apache License, Version 2.0
|
2
|
+
|
3
|
+
require 'chef/knife'
|
4
|
+
require 'chef/knife/base_vsphere_command'
|
5
|
+
require 'rbvmomi'
|
6
|
+
require 'netaddr'
|
7
|
+
|
8
|
+
class Chef::Knife::VsphereVmCdrom < Chef::Knife::BaseVsphereCommand
|
9
|
+
banner 'knife vsphere vm cdrom VMNAME (options)'
|
10
|
+
|
11
|
+
common_options
|
12
|
+
|
13
|
+
option :datastore,
|
14
|
+
long: '--datastore STORE',
|
15
|
+
description: 'The datastore for an iso source'
|
16
|
+
|
17
|
+
option :iso,
|
18
|
+
long: '--iso ISO',
|
19
|
+
description: 'The name and path of the ISO to attach'
|
20
|
+
|
21
|
+
option :attach,
|
22
|
+
short: '-a',
|
23
|
+
long: '--attach',
|
24
|
+
description: 'Attach the virtual cdrom to the VM'
|
25
|
+
|
26
|
+
option :disconnect,
|
27
|
+
long: '--disconnect',
|
28
|
+
description: 'Disconnect the virtual cdrom from the VM'
|
29
|
+
|
30
|
+
option :on_boot,
|
31
|
+
long: '--on_boot ONBOOT',
|
32
|
+
description: 'False for Detached on boot or True for Attached on boot'
|
33
|
+
|
34
|
+
option :client_device,
|
35
|
+
long: '--client_device',
|
36
|
+
description: 'Set the backing store to client-device'
|
37
|
+
|
38
|
+
option :recursive,
|
39
|
+
short: '-r',
|
40
|
+
long: '--recursive',
|
41
|
+
description: 'Search all folders'
|
42
|
+
|
43
|
+
def run
|
44
|
+
$stdout.sync = true
|
45
|
+
|
46
|
+
vmname = @name_args[0]
|
47
|
+
if vmname.nil?
|
48
|
+
show_usage
|
49
|
+
ui.fatal('You must specify a virtual machine name')
|
50
|
+
exit 1
|
51
|
+
end
|
52
|
+
|
53
|
+
vim_connection
|
54
|
+
|
55
|
+
if get_config(:recursive)
|
56
|
+
vms = get_vms(vmname)
|
57
|
+
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")
|
59
|
+
end
|
60
|
+
abort "VM #{vmname} not found" if vms.length == 0
|
61
|
+
vm = vms[0]
|
62
|
+
else
|
63
|
+
base_folder = find_folder(get_config(:folder))
|
64
|
+
|
65
|
+
vm = find_in_folder(base_folder, RbVmomi::VIM::VirtualMachine, vmname) || abort("VM #{vmname} not found")
|
66
|
+
end
|
67
|
+
|
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
|
+
)
|
103
|
+
)
|
104
|
+
}]
|
105
|
+
)
|
106
|
+
puts 'attempting to reconfigure the vm'
|
107
|
+
vm.ReconfigVM_Task(spec: machine_conf_spec).wait_for_completion
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -368,15 +368,17 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
368
368
|
def wait_for_access(connect_host, connect_port, protocol)
|
369
369
|
if protocol == 'winrm'
|
370
370
|
load_winrm_deps
|
371
|
+
if get_config(:winrm_transport) == 'ssl' && get_config(:winrm_port) == '5985'
|
372
|
+
config[:winrm_port] = '5986'
|
373
|
+
end
|
371
374
|
connect_port = get_config(:winrm_port)
|
372
|
-
print "\n#{ui.color(
|
375
|
+
print "\n#{ui.color("Waiting for winrm access to become available on #{connect_host}:#{connect_port}",:magenta)}"
|
373
376
|
print('.') until tcp_test_winrm(connect_host, connect_port) do
|
374
377
|
sleep 10
|
375
378
|
puts('done')
|
376
379
|
end
|
377
380
|
else
|
378
|
-
print "\n#{ui.color(
|
379
|
-
# If FreeSSHd, winsshd etc are available
|
381
|
+
print "\n#{ui.color("Waiting for sshd access to become available on #{connect_host}:#{connect_port}", :magenta)}"
|
380
382
|
print('.') until tcp_test_ssh(connect_host, connect_port) do
|
381
383
|
sleep 10
|
382
384
|
puts('done')
|
@@ -534,7 +536,9 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
|
534
536
|
end
|
535
537
|
end
|
536
538
|
|
537
|
-
|
539
|
+
if get_config(:disable_customization)
|
540
|
+
clone_spec.customization = cust_spec
|
541
|
+
else
|
538
542
|
use_ident = !config[:customization_hostname].nil? || !get_config(:customization_domain).nil? || cust_spec.identity.nil?
|
539
543
|
|
540
544
|
if use_ident
|
@@ -16,19 +16,28 @@ class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
|
|
16
16
|
short: '-r',
|
17
17
|
description: 'Recurse into sub-folders'
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
option :onlyfolders,
|
20
|
+
long: '--only-folders',
|
21
|
+
description: 'List only the folders found',
|
22
|
+
boolean: false
|
23
|
+
|
24
|
+
def traverse_folders(folder, is_top = false, recurse = false, only_folders = false)
|
25
|
+
if only_folders
|
26
|
+
print_folder(folder)
|
27
|
+
else
|
28
|
+
vms = find_all_in_folder(folder, RbVmomi::VIM::VirtualMachine).select { |v| v.config && !v.config.template }
|
29
|
+
if vms.any?
|
30
|
+
print_folder(folder)
|
31
|
+
vms.each { |v| print_vm(v) }
|
32
|
+
elsif is_top
|
33
|
+
puts "#{ui.color('No VMs', :cyan)}"
|
34
|
+
end
|
26
35
|
end
|
27
36
|
|
28
37
|
return unless recurse
|
29
38
|
folders = find_all_in_folder(folder, RbVmomi::VIM::Folder)
|
30
39
|
folders.each do |child|
|
31
|
-
traverse_folders(child, false, recurse)
|
40
|
+
traverse_folders(child, false, recurse, only_folders)
|
32
41
|
end
|
33
42
|
end
|
34
43
|
|
@@ -47,11 +56,16 @@ class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
|
|
47
56
|
puts "\t\t#{ui.color('State:', :magenta)} #{state}"
|
48
57
|
end
|
49
58
|
|
59
|
+
def print_folder(folder)
|
60
|
+
puts "#{ui.color('Folder', :cyan)}: " + (folder.path[3..-1].map { |x| x[1] }.* '/')
|
61
|
+
end
|
62
|
+
|
50
63
|
def run
|
51
64
|
vim_connection
|
52
65
|
base_folder = find_folder(get_config(:folder))
|
53
|
-
|
66
|
+
only_folders = get_config(:onlyfolders)
|
67
|
+
recurse = only_folders || get_config(:recursive)
|
54
68
|
is_top = true
|
55
|
-
traverse_folders(base_folder, is_top, recurse)
|
69
|
+
traverse_folders(base_folder, is_top, recurse, only_folders)
|
56
70
|
end
|
57
71
|
end
|
@@ -20,7 +20,8 @@ class Chef::Knife::VsphereVmMarkastemplate < Chef::Knife::BaseVsphereCommand
|
|
20
20
|
|
21
21
|
option :folder,
|
22
22
|
long: '--folder FOLDER',
|
23
|
-
description: 'The folder which contains the VM'
|
23
|
+
description: 'The folder which contains the VM',
|
24
|
+
default: ''
|
24
25
|
|
25
26
|
def run
|
26
27
|
$stdout.sync = true
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ezra Pagel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: netaddr
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: chef
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.10.0
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 0.10.0
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rbvmomi
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +52,20 @@ dependencies:
|
|
66
52
|
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: 0.6.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: chef
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.10.0
|
69
69
|
description: VMware vSphere Support for Chef's Knife Command
|
70
70
|
email: ezra@cpan.org
|
71
71
|
executables: []
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- lib/chef/knife/vsphere_cluster_list.rb
|
78
78
|
- lib/chef/knife/vsphere_cpu_ratio.rb
|
79
79
|
- lib/chef/knife/vsphere_customization_list.rb
|
80
|
+
- lib/chef/knife/vsphere_datastore_file.rb
|
80
81
|
- lib/chef/knife/vsphere_datastore_list.rb
|
81
82
|
- lib/chef/knife/vsphere_datastore_maxfree.rb
|
82
83
|
- lib/chef/knife/vsphere_datastorecluster_list.rb
|
@@ -88,6 +89,7 @@ files:
|
|
88
89
|
- lib/chef/knife/vsphere_template_list.rb
|
89
90
|
- lib/chef/knife/vsphere_vlan_create.rb
|
90
91
|
- lib/chef/knife/vsphere_vlan_list.rb
|
92
|
+
- lib/chef/knife/vsphere_vm_cdrom.rb
|
91
93
|
- lib/chef/knife/vsphere_vm_clone.rb
|
92
94
|
- lib/chef/knife/vsphere_vm_config.rb
|
93
95
|
- lib/chef/knife/vsphere_vm_delete.rb
|