knife-vcenter 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/CHANGELOG.md +9 -1
- data/README.md +7 -4
- data/lib/chef/knife/cloud/vcenter_service.rb +43 -8
- data/lib/chef/knife/cloud/vcenter_service_options.rb +1 -1
- data/lib/chef/knife/vcenter_vm_clone.rb +12 -4
- data/lib/knife-vcenter/version.rb +1 -1
- data/lib/support/clone_vm.rb +6 -5
- 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: 349985f969ef2f03208406e79737a3fec3f8b3d8
|
4
|
+
data.tar.gz: a805e81d085f8e00c1128e1f117260606b5a9293
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4071809835cf22c85f8a1d5daab0681b6feb2d0f252bd6c9a293a1158f169800d02755a9f48852b424aad049d2ef549a2184fd50e3e373ca0d831972a0ac4e7
|
7
|
+
data.tar.gz: '009aeb4f2f77b51187f2cc856d2a43103407655331b15057fa092ce5c2fb8631ca945ac02e6be0b29e1e8357889041b9d8b83671e572d9f66548bcf9b44ed5af'
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,16 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [1.
|
3
|
+
## [1.1.0](https://github.com/chef/knife-vcenter/tree/1.1.0) (2017-09-13)
|
4
|
+
[Full Changelog](https://github.com/chef/knife-vcenter/compare/v1.0.0...1.1.0)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- Updated to make resource\_pool and targethost optional [\#6](https://github.com/chef/knife-vcenter/pull/6) ([russellseymour](https://github.com/russellseymour))
|
9
|
+
|
10
|
+
## [v1.0.0](https://github.com/chef/knife-vcenter/tree/v1.0.0) (2017-08-28)
|
4
11
|
**Merged pull requests:**
|
5
12
|
|
13
|
+
- Added new option to state wether vCenter SDK logs should be displayed [\#4](https://github.com/chef/knife-vcenter/pull/4) ([russellseymour](https://github.com/russellseymour))
|
6
14
|
- 1.0.0 release [\#3](https://github.com/chef/knife-vcenter/pull/3) ([jjasghar](https://github.com/jjasghar))
|
7
15
|
- Walking through the knife-vcenter code [\#2](https://github.com/chef/knife-vcenter/pull/2) ([jjasghar](https://github.com/jjasghar))
|
8
16
|
- Useful information for public release. [\#1](https://github.com/chef/knife-vcenter/pull/1) ([jjasghar](https://github.com/jjasghar))
|
data/README.md
CHANGED
@@ -50,7 +50,7 @@ knife[:vcenter_disable_ssl_verify] = true # if you want to disable SSL checking
|
|
50
50
|
or alternatively you can supply them on the command-line:
|
51
51
|
|
52
52
|
```bash
|
53
|
-
knife vcenter _command_ --vcenter-username myuser --
|
53
|
+
knife vcenter _command_ --vcenter-username myuser --vcenter-password mypassword
|
54
54
|
```
|
55
55
|
|
56
56
|
## Usage
|
@@ -124,13 +124,16 @@ _The IP address of the machine is not returned yet as this requires a call to a
|
|
124
124
|
|
125
125
|
Create a new machine by cloning an existing machine or a template. This machine will be bootstrapped by Chef, as long as all the relevant details are in the `knife.rb` file.
|
126
126
|
|
127
|
-
|
127
|
+
The following parameters are required:
|
128
128
|
|
129
|
-
- `--targethost` - The host that the virtual machine should be created on
|
130
|
-
- `--folder` - Folder that machine should be stored in. This must already exist.
|
131
129
|
- `--datacenter` - Datacenter in the vSphere environment that controls the target host
|
132
130
|
- `--template` - Name of the virtual machine or template to use
|
133
131
|
|
132
|
+
There are some optional parameters that can be specified:
|
133
|
+
|
134
|
+
- `--targethost` - The host that the virtual machine should be created on. If not specified the first host in the cluster is used.
|
135
|
+
- `--folder` - Folder that machine should be stored in. If specified this must already exist.
|
136
|
+
|
134
137
|
```
|
135
138
|
$ knife vcenter vm clone example-01 --targethost 172.16.20.3 --folder example --ssh-password P@ssw0rd! --datacenter Datacenter --template ubuntu16-template -N example-01
|
136
139
|
Creating new machine
|
@@ -97,10 +97,14 @@ class Chef
|
|
97
97
|
case options[:type]
|
98
98
|
when "clone"
|
99
99
|
|
100
|
+
datacenter_exists?(options[:datacenter])
|
101
|
+
|
100
102
|
# Some of ht eoptions need to be the ID of the component in VMWAre
|
101
103
|
# Update these using the REST API so that they can be passed to the support library
|
102
104
|
options[:targethost] = get_host(options[:targethost])
|
103
105
|
|
106
|
+
options[:resource_pool] = get_resource_pool(options[:resource_pool])
|
107
|
+
|
104
108
|
# Configure the folder option as a has with the name an the id
|
105
109
|
options[:folder] = {
|
106
110
|
name: options[:folder],
|
@@ -159,6 +163,14 @@ class Chef
|
|
159
163
|
Com::Vmware::Vcenter::Cluster.new(vapi_config).list()
|
160
164
|
end
|
161
165
|
|
166
|
+
def datacenter_exists?(name)
|
167
|
+
filter = Com::Vmware::Vcenter::Datacenter::FilterSpec.new(names: Set.new([name]))
|
168
|
+
dc_obj = Com::Vmware::Vcenter::Datacenter.new(vapi_config)
|
169
|
+
dc = dc_obj.list(filter)
|
170
|
+
|
171
|
+
raise format('Unable to find data center: %s', name) if dc.empty?
|
172
|
+
end
|
173
|
+
|
162
174
|
def get_folder(name)
|
163
175
|
# Create a filter to ensure that only the named folder is returned
|
164
176
|
filter = Com::Vmware::Vcenter::Folder::FilterSpec.new({names: Set.new([name])})
|
@@ -170,23 +182,46 @@ class Chef
|
|
170
182
|
end
|
171
183
|
|
172
184
|
def get_host(name)
|
173
|
-
filter = Com::Vmware::Vcenter::Host::FilterSpec.new({names: Set.new([name])})
|
174
185
|
host_obj = Com::Vmware::Vcenter::Host.new(vapi_config)
|
175
|
-
|
186
|
+
|
187
|
+
if name.nil?
|
188
|
+
host = host_obj.list
|
189
|
+
else
|
190
|
+
filter = Com::Vmware::Vcenter::Host::FilterSpec.new({names: Set.new([name])})
|
191
|
+
host = host_obj.list(filter)
|
192
|
+
end
|
193
|
+
|
176
194
|
host[0].host
|
177
195
|
end
|
178
196
|
|
179
197
|
def get_datastore(name)
|
180
|
-
filter = Com::Vmware::Vcenter::Datastore::FilterSpec.new({names: Set.new([name])})
|
181
198
|
datastore_obj = Com::Vmware::Vcenter::Datastore.new(vapi_config)
|
182
|
-
|
199
|
+
|
200
|
+
if name.nil?
|
201
|
+
datastore = datastore_obj.list
|
202
|
+
else
|
203
|
+
filter = Com::Vmware::Vcenter::Datastore::FilterSpec.new({names: Set.new([name])})
|
204
|
+
datastore = datastore_obj.list(filter)
|
205
|
+
end
|
206
|
+
|
183
207
|
datastore[0].datastore
|
184
208
|
end
|
185
209
|
|
186
|
-
def
|
187
|
-
|
188
|
-
|
189
|
-
|
210
|
+
def get_resource_pool(name)
|
211
|
+
# Create a resource pool object
|
212
|
+
rp_obj = Com::Vmware::Vcenter::ResourcePool.new(vapi_config)
|
213
|
+
|
214
|
+
# If a name has been set then try to find it, otherwise use the first
|
215
|
+
# resource pool that can be found
|
216
|
+
if name.nil?
|
217
|
+
resource_pool = rp_obj.list
|
218
|
+
else
|
219
|
+
# create a filter to find the named resource pool
|
220
|
+
filter = Com::Vmware::Vcenter::ResourcePool::FilterSpec.new(names: Set.new([name]))
|
221
|
+
resource_pool = rp_obj.list(filter)
|
222
|
+
raise format('Unable to find Resource Pool: %s', name) if resource_pool.nil?
|
223
|
+
end
|
224
|
+
|
190
225
|
resource_pool[0].resource_pool
|
191
226
|
end
|
192
227
|
|
@@ -32,7 +32,7 @@ class Chef
|
|
32
32
|
include VcenterServiceOptions
|
33
33
|
include ServerCreateOptions
|
34
34
|
|
35
|
-
banner 'knife vcenter vm clone NAME'
|
35
|
+
banner 'knife vcenter vm clone NAME (options)'
|
36
36
|
|
37
37
|
option :template,
|
38
38
|
long: "--template NAME",
|
@@ -55,6 +55,14 @@ class Chef
|
|
55
55
|
long: "--folder NAME",
|
56
56
|
description: "Folder to deploy the new machine into"
|
57
57
|
|
58
|
+
option :pool,
|
59
|
+
long: "--pool NAME",
|
60
|
+
description: "Name of resource pool to use when creating the machine"
|
61
|
+
|
62
|
+
option :node_ssl_verify_mode,
|
63
|
+
:long => "--node-ssl-verify-mode [peer|none]",
|
64
|
+
:description => "Whether or not to verify the SSL cert for all HTTPS requests."
|
65
|
+
|
58
66
|
def validate_params!
|
59
67
|
super
|
60
68
|
|
@@ -62,7 +70,7 @@ class Chef
|
|
62
70
|
ui.error('You must provide the name of the new machine')
|
63
71
|
end
|
64
72
|
|
65
|
-
check_for_missing_config_values!(:template, :
|
73
|
+
check_for_missing_config_values!(:template, :datacenter)
|
66
74
|
end
|
67
75
|
|
68
76
|
def before_exec_command
|
@@ -75,9 +83,9 @@ class Chef
|
|
75
83
|
targethost: locate_config_value(:targethost),
|
76
84
|
datacenter: locate_config_value(:datacenter),
|
77
85
|
poweron: !locate_config_value(:disable_power_on),
|
78
|
-
folder: locate_config_value(:folder)
|
86
|
+
folder: locate_config_value(:folder),
|
87
|
+
resource_pool: locate_config_value(:pool),
|
79
88
|
}
|
80
|
-
|
81
89
|
end
|
82
90
|
|
83
91
|
def before_bootstrap
|
data/lib/support/clone_vm.rb
CHANGED
@@ -31,16 +31,18 @@ class Support
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def clone
|
34
|
-
|
35
34
|
# set the datacenter name
|
36
35
|
dc = vim.serviceInstance.find_datacenter(options[:datacenter])
|
37
36
|
src_vm = dc.find_vm(options[:template])
|
38
|
-
|
37
|
+
|
38
|
+
raise format("Unable to find template: %s", options[:template]) if src_vm.nil?
|
39
39
|
|
40
40
|
# Specify where the machine is going to be created
|
41
41
|
relocate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec
|
42
42
|
relocate_spec.host = options[:targethost]
|
43
|
-
|
43
|
+
|
44
|
+
# Set the resource pool
|
45
|
+
relocate_spec.pool = options[:resource_pool]
|
44
46
|
|
45
47
|
clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(location: relocate_spec,
|
46
48
|
powerOn: options[:poweron],
|
@@ -49,12 +51,11 @@ class Support
|
|
49
51
|
# Set the folder to use
|
50
52
|
dest_folder = options[:folder].nil? ? src_vm.parent : options[:folder][:id]
|
51
53
|
|
52
|
-
puts "Cloning the template to create the
|
54
|
+
puts "Cloning the template '#{options[:template]}' to create the VM..."
|
53
55
|
task = src_vm.CloneVM_Task(folder: dest_folder, name: options[:name], spec: clone_spec)
|
54
56
|
# TODO: it would be nice to have dots to tell you it's working here
|
55
57
|
task.wait_for_completion
|
56
58
|
|
57
|
-
|
58
59
|
# get the IP address of the machine for bootstrapping
|
59
60
|
# machine name is based on the path, e.g. that includes the folder
|
60
61
|
name = options[:folder].nil? ? options[:name] : format("%s/%s", options[:folder][:name], options[:name])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-vcenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef Partner Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|