knife-vsphere 0.1.4 → 0.1.5
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.
- data/lib/chef/knife/{VsphereBaseCommand.rb → BaseVsphereCommand.rb} +6 -17
- data/lib/chef/knife/vsphere_customization_list.rb +18 -31
- data/lib/chef/knife/vsphere_template_list.rb +19 -33
- data/lib/chef/knife/vsphere_vm_clone.rb +78 -35
- data/lib/chef/knife/vsphere_vm_delete.rb +23 -38
- data/lib/chef/knife/vsphere_vm_list.rb +27 -41
- data/lib/chef/knife/vsphere_vm_state.rb +10 -20
- data/lib/knife-vsphere/version.rb +1 -1
- metadata +25 -9
@@ -2,24 +2,14 @@
|
|
2
2
|
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
5
|
|
17
6
|
require 'chef/knife'
|
18
7
|
require 'rbvmomi'
|
19
8
|
|
9
|
+
# Base class for vsphere knife commands
|
20
10
|
class Chef
|
21
11
|
class Knife
|
22
|
-
class
|
12
|
+
class BaseVsphereCommand < Knife
|
23
13
|
|
24
14
|
deps do
|
25
15
|
require 'chef/knife/bootstrap'
|
@@ -34,11 +24,6 @@ class Chef
|
|
34
24
|
|
35
25
|
def self.get_common_options
|
36
26
|
|
37
|
-
option :host,
|
38
|
-
:short => "-H HOST",
|
39
|
-
:long => "--host HOST",
|
40
|
-
:description => "The host to create the VM on"
|
41
|
-
|
42
27
|
option :vsphere_user,
|
43
28
|
:short => "-u USERNAME",
|
44
29
|
:long => "--user USERNAME",
|
@@ -115,6 +100,10 @@ class Chef
|
|
115
100
|
find { |o| o.name == name }
|
116
101
|
end
|
117
102
|
|
103
|
+
def fatal_exit(msg)
|
104
|
+
ui.fatal(msg)
|
105
|
+
exit 1
|
106
|
+
end
|
118
107
|
|
119
108
|
|
120
109
|
end
|
@@ -1,42 +1,29 @@
|
|
1
|
-
#r# Author:: Ezra Pagel (<ezra@cpan.org>)
|
2
|
-
# License:: Apache License, Version 2.0
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
1
|
#
|
8
|
-
#
|
2
|
+
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
|
+
# License:: Apache License, Version 2.0
|
9
4
|
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
|
16
5
|
require 'chef/knife'
|
17
|
-
require 'chef/knife/
|
6
|
+
require 'chef/knife/BaseVsphereCommand'
|
18
7
|
|
19
|
-
|
20
|
-
|
21
|
-
class VsphereCustomizationList < VsphereBaseCommand
|
8
|
+
# Lists all customization specifications in the configured datacenter
|
9
|
+
class Chef::Knife::VsphereCustomizationList < Chef::Knife::BaseVsphereCommand
|
22
10
|
|
23
|
-
|
11
|
+
banner "knife vsphere customization list"
|
24
12
|
|
25
|
-
|
26
|
-
|
27
|
-
|
13
|
+
get_common_options
|
14
|
+
|
15
|
+
def run
|
28
16
|
|
29
|
-
|
30
|
-
|
31
|
-
|
17
|
+
$stdout.sync = true
|
18
|
+
|
19
|
+
vim = get_vim_connection
|
32
20
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
21
|
+
csm = vim.serviceContent.customizationSpecManager
|
22
|
+
csm.info.each do |c|
|
23
|
+
puts "#{ui.color("Customization Name", :cyan)}: #{c.name}"
|
24
|
+
|
40
25
|
end
|
26
|
+
|
41
27
|
end
|
42
28
|
end
|
29
|
+
|
@@ -2,48 +2,34 @@
|
|
2
2
|
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
5
|
|
17
6
|
require 'chef/knife'
|
18
|
-
require 'chef/knife/
|
7
|
+
require 'chef/knife/BaseVsphereCommand'
|
19
8
|
|
20
|
-
|
21
|
-
|
22
|
-
class VsphereTemplateList < VsphereBaseCommand
|
9
|
+
# Lists all known VM templates in the configured datacenter
|
10
|
+
class Chef::Knife::VsphereTemplateList < Chef::Knife::BaseVsphereCommand
|
23
11
|
|
24
|
-
|
12
|
+
banner "knife vsphere template list"
|
25
13
|
|
26
|
-
|
27
|
-
|
14
|
+
get_common_options
|
15
|
+
|
16
|
+
def run
|
28
17
|
|
29
|
-
|
18
|
+
$stdout.sync = true
|
19
|
+
$stderr.sync = true
|
30
20
|
|
31
|
-
|
32
|
-
|
33
|
-
vim = get_vim_connection
|
21
|
+
vim = get_vim_connection
|
34
22
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
23
|
+
dcname = config[:vsphere_dc] || Chef::Config[:knife][:vsphere_dc]
|
24
|
+
dc = vim.serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
|
25
|
+
|
26
|
+
vmFolders = get_folders(dc.vmFolder)
|
39
27
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
28
|
+
vms = find_all_in_folders(dc.vmFolder, RbVmomi::VIM::VirtualMachine).
|
29
|
+
select {|v| !v.config.nil? && v.config.template == true }
|
30
|
+
|
31
|
+
vms.each do |vm|
|
32
|
+
puts "#{ui.color("Template Name", :cyan)}: #{vm.name}"
|
47
33
|
end
|
48
34
|
end
|
49
35
|
end
|
@@ -2,48 +2,48 @@
|
|
2
2
|
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
5
|
|
17
6
|
require 'chef/knife'
|
18
|
-
require 'chef/knife/
|
7
|
+
require 'chef/knife/BaseVsphereCommand'
|
19
8
|
require 'rbvmomi'
|
20
9
|
require 'netaddr'
|
21
10
|
|
22
|
-
|
11
|
+
# Clone an existing template into a new VM, optionally applying a customization specification.
|
12
|
+
#
|
13
|
+
# usage:
|
14
|
+
# knife vsphere vm clone NewNode UbuntuTemplate --cspec StaticSpec \
|
15
|
+
# --cips 192.168.0.99/24,192.168.1.99/24 \
|
16
|
+
# --chostname NODENAME --cdomain NODEDOMAIN
|
17
|
+
class Chef::Knife::VsphereVmClone < Chef::Knife::BaseVsphereCommand
|
23
18
|
|
24
|
-
banner "knife vsphere vm clone (options)"
|
19
|
+
banner "knife vsphere vm clone VMNAME TEMPLATE (options)"
|
25
20
|
|
26
21
|
get_common_options
|
27
22
|
|
28
|
-
option :template,
|
29
|
-
:short => "-t TEMPLATE",
|
30
|
-
:long => "--template TEMPLATE",
|
31
|
-
:description => "The template to create the VM from"
|
32
|
-
|
33
|
-
option :vmname,
|
34
|
-
:short => "-N VMNAME",
|
35
|
-
:long => "--vmname VMNAME",
|
36
|
-
:description => "The name for the new virtual machine"
|
37
|
-
|
38
23
|
option :customization_spec,
|
39
|
-
:long => "--cspec
|
24
|
+
:long => "--cspec CUST_SPEC",
|
40
25
|
:description => "The name of any customization specification to apply"
|
41
26
|
|
42
27
|
option :customization_ips,
|
43
|
-
:long => "--cips
|
44
|
-
:description => "
|
45
|
-
|
28
|
+
:long => "--cips CUST_IPS",
|
29
|
+
:description => "Comma-delimited list of CIDR IPs for customization"
|
30
|
+
|
31
|
+
option :customization_hostname,
|
32
|
+
:long => "--chostname CUST_HOSTNAME",
|
33
|
+
:description => "Unqualified hostname for customization"
|
34
|
+
|
35
|
+
option :customization_domain,
|
36
|
+
:long => "--cdomain CUST_DOMAIN",
|
37
|
+
:description => "Domain name for customization"
|
46
38
|
|
39
|
+
option :customization_tz,
|
40
|
+
:long => "--ctz CUST_TIMEZONE",
|
41
|
+
:description => "Timezone invalid 'Area/Location' format"
|
42
|
+
|
43
|
+
option :power,
|
44
|
+
:long => "--start STARTVM",
|
45
|
+
:description => "Indicates whether to start the VM after a successful clone",
|
46
|
+
:default => true
|
47
47
|
|
48
48
|
|
49
49
|
|
@@ -51,9 +51,18 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::VsphereBaseCommand
|
|
51
51
|
|
52
52
|
$stdout.sync = true
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
vmname = @name_args[0]
|
55
|
+
if vmname.nil?
|
56
|
+
show_usage
|
57
|
+
fatal_exit("You must specify a virtual machine name")
|
58
|
+
end
|
59
|
+
|
60
|
+
template = @name_args[1]
|
61
|
+
if template.nil?
|
62
|
+
show_usage
|
63
|
+
fatal_exit("You must specify a template name")
|
64
|
+
end
|
65
|
+
|
57
66
|
vim = get_vim_connection
|
58
67
|
|
59
68
|
dcname = config[:vsphere_dc] || Chef::Config[:knife][:vsphere_dc]
|
@@ -74,20 +83,54 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::VsphereBaseCommand
|
|
74
83
|
|
75
84
|
if config[:customization_spec]
|
76
85
|
csi = find_customization(vim, config[:customization_spec]) or
|
77
|
-
|
86
|
+
fatal_exit("failed to find customization specification named #{config[:customization_spec]}")
|
87
|
+
|
88
|
+
if csi.info.type != "Linux"
|
89
|
+
fatal_exit("Only Linux customization specifications are currently supported")
|
90
|
+
end
|
78
91
|
|
79
92
|
if config[:customization_ips]
|
80
93
|
csi.spec.nicSettingMap = config[:customization_ips].split(',').map { |i| generate_adapter_map(i) }
|
81
94
|
end
|
82
95
|
|
96
|
+
use_ident = !config[:customization_hostname].nil? || !config[:customization_domain].nil?
|
97
|
+
|
98
|
+
if use_ident
|
99
|
+
# TODO - verify that we're deploying a linux spec, at least warn
|
100
|
+
ident = RbVmomi::VIM.CustomizationLinuxPrep
|
101
|
+
|
102
|
+
if config[:customization_hostname]
|
103
|
+
ident.hostName = RbVmomi::VIM.CustomizationFixedName
|
104
|
+
ident.hostName.name = config[:customization_hostname]
|
105
|
+
else
|
106
|
+
ident.hostName = RbVmomi::VIM.CustomizationFixedName
|
107
|
+
ident.hostName.name = config[:customization_domain]
|
108
|
+
end
|
109
|
+
|
110
|
+
if config[:customization_domain]
|
111
|
+
ident.domain = config[:customization_domain]
|
112
|
+
end
|
113
|
+
|
114
|
+
csi.spec.identity = ident
|
115
|
+
end
|
116
|
+
|
83
117
|
clone_spec.customization = csi.spec
|
84
118
|
|
85
119
|
end
|
86
120
|
|
87
121
|
task = src_vm.CloneVM_Task(:folder => src_vm.parent, :name => vmname, :spec => clone_spec)
|
88
122
|
puts "Cloning template #{template} to new VM #{vmname}"
|
89
|
-
task.wait_for_completion
|
123
|
+
task.wait_for_completion
|
90
124
|
puts "Finished creating virtual machine #{vmname}"
|
125
|
+
|
126
|
+
if config[:power]
|
127
|
+
vm = find_in_folders(dc.vmFolder, RbVmomi::VIM::VirtualMachine, vmname) or
|
128
|
+
fatal_exit("VM #{vmname} not found")
|
129
|
+
vm.PowerOnVM_Task.wait_for_completion
|
130
|
+
puts "Powered on virtual machine #{vmname}"
|
131
|
+
end
|
132
|
+
|
133
|
+
|
91
134
|
end
|
92
135
|
|
93
136
|
|
@@ -116,7 +159,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::VsphereBaseCommand
|
|
116
159
|
settings.subnetMask = cidr_ip.netmask_ext
|
117
160
|
|
118
161
|
# TODO - want to confirm gw/ip are in same subnet?
|
119
|
-
if
|
162
|
+
if gw.nil?
|
120
163
|
settings.gateway = [cidr_ip.network(:Objectify => true).next_ip]
|
121
164
|
else
|
122
165
|
gw_cidr = NetAddr::CIDR.create(gw)
|
@@ -127,7 +170,7 @@ class Chef::Knife::VsphereVmClone < Chef::Knife::VsphereBaseCommand
|
|
127
170
|
adapter_map = RbVmomi::VIM.CustomizationAdapterMapping
|
128
171
|
adapter_map.adapter = settings
|
129
172
|
adapter_map
|
130
|
-
|
173
|
+
|
131
174
|
end
|
132
175
|
|
133
176
|
end
|
@@ -2,55 +2,40 @@
|
|
2
2
|
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
5
|
|
17
6
|
require 'chef/knife'
|
18
|
-
require 'chef/knife/
|
7
|
+
require 'chef/knife/BaseVsphereCommand'
|
19
8
|
require 'rbvmomi'
|
20
9
|
|
21
|
-
|
22
|
-
|
23
|
-
class VsphereVmDelete < VsphereBaseCommand
|
24
|
-
|
10
|
+
# Delete a virtual machine from vCenter
|
11
|
+
class Chef::Knife::VsphereVmDelete < Chef::Knife::BaseVsphereCommand
|
25
12
|
|
26
|
-
|
13
|
+
banner "knife vsphere vm delete VMNAME"
|
27
14
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
:long => "--vmname VMNAME",
|
33
|
-
:description => "The name of the virtual machine to delete"
|
15
|
+
get_common_options
|
16
|
+
|
17
|
+
def run
|
18
|
+
$stdout.sync = true
|
34
19
|
|
35
|
-
|
20
|
+
vmname = @name_args[0]
|
36
21
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
22
|
+
if vmname.nil?
|
23
|
+
show_usage
|
24
|
+
fatal_exit("You must specify a virtual machine name")
|
25
|
+
end
|
26
|
+
|
27
|
+
vim = get_vim_connection
|
42
28
|
|
43
|
-
|
44
|
-
|
29
|
+
dcname = config[:vsphere_dc] || Chef::Config[:knife][:vsphere_dc]
|
30
|
+
dc = vim.serviceInstance.find_datacenter(dcname) or
|
31
|
+
fatal_exit("datacenter not found")
|
45
32
|
|
46
|
-
|
47
|
-
|
33
|
+
vm = find_in_folders(dc.vmFolder, RbVmomi::VIM::VirtualMachine, vmname) or
|
34
|
+
fatal_exit("VM #{vmname} not found")
|
48
35
|
|
49
|
-
|
50
|
-
|
51
|
-
|
36
|
+
vm.PowerOffVM_Task.wait_for_completion unless vm.runtime.powerState == "poweredOff"
|
37
|
+
vm.Destroy_Task
|
38
|
+
puts "Deleted virtual machine #{vmname}"
|
52
39
|
|
53
|
-
end
|
54
|
-
end
|
55
40
|
end
|
56
41
|
end
|
@@ -1,56 +1,42 @@
|
|
1
|
-
#r# Author:: Ezra Pagel (<ezra@cpan.org>)
|
2
|
-
# License:: Apache License, Version 2.0
|
3
|
-
#
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
-
# you may not use this file except in compliance with the License.
|
6
|
-
# You may obtain a copy of the License at
|
7
1
|
#
|
8
|
-
#
|
2
|
+
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
|
+
# License:: Apache License, Version 2.0
|
9
4
|
#
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
-
# See the License for the specific language governing permissions and
|
14
|
-
# limitations under the License.
|
15
|
-
|
16
5
|
require 'chef/knife'
|
17
|
-
require 'chef/knife/
|
6
|
+
require 'chef/knife/BaseVsphereCommand'
|
18
7
|
|
19
|
-
|
20
|
-
|
21
|
-
class VsphereVmList < VsphereBaseCommand
|
8
|
+
# Lists all known virtual machines in the configured datacenter
|
9
|
+
class Chef::Knife::VsphereVmList < Chef::Knife::BaseVsphereCommand
|
22
10
|
|
23
|
-
|
11
|
+
banner "knife vsphere vm list"
|
24
12
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
13
|
+
get_common_options
|
14
|
+
|
15
|
+
option :folder,
|
16
|
+
:short => "-f SHOWFOLDER",
|
17
|
+
:long => "--folder",
|
18
|
+
:description => "The folder to list VMs in"
|
31
19
|
|
32
|
-
|
20
|
+
def run
|
33
21
|
|
34
|
-
|
35
|
-
|
36
|
-
|
22
|
+
$stdout.sync = true
|
23
|
+
|
24
|
+
vim = get_vim_connection
|
37
25
|
|
38
26
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
27
|
+
dcname = config[:vsphere_dc] || Chef::Config[:knife][:vsphere_dc]
|
28
|
+
dc = vim.serviceInstance.find_datacenter(dcname) or abort "datacenter not found"
|
29
|
+
|
30
|
+
baseFolder = dc.vmFolder;
|
43
31
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
32
|
+
if config[:folder]
|
33
|
+
baseFolder = get_folders(dc.vmFolder).find { |f| f.name == config[:folder]} or
|
34
|
+
abort "no such folder #{config[:folder]}"
|
35
|
+
end
|
48
36
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
37
|
+
vms = find_all_in_folders(baseFolder, RbVmomi::VIM::VirtualMachine)
|
38
|
+
vms.each do |vm|
|
39
|
+
puts "#{ui.color("VM Name", :cyan)}: #{vm.name}"
|
54
40
|
end
|
55
41
|
end
|
56
42
|
end
|
@@ -2,20 +2,9 @@
|
|
2
2
|
# Author:: Ezra Pagel (<ezra@cpan.org>)
|
3
3
|
# License:: Apache License, Version 2.0
|
4
4
|
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
5
|
|
17
6
|
require 'chef/knife'
|
18
|
-
require 'chef/knife/
|
7
|
+
require 'chef/knife/BaseVsphereCommand'
|
19
8
|
require 'rbvmomi'
|
20
9
|
require 'netaddr'
|
21
10
|
|
@@ -29,17 +18,13 @@ PowerStates = {
|
|
29
18
|
PsSuspended => 'suspended'
|
30
19
|
}
|
31
20
|
|
32
|
-
|
21
|
+
# Manage power state of a virtual machine
|
22
|
+
class Chef::Knife::VsphereVmState < Chef::Knife::BaseVsphereCommand
|
33
23
|
|
34
|
-
banner "knife vsphere vm state (options)"
|
24
|
+
banner "knife vsphere vm state VMNAME (options)"
|
35
25
|
|
36
26
|
get_common_options
|
37
27
|
|
38
|
-
option :vmname,
|
39
|
-
:short => "-N VMNAME",
|
40
|
-
:long => "--vmname VMNAME",
|
41
|
-
:description => "The name for the new virtual machine"
|
42
|
-
|
43
28
|
option :state,
|
44
29
|
:short => "-s STATE",
|
45
30
|
:long => "--state STATE",
|
@@ -49,7 +34,12 @@ class Chef::Knife::VsphereVmState < Chef::Knife::VsphereBaseCommand
|
|
49
34
|
|
50
35
|
$stdout.sync = true
|
51
36
|
|
52
|
-
vmname =
|
37
|
+
vmname = @name_args[0]
|
38
|
+
if vmname.nil?
|
39
|
+
show_usage
|
40
|
+
ui.fatal("You must specify a virtual machine name")
|
41
|
+
exit 1
|
42
|
+
end
|
53
43
|
|
54
44
|
vim = get_vim_connection
|
55
45
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-vsphere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ezra Pagel
|
@@ -15,13 +15,29 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-06 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: netaddr
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 5
|
33
|
+
- 0
|
34
|
+
version: 1.5.0
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: chef
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
25
41
|
none: false
|
26
42
|
requirements:
|
27
43
|
- - ~>
|
@@ -33,11 +49,11 @@ dependencies:
|
|
33
49
|
- 0
|
34
50
|
version: 0.10.0
|
35
51
|
type: :runtime
|
36
|
-
version_requirements: *
|
52
|
+
version_requirements: *id002
|
37
53
|
- !ruby/object:Gem::Dependency
|
38
54
|
name: rbvmomi
|
39
55
|
prerelease: false
|
40
|
-
requirement: &
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
57
|
none: false
|
42
58
|
requirements:
|
43
59
|
- - ~>
|
@@ -49,7 +65,7 @@ dependencies:
|
|
49
65
|
- 3
|
50
66
|
version: 1.2.3
|
51
67
|
type: :runtime
|
52
|
-
version_requirements: *
|
68
|
+
version_requirements: *id003
|
53
69
|
description: VMware vSphere Support for Chef's Knife Command
|
54
70
|
email: ezra@cpan.org
|
55
71
|
executables: []
|
@@ -59,13 +75,13 @@ extensions: []
|
|
59
75
|
extra_rdoc_files: []
|
60
76
|
|
61
77
|
files:
|
78
|
+
- lib/chef/knife/BaseVsphereCommand.rb
|
62
79
|
- lib/chef/knife/vsphere_customization_list.rb
|
63
80
|
- lib/chef/knife/vsphere_template_list.rb
|
64
81
|
- lib/chef/knife/vsphere_vm_clone.rb
|
65
82
|
- lib/chef/knife/vsphere_vm_delete.rb
|
66
83
|
- lib/chef/knife/vsphere_vm_list.rb
|
67
84
|
- lib/chef/knife/vsphere_vm_state.rb
|
68
|
-
- lib/chef/knife/VsphereBaseCommand.rb
|
69
85
|
- lib/knife-vsphere/version.rb
|
70
86
|
has_rdoc: true
|
71
87
|
homepage:
|