knife-vcloud 1.0.0 → 1.1.0
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 +4 -4
- data/CHANGELOG.md +18 -0
- data/README.md +60 -9
- data/lib/chef/knife/common/vc_common.rb +87 -1
- data/lib/chef/knife/vc_commands.rb +1 -0
- data/lib/chef/knife/vc_configure.rb +71 -0
- data/lib/chef/knife/vm/vc_vm_config_guest.rb +1 -1
- data/lib/chef/knife/vm/vc_vm_config_network.rb +2 -0
- data/lib/chef/knife/vm/vc_vm_network.rb +132 -0
- data/lib/chef/knife/vm/vc_vm_set_info.rb +28 -1
- data/lib/chef/knife/vm/vc_vm_show.rb +1 -1
- data/lib/knife-vcloud/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e1a6581ab79e682545433b7cd7bfa2517c1be97
|
4
|
+
data.tar.gz: dddf81518b3eeb63a7d65e4493d522c57c34a998
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 232a90edc098da6619adbba3d7f67d6db238ad46bce3243f7c3b2aa7eeed0f7e8cc81d846ea0978d32fdf5161414d10c8d096a16c7d2b8ba63dfcabfef258311
|
7
|
+
data.tar.gz: bdff29d51a5dee502ab2c1ebc6db8e15a0f34c464a1b5a903cf93ba0d61d922864591e4bc18a4c578593db61349daf861c095dc78959dba3c8e41226c14c67d1
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
Changes
|
2
2
|
==
|
3
|
+
2013-12-13 (1.1.0)
|
4
|
+
--
|
5
|
+
|
6
|
+
This version introduces new features and deprecations.
|
7
|
+
Deprecated features will be dropped in the future release.
|
8
|
+
|
9
|
+
FEATURES:
|
10
|
+
|
11
|
+
* Add option *--override-guest* to `vm set info` to rename also its guest name (*false* by default for backward-compatibility)
|
12
|
+
* Add command `vm network [add|delete|edit]` to manage multiple networks
|
13
|
+
* Use RSA keys to manage passwords
|
14
|
+
* Add command `knife vc configure` to manage knife-vcloud's configuration
|
15
|
+
|
16
|
+
DEPRECATIONS:
|
17
|
+
|
18
|
+
* `vm config network` is now deprecated
|
19
|
+
* *knife[:vcloud_password_login]* is now deprecated and should be replaced using ```knife vc configure```
|
20
|
+
|
3
21
|
2013-11-29 (1.0.0)
|
4
22
|
--
|
5
23
|
|
data/README.md
CHANGED
@@ -42,6 +42,7 @@ USAGE
|
|
42
42
|
|
43
43
|
knife vc catalog item show [CATALOG_ITEM] (options)
|
44
44
|
knife vc catalog show [CATALOG] (options)
|
45
|
+
knife vc configure (options)
|
45
46
|
knife vc login (options)
|
46
47
|
knife vc network show [network] (options)
|
47
48
|
knife vc org list (options)
|
@@ -63,7 +64,8 @@ USAGE
|
|
63
64
|
knife vc vdc show VDC (options)
|
64
65
|
knife vc vm bootstrap [VM] (options)
|
65
66
|
knife vc vm config guest [VM] (options)
|
66
|
-
knife vc vm config network [VM] [NETWORK_NAME] (options)
|
67
|
+
[DEPRECATED] knife vc vm config network [VM] [NETWORK_NAME] (options)
|
68
|
+
knife vc vm network [add|delete|edit| [VM] [NETWORK] (options)
|
67
69
|
knife vc vm reboot [VM] (options)
|
68
70
|
knife vc vm reset [VM] (options)
|
69
71
|
knife vc vm set disks [VM] (options)
|
@@ -75,7 +77,20 @@ USAGE
|
|
75
77
|
|
76
78
|
###Configuration
|
77
79
|
|
78
|
-
|
80
|
+
A first configuration should be done using ```knife vc configure``` that would prompt user for
|
81
|
+
credentials and vCloud URL.
|
82
|
+
|
83
|
+
**DEPRECATION NOTE: *vcloud_password_login* has been deprecated and will be removed in future versions.**
|
84
|
+
|
85
|
+
E.g.,
|
86
|
+
|
87
|
+
$ bundle exec knife vc configure
|
88
|
+
Loading existing pem
|
89
|
+
vCloud URL (https://mycloud.test.com):
|
90
|
+
vCloud username (testuser):
|
91
|
+
...
|
92
|
+
|
93
|
+
Other configuration options can be set either via arguments or inside the *.chef/knife.rb* file.
|
79
94
|
The only difference is that in *knife.rb* dashes must be converted to underscores
|
80
95
|
and *vcloud_* must be prepended.
|
81
96
|
|
@@ -95,7 +110,6 @@ to use:
|
|
95
110
|
The following options specify user's credentials and thus are accepted by every command:
|
96
111
|
|
97
112
|
--user-login USER
|
98
|
-
--password-login SECRET
|
99
113
|
--org-login ORGANIZATION
|
100
114
|
|
101
115
|
**Knife.rb configuration example:**
|
@@ -103,7 +117,7 @@ The following options specify user's credentials and thus are accepted by every
|
|
103
117
|
knife[:vcloud_url] = 'https://vcloud.server.org'
|
104
118
|
knife[:vcloud_org_login] = 'vcloud_organization'
|
105
119
|
knife[:vcloud_user_login] = 'vcloud_user'
|
106
|
-
knife[:
|
120
|
+
knife[:vcloud_password] = <MUST BE GENERATED WITH knife vc configure>
|
107
121
|
(OPTIONAL) knife[:vcloud_api_version] = '1.5'
|
108
122
|
|
109
123
|
####IDs and names
|
@@ -386,6 +400,9 @@ _Example:_
|
|
386
400
|
###Set VM's CPUs / Memory / Name
|
387
401
|
This command sets name, CPUs and RAM info for a given VM.
|
388
402
|
|
403
|
+
Renaming a VM implies renaming its guest name.
|
404
|
+
Use ```--no-override-guest-name``` if you want to preserve the old name.
|
405
|
+
|
389
406
|
_Example:_
|
390
407
|
|
391
408
|
$ knife vc vm set info --name NewName --vapp vApp_test vm-test
|
@@ -422,16 +439,50 @@ _Example:_
|
|
422
439
|
Summary: Status: success - time elapsed: 7.21 seconds
|
423
440
|
|
424
441
|
###VM's network configuration
|
425
|
-
|
426
|
-
|
442
|
+
VM networks can be added, removed and modified using the *vm network* command.
|
443
|
+
This commands allows for basic VM network configuration and accepts several options to configure a given network (see *knife vc vm network --help* for details).
|
427
444
|
|
428
445
|
Please note that you must use the human readable name of the network (i.e., _TestNet\_1_).
|
429
446
|
|
430
|
-
|
447
|
+
**DEPRECATION NOTE: The command *vm config network* has been deprecated and will be removed in future versions.**
|
448
|
+
|
449
|
+
_Add example:_
|
450
|
+
|
451
|
+
$ knife vc vm network edit testvm TST_Data
|
452
|
+
Forcing parent network to itself
|
453
|
+
VM network configuration...
|
454
|
+
Guest customizations must be applied to a stopped VM, but it's running. Can I STOP it? (Y/N) y
|
455
|
+
Stopping VM...
|
456
|
+
Summary: Status: success - time elapsed: 1.617 seconds
|
457
|
+
Adding TST_Data to VM...
|
458
|
+
Summary: Status: success - time elapsed: 5.866 seconds
|
459
|
+
Forcing Guest Customization to apply changes...
|
460
|
+
Summary: Status: success - time elapsed: 13.387 seconds
|
461
|
+
|
462
|
+
_Edit example:_
|
463
|
+
|
464
|
+
$ knife vc vm network edit testvm TST_Data --ip-allocation-mode DHCP
|
465
|
+
Forcing parent network to itself
|
466
|
+
VM network configuration...
|
467
|
+
Guest customizations must be applied to a stopped VM, but it's running. Can I STOP it? (Y/N) y
|
468
|
+
Stopping VM...
|
469
|
+
Summary: Status: success - time elapsed: 5.34 seconds
|
470
|
+
VM network configuration for TST_Data...
|
471
|
+
Summary: Status: success - time elapsed: 3.397 seconds
|
472
|
+
Forcing Guest Customization to apply changes...
|
473
|
+
Summary: Status: success - time elapsed: 8.01 seconds
|
474
|
+
|
475
|
+
_Delete example:_
|
431
476
|
|
432
|
-
$ knife vc vm
|
477
|
+
$ knife vc vm network delete test_vm TST_Data
|
433
478
|
VM network configuration...
|
434
|
-
|
479
|
+
Guest customizations must be applied to a stopped VM, but it's running. Can I STOP it? (Y/N) y
|
480
|
+
Stopping VM...
|
481
|
+
Summary: Status: success - time elapsed: 4.77 seconds
|
482
|
+
Removing TST_Data from VM...
|
483
|
+
Summary: Status: success - time elapsed: 3.614 seconds
|
484
|
+
Forcing Guest Customization to apply changes...
|
485
|
+
Summary: Status: success - time elapsed: 11.194 seconds
|
435
486
|
|
436
487
|
###VM's Guest Customization configuration
|
437
488
|
This command allows for basic VM Guest Customization configuration.
|
@@ -18,9 +18,13 @@
|
|
18
18
|
|
19
19
|
require 'chef/knife'
|
20
20
|
require 'date'
|
21
|
+
require 'openssl'
|
22
|
+
require 'base64'
|
21
23
|
|
22
24
|
class Chef
|
23
25
|
class Knife
|
26
|
+
class ConfigurationError < StandardError; end
|
27
|
+
|
24
28
|
module VcCommon
|
25
29
|
def self.included(includer)
|
26
30
|
includer.class_eval do
|
@@ -75,10 +79,28 @@ class Chef
|
|
75
79
|
|
76
80
|
def connection
|
77
81
|
unless @connection
|
82
|
+
pemfile = locate_config_value(:vcloud_pem)
|
83
|
+
|
84
|
+
if locate_config_value(:vcloud_password_login)
|
85
|
+
ui.info("#{ui.color('DEPRECATION WARNING:', :bold)} knife[:vcloud_password_login] is deprecated" \
|
86
|
+
" and will be removed in the next version. You should remove it and run 'knife vc configure'.")
|
87
|
+
passwd = locate_config_value(:vcloud_password_login)
|
88
|
+
else
|
89
|
+
unless pemfile
|
90
|
+
raise ConfigurationError, "PEM file not configured. Please run 'knife vc configure'"
|
91
|
+
end
|
92
|
+
|
93
|
+
unless locate_config_value(:vcloud_password)
|
94
|
+
raise ConfigurationError, "Password not configured. Please run 'knife vc configure'"
|
95
|
+
end
|
96
|
+
|
97
|
+
passwd = get_password(pemfile)
|
98
|
+
end
|
99
|
+
|
78
100
|
@connection = VCloudClient::Connection.new(
|
79
101
|
locate_config_value(:vcloud_url),
|
80
102
|
locate_config_value(:vcloud_user_login),
|
81
|
-
|
103
|
+
passwd,
|
82
104
|
locate_config_value(:vcloud_org_login),
|
83
105
|
locate_config_value(:vcloud_api_version)
|
84
106
|
)
|
@@ -119,6 +141,13 @@ class Chef
|
|
119
141
|
end
|
120
142
|
end
|
121
143
|
|
144
|
+
def deprecation_msg(value)
|
145
|
+
if value && !value.empty?
|
146
|
+
ui.info("#{ui.color('DEPRECATION WARNING:', :bold)} This method is deprecated" \
|
147
|
+
" and will be removed in the next version. You should use #{value}.")
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
122
151
|
def locate_config_value(key)
|
123
152
|
key = key.to_sym
|
124
153
|
Chef::Config[:knife][key] || config[key]
|
@@ -147,6 +176,63 @@ class Chef
|
|
147
176
|
collection.sort_by {|k, v| k }
|
148
177
|
end
|
149
178
|
|
179
|
+
# Generate a new key pair and store it on knife.rb
|
180
|
+
def generate_key(dir="#{File.join(Dir.home, '.chef')}", output="vc_key.pem")
|
181
|
+
key = OpenSSL::PKey::RSA.new 2048
|
182
|
+
|
183
|
+
pemfile = File.join(dir, output)
|
184
|
+
|
185
|
+
File.open("#{pemfile}", 'w') do |io| io.write key.to_pem end
|
186
|
+
FileUtils.chmod 0600, pemfile
|
187
|
+
|
188
|
+
store_config(:vcloud_pem, pemfile)
|
189
|
+
end
|
190
|
+
|
191
|
+
# Store a password in knife.rb
|
192
|
+
def store_password(keyfile)
|
193
|
+
pub_key = OpenSSL::PKey::RSA.new(File.read(keyfile)).public_key
|
194
|
+
result = Base64.encode64(pub_key.public_encrypt(ui.ask("Enter your password: ") { |q| q.echo = false }))
|
195
|
+
store_config(:vcloud_password, result.gsub("\n", ''))
|
196
|
+
end
|
197
|
+
|
198
|
+
# Retrieve a stored password
|
199
|
+
def get_password(keyfile)
|
200
|
+
priv_key = OpenSSL::PKey::RSA.new(File.read(keyfile))
|
201
|
+
result = priv_key.private_decrypt(Base64.decode64(locate_config_value(:vcloud_password)))
|
202
|
+
result
|
203
|
+
end
|
204
|
+
|
205
|
+
# Update knife.rb with an entry knife[:KEY] = VALUE
|
206
|
+
#
|
207
|
+
# It checks whether a given configuration already exists and, if so, updates it
|
208
|
+
def store_config(key, value)
|
209
|
+
configfile = File.join(Dir.home, '.chef', 'knife.rb')
|
210
|
+
old_config = File.open(configfile, 'r').readlines
|
211
|
+
full_key = "knife[:#{key}]"
|
212
|
+
|
213
|
+
if Chef::Config[:knife][key]
|
214
|
+
# Replace existing key
|
215
|
+
File.open("#{configfile}.tmp", 'w') do |new_config|
|
216
|
+
old_config.each do |line|
|
217
|
+
if line =~ Regexp.new("^#{Regexp.escape(full_key)}")
|
218
|
+
line = "#{full_key} = '#{value}'"
|
219
|
+
end
|
220
|
+
new_config.puts line
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
FileUtils.mv("#{configfile}.tmp", configfile)
|
225
|
+
else
|
226
|
+
# Create a new one
|
227
|
+
File.open(configfile, 'a') do |new_config|
|
228
|
+
new_config.puts "#{full_key} = '#{value}'"
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
# Reload Chef configuration
|
233
|
+
self.configure_chef
|
234
|
+
end
|
235
|
+
|
150
236
|
private
|
151
237
|
def humanize_elapsed_time(start_time, end_time)
|
152
238
|
start_time = Time.parse(start_time || Time.now)
|
@@ -56,6 +56,7 @@ require 'chef/knife/vapp/vc_vapp_snapshot'
|
|
56
56
|
require 'chef/knife/common/vc_vm_common'
|
57
57
|
require 'chef/knife/vm/vc_vm_config_guest'
|
58
58
|
require 'chef/knife/vm/vc_vm_config_network'
|
59
|
+
require 'chef/knife/vm/vc_vm_network'
|
59
60
|
require 'chef/knife/vm/vc_vm_show'
|
60
61
|
require 'chef/knife/vm/vc_vm_set_info'
|
61
62
|
require 'chef/knife/vm/vc_vm_set_disks'
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/knife/common/vc_common'
|
20
|
+
|
21
|
+
class Chef
|
22
|
+
class Knife
|
23
|
+
class VcConfigure < Chef::Knife
|
24
|
+
include Knife::VcCommon
|
25
|
+
|
26
|
+
banner "knife vc configure (options)"
|
27
|
+
|
28
|
+
option :change_password,
|
29
|
+
:short => "-p",
|
30
|
+
:long => "--[no-]change-password",
|
31
|
+
:description => "Change the stored password",
|
32
|
+
:boolean => true,
|
33
|
+
:default => false
|
34
|
+
|
35
|
+
def run
|
36
|
+
$stdout.sync = true
|
37
|
+
|
38
|
+
# Load or generate a keypair to encrypt info
|
39
|
+
pemfile = locate_config_value(:vcloud_pem)
|
40
|
+
if pemfile
|
41
|
+
ui.msg("Loading existing pem")
|
42
|
+
keyfile = "#{pemfile}"
|
43
|
+
else
|
44
|
+
ui.msg("PEM file not existing. Creating one.")
|
45
|
+
generate_key()
|
46
|
+
keyfile = locate_config_value(:vcloud_pem)
|
47
|
+
end
|
48
|
+
|
49
|
+
value = ui.ask("vCloud URL (%s): " % locate_config_value(:vcloud_url))
|
50
|
+
unless value.empty?
|
51
|
+
store_config(:vcloud_url, value)
|
52
|
+
end
|
53
|
+
|
54
|
+
value = ui.ask("vCloud username (%s): " % locate_config_value(:vcloud_user_login))
|
55
|
+
unless value.empty?
|
56
|
+
store_config(:vcloud_user_login, value)
|
57
|
+
end
|
58
|
+
|
59
|
+
value = ui.ask("vCloud API version (%s): " % (locate_config_value(:vcloud_api_version) || "5.1"))
|
60
|
+
unless value.empty?
|
61
|
+
store_config(:vcloud_api_version, value)
|
62
|
+
end
|
63
|
+
|
64
|
+
if !locate_config_value(:vcloud_password) ||
|
65
|
+
locate_config_value(:change_password)
|
66
|
+
store_password(keyfile)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -91,7 +91,7 @@ class Chef
|
|
91
91
|
|
92
92
|
guest_name = sanitize_guest_name(computer_name)
|
93
93
|
|
94
|
-
ui.msg "Renaming guest name to #{guest_name}..."
|
94
|
+
ui.msg "Renaming guest name to #{guest_name}..." if locate_config_value(:guest_computer_name)
|
95
95
|
task_id, response = connection.set_vm_guest_customization vm[:id], guest_name, config
|
96
96
|
|
97
97
|
ui.msg "VM guest configuration..."
|
@@ -0,0 +1,132 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Stefano Tortarolo (<stefano.tortarolo@gmail.com>)
|
3
|
+
# Copyright:: Copyright (c) 2012-2013
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
class Chef
|
20
|
+
class Knife
|
21
|
+
class VcVmNetwork < Chef::Knife
|
22
|
+
include Knife::VcCommon
|
23
|
+
include Knife::VcVmCommon
|
24
|
+
include Knife::VcNetworkCommon
|
25
|
+
|
26
|
+
banner "knife vc vm network [add|delete|edit| [VM] [NETWORK] (options)"
|
27
|
+
|
28
|
+
option :vm_net_index,
|
29
|
+
:long => "--net-index NETWORK_IDX",
|
30
|
+
:description => "Index of the current network interface"
|
31
|
+
|
32
|
+
option :vm_net_ip,
|
33
|
+
:long => "--net-ip NETWORK_IP",
|
34
|
+
:description => "IP of the current network interface"
|
35
|
+
|
36
|
+
option :vm_net_is_connected,
|
37
|
+
:long => "--net-[no-]connected",
|
38
|
+
:description => "Toggle IsConnected flag of the current network interface (default true)",
|
39
|
+
:boolean => true,
|
40
|
+
:default => true
|
41
|
+
|
42
|
+
option :vm_ip_allocation_mode,
|
43
|
+
:long => "--ip-allocation-mode ALLOCATION_MODE",
|
44
|
+
:description => "Set IP allocation mode of the current network interface (default POOL)",
|
45
|
+
:default => 'POOL'
|
46
|
+
|
47
|
+
def run
|
48
|
+
$stdout.sync = true
|
49
|
+
|
50
|
+
command_arg = @name_args.shift
|
51
|
+
vm_arg = @name_args.shift
|
52
|
+
network_arg = @name_args.shift
|
53
|
+
|
54
|
+
unless command_arg =~ /add|delete|edit/
|
55
|
+
raise ArgumentError, "Invalid command #{command_arg} supplied. Only add, delete and edit are allowed."
|
56
|
+
end
|
57
|
+
|
58
|
+
command = command_arg.to_sym
|
59
|
+
|
60
|
+
config = {
|
61
|
+
:network_index => locate_config_value(:vm_net_index),
|
62
|
+
:ip => locate_config_value(:vm_net_ip),
|
63
|
+
:is_connected => locate_config_value(:vm_net_is_connected),
|
64
|
+
:ip_allocation_mode => locate_config_value(:vm_ip_allocation_mode),
|
65
|
+
:retain_network => locate_config_value(:retain_network)
|
66
|
+
}
|
67
|
+
|
68
|
+
connection.login
|
69
|
+
|
70
|
+
vm = get_vm(vm_arg)
|
71
|
+
network = get_network network_arg
|
72
|
+
|
73
|
+
unless network
|
74
|
+
raise new ArgumentError, "Network #{network_arg} not found in vDC."
|
75
|
+
end
|
76
|
+
|
77
|
+
unless command == :delete
|
78
|
+
parent_network_arg = locate_config_value(:parent_network)
|
79
|
+
if parent_network_arg
|
80
|
+
ui.msg "Retrieving parent network details"
|
81
|
+
parent_network = get_network parent_network_arg
|
82
|
+
config[:parent_network] = { :id => parent_network[:id],
|
83
|
+
:name => parent_network[:name] }
|
84
|
+
else
|
85
|
+
ui.msg "Forcing parent network to itself"
|
86
|
+
config[:parent_network] = { :id => network[:id],
|
87
|
+
:name => network[:name] }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
ui.msg "VM network configuration..."
|
92
|
+
stop_if_running(connection, vm)
|
93
|
+
|
94
|
+
case command
|
95
|
+
when :add
|
96
|
+
ui.msg "Adding #{network[:name]} to VM..."
|
97
|
+
task_id, response = connection.add_vm_network vm[:id], network, config
|
98
|
+
result = wait_task(connection, task_id)
|
99
|
+
when :delete
|
100
|
+
ui.msg "Removing #{network[:name]} from VM..."
|
101
|
+
task_id, response = connection.delete_vm_network vm[:id], network
|
102
|
+
result = wait_task(connection, task_id)
|
103
|
+
when :edit
|
104
|
+
ui.msg "VM network configuration for #{network[:name]}..."
|
105
|
+
task_id, response = connection.edit_vm_network vm[:id], network, config
|
106
|
+
result = wait_task(connection, task_id)
|
107
|
+
end
|
108
|
+
|
109
|
+
if result
|
110
|
+
unless vm[:guest_customizations][:enabled]
|
111
|
+
config = {
|
112
|
+
:enabled => true,
|
113
|
+
:admin_passwd_enabled => vm[:guest_customizations][:admin_passwd_enabled],
|
114
|
+
:admin_passwd => vm[:guest_customizations][:admin_passwd],
|
115
|
+
:customization_script => script
|
116
|
+
}
|
117
|
+
|
118
|
+
ui.msg "Enabling Guest Customization to apply changes..."
|
119
|
+
task_id, response = connection.set_vm_guest_customization vm[:id], guest_name, config
|
120
|
+
wait_task(connection, task_id)
|
121
|
+
end
|
122
|
+
|
123
|
+
ui.msg "Forcing Guest Customization to apply changes..."
|
124
|
+
task_id = connection.force_customization_vm vm[:id]
|
125
|
+
wait_task(connection, task_id)
|
126
|
+
end
|
127
|
+
|
128
|
+
connection.logout
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
@@ -36,6 +36,12 @@ class Chef
|
|
36
36
|
:long => "--name VM_NAME",
|
37
37
|
:description => "Rename the VM"
|
38
38
|
|
39
|
+
option :override_guest_name,
|
40
|
+
:long => "--[no-]override-guest",
|
41
|
+
:description => "Override also Guest Name (used with --name)",
|
42
|
+
:boolean => true,
|
43
|
+
:default => false
|
44
|
+
|
39
45
|
def run
|
40
46
|
$stdout.sync = true
|
41
47
|
|
@@ -72,7 +78,28 @@ class Chef
|
|
72
78
|
task_id = connection.rename_vm vm[:id], vm_name
|
73
79
|
result = wait_task(connection, task_id)
|
74
80
|
|
75
|
-
return result
|
81
|
+
return unless result && locate_config_value(:override_guest_name)
|
82
|
+
|
83
|
+
# Change also its guest computer name
|
84
|
+
guest_config = {:enabled => true}
|
85
|
+
|
86
|
+
# Inheriting admin_passwd if enabled
|
87
|
+
if vm[:guest_customizations][:admin_passwd_enabled]
|
88
|
+
guest_config[:admin_passwd] = vm[:guest_customizations][:admin_passwd]
|
89
|
+
end
|
90
|
+
|
91
|
+
stop_if_running(connection, vm)
|
92
|
+
|
93
|
+
guest_name = sanitize_guest_name(vm_name)
|
94
|
+
|
95
|
+
ui.msg "Renaming guest name to #{guest_name}..."
|
96
|
+
task_id, response = connection.set_vm_guest_customization vm[:id], guest_name, guest_config
|
97
|
+
|
98
|
+
wait_task(connection, task_id)
|
99
|
+
|
100
|
+
ui.msg "Forcing Guest Customization..."
|
101
|
+
task_id = connection.force_customization_vm vm[:id]
|
102
|
+
wait_task(connection, task_id)
|
76
103
|
end
|
77
104
|
end
|
78
105
|
end
|
data/lib/knife-vcloud/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-vcloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Tortarolo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 1.
|
47
|
+
version: 1.1.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 1.
|
54
|
+
version: 1.1.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: winrm
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,11 +103,13 @@ files:
|
|
103
103
|
- lib/chef/knife/vapp/vc_vapp_stop.rb
|
104
104
|
- lib/chef/knife/vapp/vc_vapp_suspend.rb
|
105
105
|
- lib/chef/knife/vc_commands.rb
|
106
|
+
- lib/chef/knife/vc_configure.rb
|
106
107
|
- lib/chef/knife/vc_login.rb
|
107
108
|
- lib/chef/knife/vdc/vc_vdc_show.rb
|
108
109
|
- lib/chef/knife/vm/vc_vm_bootstrap.rb
|
109
110
|
- lib/chef/knife/vm/vc_vm_config_guest.rb
|
110
111
|
- lib/chef/knife/vm/vc_vm_config_network.rb
|
112
|
+
- lib/chef/knife/vm/vc_vm_network.rb
|
111
113
|
- lib/chef/knife/vm/vc_vm_reboot.rb
|
112
114
|
- lib/chef/knife/vm/vc_vm_reset.rb
|
113
115
|
- lib/chef/knife/vm/vc_vm_set_disks.rb
|
@@ -142,3 +144,4 @@ signing_key:
|
|
142
144
|
specification_version: 4
|
143
145
|
summary: A knife plugin for the VMWare vCloud API
|
144
146
|
test_files: []
|
147
|
+
has_rdoc:
|