fog-vsphere 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +33 -0
- data/.rubocop_todo.yml +41 -49
- data/.travis.yml +2 -1
- data/CHANGELOG.md +16 -0
- data/lib/fog/vsphere/compute.rb +6 -2
- data/lib/fog/vsphere/models/compute/host.rb +1 -0
- data/lib/fog/vsphere/models/compute/interface.rb +2 -1
- data/lib/fog/vsphere/models/compute/interfaces.rb +1 -1
- data/lib/fog/vsphere/models/compute/server.rb +1 -0
- data/lib/fog/vsphere/models/compute/volume.rb +0 -2
- data/lib/fog/vsphere/requests/compute/cloudinit_to_customspec.rb +3 -0
- data/lib/fog/vsphere/requests/compute/get_datacenter.rb +3 -2
- data/lib/fog/vsphere/requests/compute/get_folder.rb +22 -18
- data/lib/fog/vsphere/requests/compute/list_hosts.rb +2 -0
- data/lib/fog/vsphere/requests/compute/list_vm_cdroms.rb +1 -0
- data/lib/fog/vsphere/requests/compute/list_vm_volumes.rb +1 -0
- data/lib/fog/vsphere/requests/compute/modify_vm_interface.rb +1 -1
- data/lib/fog/vsphere/requests/compute/vm_clone.rb +5 -1
- data/lib/fog/vsphere/requests/compute/vm_relocate.rb +53 -5
- data/lib/fog/vsphere/version.rb +1 -1
- data/tests/compute_tests.rb +1 -0
- data/tests/requests/compute/vm_power_off_tests.rb +1 -1
- data/tests/requests/compute/vm_suspend_tests.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45a6779fc97119bf814c810a3953731bb574e97dc2a806922cfe7291f34c5acb
|
4
|
+
data.tar.gz: 8606ad0e48b0715b2cfcbbc4e2d1e5976f93a6bce82942fb456d8c3acdd37b85
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02a8cf0c88859c98f9afb68f69b78b634e7db977a37ee457923c7bcad9cfe75721663bd353a974f16c9dbd3a93b11b5341f89a0b5e23836cf25b110a66925702
|
7
|
+
data.tar.gz: e01bdf1f3c62f9be49e1a0d056823e411c49d5d95d736c3e668549442f9a36eafd9d6622b9f61126934f59eb96ce319abc94bf9aefa254265bf6cdc1d9927e49
|
data/.rubocop.yml
CHANGED
@@ -6,3 +6,36 @@ AllCops:
|
|
6
6
|
|
7
7
|
Style/Documentation:
|
8
8
|
Enabled: false
|
9
|
+
|
10
|
+
HashSyntax:
|
11
|
+
Enabled: false # don't force 1.9 hash syntax
|
12
|
+
|
13
|
+
Style/StringLiterals:
|
14
|
+
Enabled: false # dont't enforce
|
15
|
+
|
16
|
+
Style/WordArray:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Style/GuardClause:
|
20
|
+
Enabled: false # don't enforce this
|
21
|
+
|
22
|
+
Layout/SpaceInsideHashLiteralBraces:
|
23
|
+
Enabled: false
|
24
|
+
|
25
|
+
Metrics/AbcSize:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Metrics/CyclomaticComplexity:
|
29
|
+
Enabled : false
|
30
|
+
|
31
|
+
Metrics/PerceivedComplexity:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Performance/Casecmp:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Style/RescueModifier:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Metrics/MethodLength:
|
41
|
+
Max: 45
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2018-
|
3
|
+
# on 2018-11-15 11:16:00 -0500 using RuboCop version 0.49.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -26,20 +26,6 @@ Lint/EndAlignment:
|
|
26
26
|
- 'lib/fog/vsphere/requests/compute/create_vm.rb'
|
27
27
|
- 'lib/fog/vsphere/requests/compute/host_start_maintenance.rb'
|
28
28
|
|
29
|
-
# Offense count: 2
|
30
|
-
Lint/InterpolationCheck:
|
31
|
-
Exclude:
|
32
|
-
- 'tests/requests/compute/vm_power_off_tests.rb'
|
33
|
-
- 'tests/requests/compute/vm_suspend_tests.rb'
|
34
|
-
|
35
|
-
# Offense count: 13
|
36
|
-
Lint/RescueWithoutErrorClass:
|
37
|
-
Exclude:
|
38
|
-
- 'lib/fog/vsphere/compute.rb'
|
39
|
-
- 'lib/fog/vsphere/requests/compute/list_hosts.rb'
|
40
|
-
- 'lib/fog/vsphere/requests/compute/list_vm_cdroms.rb'
|
41
|
-
- 'lib/fog/vsphere/requests/compute/list_vm_volumes.rb'
|
42
|
-
|
43
29
|
# Offense count: 3
|
44
30
|
Lint/ShadowingOuterLocalVariable:
|
45
31
|
Exclude:
|
@@ -60,14 +46,14 @@ Lint/UselessAssignment:
|
|
60
46
|
- 'lib/fog/vsphere/requests/compute/vm_migrate.rb'
|
61
47
|
- 'tests/requests/compute/vm_clone_tests.rb'
|
62
48
|
|
63
|
-
# Offense count:
|
49
|
+
# Offense count: 64
|
64
50
|
Metrics/AbcSize:
|
65
|
-
Max:
|
51
|
+
Max: 635
|
66
52
|
|
67
53
|
# Offense count: 12
|
68
54
|
# Configuration parameters: CountComments, ExcludedMethods.
|
69
55
|
Metrics/BlockLength:
|
70
|
-
Max:
|
56
|
+
Max: 264
|
71
57
|
|
72
58
|
# Offense count: 21
|
73
59
|
# Configuration parameters: CountBlocks.
|
@@ -77,22 +63,22 @@ Metrics/BlockNesting:
|
|
77
63
|
# Offense count: 6
|
78
64
|
# Configuration parameters: CountComments.
|
79
65
|
Metrics/ClassLength:
|
80
|
-
Max:
|
66
|
+
Max: 284
|
81
67
|
|
82
|
-
# Offense count:
|
68
|
+
# Offense count: 19
|
83
69
|
Metrics/CyclomaticComplexity:
|
84
|
-
Max:
|
70
|
+
Max: 151
|
85
71
|
|
86
|
-
# Offense count:
|
72
|
+
# Offense count: 819
|
87
73
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
88
74
|
# URISchemes: http, https
|
89
75
|
Metrics/LineLength:
|
90
76
|
Max: 317
|
91
77
|
|
92
|
-
# Offense count:
|
78
|
+
# Offense count: 80
|
93
79
|
# Configuration parameters: CountComments.
|
94
80
|
Metrics/MethodLength:
|
95
|
-
Max:
|
81
|
+
Max: 358
|
96
82
|
|
97
83
|
# Offense count: 1
|
98
84
|
# Configuration parameters: CountComments.
|
@@ -104,31 +90,9 @@ Metrics/ModuleLength:
|
|
104
90
|
Metrics/ParameterLists:
|
105
91
|
Max: 6
|
106
92
|
|
107
|
-
# Offense count:
|
93
|
+
# Offense count: 20
|
108
94
|
Metrics/PerceivedComplexity:
|
109
|
-
Max:
|
110
|
-
|
111
|
-
# Offense count: 1
|
112
|
-
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
|
113
|
-
# NamePrefix: is_, has_, have_
|
114
|
-
# NamePrefixBlacklist: is_, has_, have_
|
115
|
-
# NameWhitelist: is_a?
|
116
|
-
Naming/PredicateName:
|
117
|
-
Exclude:
|
118
|
-
- 'spec/**/*'
|
119
|
-
- 'lib/fog/vsphere/compute.rb'
|
120
|
-
|
121
|
-
# Offense count: 15
|
122
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
123
|
-
# SupportedStyles: snake_case, camelCase
|
124
|
-
Naming/VariableName:
|
125
|
-
Exclude:
|
126
|
-
- 'lib/fog/vsphere/requests/compute/create_vm.rb'
|
127
|
-
- 'lib/fog/vsphere/requests/compute/list_datacenters.rb'
|
128
|
-
- 'lib/fog/vsphere/requests/compute/list_resource_pools.rb'
|
129
|
-
- 'lib/fog/vsphere/requests/compute/list_server_types.rb'
|
130
|
-
- 'lib/fog/vsphere/requests/compute/vm_clone.rb'
|
131
|
-
- 'tests/compute_tests.rb'
|
95
|
+
Max: 159
|
132
96
|
|
133
97
|
# Offense count: 10
|
134
98
|
Style/CaseEquality:
|
@@ -152,7 +116,7 @@ Style/DoubleNegation:
|
|
152
116
|
Exclude:
|
153
117
|
- 'tests/helpers/succeeds_helper.rb'
|
154
118
|
|
155
|
-
# Offense count:
|
119
|
+
# Offense count: 14
|
156
120
|
# Configuration parameters: MinBodyLength.
|
157
121
|
Style/GuardClause:
|
158
122
|
Exclude:
|
@@ -165,6 +129,7 @@ Style/GuardClause:
|
|
165
129
|
- 'lib/fog/vsphere/requests/compute/create_vm.rb'
|
166
130
|
- 'lib/fog/vsphere/requests/compute/list_resource_pools.rb'
|
167
131
|
- 'lib/fog/vsphere/requests/compute/list_server_types.rb'
|
132
|
+
- 'lib/fog/vsphere/requests/compute/vm_relocate.rb'
|
168
133
|
|
169
134
|
# Offense count: 2
|
170
135
|
Style/IfInsideElse:
|
@@ -199,6 +164,22 @@ Style/PercentLiteralDelimiters:
|
|
199
164
|
Exclude:
|
200
165
|
- 'Rakefile'
|
201
166
|
|
167
|
+
# Offense count: 1
|
168
|
+
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
|
169
|
+
# NamePrefix: is_, has_, have_
|
170
|
+
# NamePrefixBlacklist: is_, has_, have_
|
171
|
+
# NameWhitelist: is_a?
|
172
|
+
Style/PredicateName:
|
173
|
+
Exclude:
|
174
|
+
- 'spec/**/*'
|
175
|
+
- 'lib/fog/vsphere/compute.rb'
|
176
|
+
|
177
|
+
# Offense count: 2
|
178
|
+
# Cop supports --auto-correct.
|
179
|
+
Style/RedundantSelf:
|
180
|
+
Exclude:
|
181
|
+
- 'lib/fog/vsphere/models/compute/volume.rb'
|
182
|
+
|
202
183
|
# Offense count: 3
|
203
184
|
# Cop supports --auto-correct.
|
204
185
|
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
|
@@ -215,3 +196,14 @@ Style/RegexpLiteral:
|
|
215
196
|
Style/Semicolon:
|
216
197
|
Exclude:
|
217
198
|
- 'tests/models/compute/rules_tests.rb'
|
199
|
+
|
200
|
+
# Offense count: 14
|
201
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
202
|
+
# SupportedStyles: snake_case, camelCase
|
203
|
+
Style/VariableName:
|
204
|
+
Exclude:
|
205
|
+
- 'lib/fog/vsphere/requests/compute/create_vm.rb'
|
206
|
+
- 'lib/fog/vsphere/requests/compute/list_datacenters.rb'
|
207
|
+
- 'lib/fog/vsphere/requests/compute/list_resource_pools.rb'
|
208
|
+
- 'lib/fog/vsphere/requests/compute/list_server_types.rb'
|
209
|
+
- 'lib/fog/vsphere/requests/compute/vm_clone.rb'
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,16 @@
|
|
1
|
+
## v2.5.0
|
2
|
+
|
3
|
+
* Expose extraConfig from user_data for vm_clone #172
|
4
|
+
* Support getting folder types other than vm folder #171
|
5
|
+
* Vm_clone: ERROR if options['volumes'] is not specified #170
|
6
|
+
* Patch attribute[:datacenter] for create interface #167
|
7
|
+
* Add required datacenter param to all calls which may use get_vm_interface #165
|
8
|
+
* Add option to relocate vm's datastore #164
|
9
|
+
* Add cpu_hz attribute to host (#162)
|
10
|
+
* Fix adding 8th volume to vm (#146)
|
11
|
+
|
1
12
|
## v2.4.0
|
13
|
+
|
2
14
|
* improve folder loading performance (#158)
|
3
15
|
* improve storage pod loading performance (#160)
|
4
16
|
* improve datastore loading performance (#159)
|
@@ -8,18 +20,22 @@
|
|
8
20
|
* add server guard to unit_number calculation (#152)
|
9
21
|
|
10
22
|
## v2.3.0
|
23
|
+
|
11
24
|
* set volume unit_number when cloning a vm (#151)
|
12
25
|
* add unclustered esxi hosts back to cluster selection (#149)
|
13
26
|
* reduce the time required to list networks (#145)
|
14
27
|
|
15
28
|
## v2.2.0
|
29
|
+
|
16
30
|
* vm interface updating needs a datacenter as option (#140)
|
17
31
|
* improve vm saving to use a single api call and support network changes (#142)
|
18
32
|
|
19
33
|
## v2.1.1
|
34
|
+
|
20
35
|
* fixes an issue where networks of type DVPort cannot be listed (#137)
|
21
36
|
|
22
37
|
## v2.1.0
|
38
|
+
|
23
39
|
* fixes two issues that broke vm cloning (#134, #135)
|
24
40
|
* performance of host listing was improved (#131)
|
25
41
|
* networks have a vlan property (#129)
|
data/lib/fog/vsphere/compute.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'digest/sha2'
|
2
|
-
|
2
|
+
# rubocop:disable Lint/RescueWithoutErrorClass
|
3
3
|
module Fog
|
4
4
|
module Compute
|
5
5
|
class Vsphere < Fog::Service
|
@@ -182,6 +182,7 @@ module Fog
|
|
182
182
|
props_to_attr_hash vm_mob_ref, props
|
183
183
|
end
|
184
184
|
|
185
|
+
# rubocop:disable Metrics/MethodLength
|
185
186
|
def props_to_attr_hash(vm_mob_ref, props)
|
186
187
|
# NOTE: Object.tap is in 1.8.7 and later.
|
187
188
|
# Here we create the hash object that this method returns, but first we need
|
@@ -249,6 +250,7 @@ module Fog
|
|
249
250
|
# provides both real RbVmomi object and its name.
|
250
251
|
# e.g.
|
251
252
|
# [Datacenter("datacenter-2"), "dc-name"]
|
253
|
+
# rubocop:enable Metrics/MethodLength
|
252
254
|
def parent_attribute(path, type)
|
253
255
|
element = case type
|
254
256
|
when :datacenter
|
@@ -277,7 +279,7 @@ module Fog
|
|
277
279
|
|
278
280
|
class Mock
|
279
281
|
include Shared
|
280
|
-
|
282
|
+
# rubocop:disable Metrics/MethodLength
|
281
283
|
def self.data
|
282
284
|
@data ||= Hash.new do |hash, key|
|
283
285
|
hash[key] = {
|
@@ -537,6 +539,7 @@ module Fog
|
|
537
539
|
cpu_cores: 20,
|
538
540
|
cpu_sockets: 2,
|
539
541
|
cpu_threads: 40,
|
542
|
+
cpu_hz: 2_599_999_534,
|
540
543
|
memory: 824_597_241_856,
|
541
544
|
product_version: '6.0.0',
|
542
545
|
vm_ids: ['5032c8a5-9c5e-ba7a-3804-832a03e16381', '502916a3-b42e-17c7-43ce-b3206e9524dc']
|
@@ -546,6 +549,7 @@ module Fog
|
|
546
549
|
end
|
547
550
|
end
|
548
551
|
|
552
|
+
# rubocop:enable Metrics/MethodLength
|
549
553
|
def initialize(options = {})
|
550
554
|
require 'rbvmomi'
|
551
555
|
@vsphere_username = options[:vsphere_username]
|
@@ -44,7 +44,7 @@ module Fog
|
|
44
44
|
def destroy
|
45
45
|
requires :server_id, :key, :type
|
46
46
|
|
47
|
-
service.destroy_vm_interface(server_id, key: key, type: type)
|
47
|
+
service.destroy_vm_interface(server_id, key: key, type: type, datacenter: server.datacenter)
|
48
48
|
end
|
49
49
|
|
50
50
|
def save
|
@@ -55,6 +55,7 @@ module Fog
|
|
55
55
|
# and thus the highest :key value must correspond to the created interface. Since this has an inherent race
|
56
56
|
# condition we need to gate the saves.
|
57
57
|
SAVE_MUTEX.synchronize do
|
58
|
+
attributes[:datacenter] = server.datacenter unless attributes.key?(:datacenter)
|
58
59
|
data = service.add_vm_interface(server_id, attributes)
|
59
60
|
|
60
61
|
if data['task_state'] == 'success'
|
@@ -29,7 +29,7 @@ module Fog
|
|
29
29
|
|
30
30
|
case server
|
31
31
|
when Fog::Compute::Vsphere::Server
|
32
|
-
interface = service.get_vm_interface(server.id, key: id, mac: id, name: id)
|
32
|
+
interface = service.get_vm_interface(server.id, key: id, mac: id, name: id, datacenter: server.datacenter)
|
33
33
|
when Fog::Compute::Vsphere::Template
|
34
34
|
interface = service.get_template_interfaces(server.id, key: id, mac: id, name: id)
|
35
35
|
else
|
@@ -60,8 +60,6 @@ module Fog
|
|
60
60
|
data = service.add_vm_volume(self)
|
61
61
|
|
62
62
|
if data['task_state'] == 'success'
|
63
|
-
self.unit_number += 1 if unit_number >= 7
|
64
|
-
|
65
63
|
# We have to query vSphere to get the volume attributes since the task handle doesn't include that info.
|
66
64
|
created = server.volumes.all.find { |volume| volume.unit_number == self.unit_number }
|
67
65
|
|
@@ -12,6 +12,7 @@ module Fog
|
|
12
12
|
# identity expects an hash, REQUIRED
|
13
13
|
# nicSettingMap expects an array
|
14
14
|
# options expects an hash
|
15
|
+
# extraConfig expects a hash
|
15
16
|
|
16
17
|
custom_spec['encryptionKey'] = user_data['encryptionKey'] if user_data.key?('encryptionKey')
|
17
18
|
custom_spec['globalIPSettings'] = user_data['globalIPSettings'] if user_data.key?('globalIPSettings')
|
@@ -19,6 +20,7 @@ module Fog
|
|
19
20
|
custom_spec['identity'] = { 'Sysprep' => { 'guiRunOnce' => { 'commandList' => user_data['runcmd'] } } } if user_data.key?('runcmd') && !user_data.key?('identity')
|
20
21
|
custom_spec['nicSettingMap'] = user_data['nicSettingMap'] if user_data.key?('nicSettingMap')
|
21
22
|
custom_spec['options'] = user_data['options'] if user_data.key?('options')
|
23
|
+
custom_spec['extraConfig'] = user_data['extraConfig'] if user_data.key?('extraConfig')
|
22
24
|
|
23
25
|
# for backwards compatability
|
24
26
|
# hostname expects a string, REQUIRED
|
@@ -50,6 +52,7 @@ module Fog
|
|
50
52
|
custom_spec['identity'] = user_data['identity'] if user_data.key?('identity')
|
51
53
|
custom_spec['nicSettingMap'] = user_data['nicSettingMap'] if user_data.key?('nicSettingMap')
|
52
54
|
custom_spec['options'] = user_data['options'] if user_data.key?('options')
|
55
|
+
custom_spec['extraConfig'] = user_data['extraConfig'] if user_data.key?('extraConfig')
|
53
56
|
custom_spec['hostname'] = user_data['hostname'] if user_data.key?('hostname')
|
54
57
|
custom_spec['ipsettings'] = { 'ip' => user_data['ip'] } if user_data.key?('ip')
|
55
58
|
custom_spec['ipsettings']['subnetMask'] = user_data['netmask'] if user_data.key?('netmask')
|
@@ -14,8 +14,9 @@ module Fog
|
|
14
14
|
raw_datacenters.find { |d| d.name == name } || get_raw_datacenter(name)
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
17
|
+
# @note RbVmomi takes path instead of name as argument to find datacenter
|
18
|
+
def get_raw_datacenter(path)
|
19
|
+
connection.serviceInstance.find_datacenter(path)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -4,33 +4,32 @@ module Fog
|
|
4
4
|
class Real
|
5
5
|
def get_folder(path, datacenter_name, type = nil)
|
6
6
|
type ||= 'vm'
|
7
|
-
|
8
7
|
# Cycle through all types of folders.
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
folder = get_raw_vmfolder(path, datacenter_name)
|
13
|
-
raise(Fog::Compute::Vsphere::NotFound) unless folder
|
14
|
-
folder_attributes(folder, datacenter_name)
|
15
|
-
when 'network', :network
|
16
|
-
raise 'not implemented'
|
17
|
-
when 'datastore', :datastore
|
18
|
-
raise 'not implemented'
|
19
|
-
else
|
20
|
-
raise ArgumentError, "#{type} is unknown"
|
21
|
-
end
|
8
|
+
folder = get_raw_folder(path, datacenter_name, type)
|
9
|
+
raise(Fog::Compute::Vsphere::NotFound) unless folder
|
10
|
+
folder_attributes(folder, datacenter_name)
|
22
11
|
end
|
23
12
|
|
24
13
|
protected
|
25
14
|
|
26
|
-
def
|
15
|
+
def get_raw_folder(path, datacenter_name_or_obj, type)
|
27
16
|
# The required path syntax - 'topfolder/subfolder
|
28
17
|
|
29
18
|
# Clean up path to be relative since we're providing datacenter name
|
30
|
-
dc
|
31
|
-
|
19
|
+
dc = if datacenter_name_or_obj.is_a?(String)
|
20
|
+
find_raw_datacenter(datacenter_name_or_obj)
|
21
|
+
else
|
22
|
+
datacenter_name_or_obj
|
23
|
+
end
|
24
|
+
|
25
|
+
valid_types = %w[vm network datastore host]
|
26
|
+
raise ArgumentError, "#{type} is unknown" if type.blank?
|
27
|
+
raise "Invalid type (#{type}). Must be one of #{valid_types.join(', ')} " unless valid_types.include?(type.to_s)
|
28
|
+
meth = "#{type}Folder"
|
29
|
+
dc_root_folder = dc.send(meth)
|
30
|
+
|
32
31
|
# Filter the root path for this datacenter not to be used."
|
33
|
-
dc_root_folder_path = dc_root_folder.path.map { |
|
32
|
+
dc_root_folder_path = dc_root_folder.path.map { |_, name| name }.join('/')
|
34
33
|
paths = path.sub(/^\/?#{Regexp.quote(dc_root_folder_path)}\/?/, '').split('/')
|
35
34
|
|
36
35
|
return dc_root_folder if paths.empty?
|
@@ -46,6 +45,10 @@ module Fog
|
|
46
45
|
end
|
47
46
|
end
|
48
47
|
|
48
|
+
def get_raw_vmfolder(path, datacenter_name)
|
49
|
+
get_raw_folder(path, datacenter_name, 'vm')
|
50
|
+
end
|
51
|
+
|
49
52
|
def folder_attributes(folder, datacenter_name)
|
50
53
|
{
|
51
54
|
id: managed_obj_id(folder),
|
@@ -65,6 +68,7 @@ module Fog
|
|
65
68
|
return :vm if types.include?('VirtualMachine')
|
66
69
|
return :network if types.include?('Network')
|
67
70
|
return :datastore if types.include?('Datastore')
|
71
|
+
return :host if types.include?('ComputeResource')
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:disable Lint/RescueWithoutErrorClass
|
1
2
|
module Fog
|
2
3
|
module Compute
|
3
4
|
class Vsphere
|
@@ -77,6 +78,7 @@ module Fog
|
|
77
78
|
cpu_cores: 'hardware.cpuInfo.numCpuCores',
|
78
79
|
cpu_sockets: 'hardware.cpuInfo.numCpuPackages',
|
79
80
|
cpu_threads: 'hardware.cpuInfo.numCpuThreads',
|
81
|
+
cpu_hz: 'hardware.cpuInfo.hz',
|
80
82
|
memory: 'hardware.memorySize',
|
81
83
|
uuid: 'hardware.systemInfo.uuid',
|
82
84
|
model: 'hardware.systemInfo.model',
|
@@ -13,7 +13,7 @@ module Fog
|
|
13
13
|
raise ArgumentError, 'instance id is a required parameter' unless vmid
|
14
14
|
|
15
15
|
interface = get_interface_from_options(vmid, options.merge(server_id: vmid))
|
16
|
-
vm_reconfig_hardware('instance_uuid' => vmid, 'hardware_spec' => { 'deviceChange' => [create_interface(interface, interface.key, :remove)] })
|
16
|
+
vm_reconfig_hardware('instance_uuid' => vmid, 'hardware_spec' => { 'deviceChange' => [create_interface(interface, interface.key, :remove, options)] })
|
17
17
|
end
|
18
18
|
|
19
19
|
def update_vm_interface(vmid, options = {})
|
@@ -93,6 +93,7 @@ module Fog
|
|
93
93
|
# existing disks as well as add or remove them. The
|
94
94
|
# resizing is applied only when the size is bigger then the
|
95
95
|
# in size in the template
|
96
|
+
# rubocop:disable Metrics/MethodLength
|
96
97
|
def vm_clone(options = {})
|
97
98
|
# Option handling
|
98
99
|
options = vm_clone_check_options(options)
|
@@ -631,7 +632,9 @@ module Fog
|
|
631
632
|
end
|
632
633
|
# relocate templates is not supported by fog-vsphere when vm is cloned on a storage pod
|
633
634
|
unless options.key?('storage_pod')
|
634
|
-
|
635
|
+
unless options['volumes'].blank?
|
636
|
+
relocation_spec[:disk] = relocate_template_volumes_specs(vm_mob_ref, options['volumes'], options['datacenter'])
|
637
|
+
end
|
635
638
|
end
|
636
639
|
# And the clone specification
|
637
640
|
clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(location: relocation_spec,
|
@@ -711,6 +714,7 @@ module Fog
|
|
711
714
|
'task_ref' => task._ref
|
712
715
|
}
|
713
716
|
end
|
717
|
+
# rubocop:enable Metrics/MethodLength
|
714
718
|
|
715
719
|
# Build up the network config spec for simple case:
|
716
720
|
# simple case: apply just the network_label, nic_type and network_adapter_device_key
|
@@ -2,18 +2,31 @@ module Fog
|
|
2
2
|
module Compute
|
3
3
|
class Vsphere
|
4
4
|
class Real
|
5
|
-
#
|
6
|
-
# Server.
|
5
|
+
# Relocates a VM to different host or datastore.
|
7
6
|
#
|
8
7
|
# ==== Parameters
|
9
8
|
# * options<~Hash>:
|
10
9
|
# * 'instance_uuid'<~String> - *REQUIRED* VM to relocate
|
11
10
|
# * 'host'<~String> - name of host which will run the VM.
|
11
|
+
# * 'cluster'<~String> - name of cluster where host is.
|
12
|
+
# Only works with clusters within same datacenter as
|
13
|
+
# where vm is running. Defaults to vm's host's cluster.
|
14
|
+
# * 'datacenter'<~String> - name of datacenter where host is.
|
15
|
+
# It must be same datacenter as where vm is running.
|
16
|
+
# Defaults to vm's datacenter.
|
17
|
+
# * 'datastore'<~String> - name of datastore where VM will
|
18
|
+
# be located.
|
12
19
|
# * 'pool'<~String> - name of pool which the VM should be
|
13
20
|
# attached.
|
14
21
|
# * 'disks'<~Array> - disks to relocate. Each disk is a
|
15
22
|
# hash with diskId wich is key attribute of volume,
|
16
|
-
# and datastore to relocate to.
|
23
|
+
# and datastore to relocate to. diskBackingInfo can be provided,
|
24
|
+
# with type FlatVer2 or SeSparse
|
25
|
+
# Example: [{
|
26
|
+
# 'diskId' => 2000,
|
27
|
+
# 'datastore' => 'datastore_name',
|
28
|
+
# 'diskBackingInfo' => {'type' => 'FlatVer2', ...}
|
29
|
+
# }]
|
17
30
|
def vm_relocate(options = {})
|
18
31
|
raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'
|
19
32
|
|
@@ -25,14 +38,25 @@ module Fog
|
|
25
38
|
raise Fog::Vsphere::Errors::NotFound,
|
26
39
|
"Could not find VirtualMachine with instance uuid #{options['instance_uuid']}"
|
27
40
|
end
|
28
|
-
|
41
|
+
datacenter = options['datacenter'] || get_vm_datacenter(vm_mob_ref)
|
42
|
+
cluster_name = options['cluster'] || get_vm_cluster(vm_mob_ref)
|
43
|
+
|
44
|
+
options['host'] = get_raw_host(options['host'], cluster_name, datacenter) if options['host']
|
45
|
+
options['datastore'] = get_raw_datastore(options['datastore'], datacenter) if options.key?('datastore')
|
46
|
+
|
29
47
|
if options['disks']
|
30
48
|
options['disks'] = options['disks'].map do |disk|
|
31
|
-
disk['datastore'] = get_raw_datastore(disk['datastore'],
|
49
|
+
disk['datastore'] = get_raw_datastore(disk['datastore'], datacenter)
|
50
|
+
if disk['diskBackingInfo'] && disk['diskBackingInfo']['type']
|
51
|
+
backing_type = "VirtualDisk#{disk['diskBackingInfo'].delete('type')}BackingInfo"
|
52
|
+
disk['diskBackingInfo'] = RbVmomi::VIM.send(backing_type, disk['diskBackingInfo'])
|
53
|
+
end
|
32
54
|
RbVmomi::VIM::VirtualMachineRelocateSpecDiskLocator(disk)
|
33
55
|
end
|
34
56
|
end
|
57
|
+
|
35
58
|
spec = RbVmomi::VIM::VirtualMachineRelocateSpec(
|
59
|
+
datastore: options['datastore'],
|
36
60
|
pool: options['pool'],
|
37
61
|
host: options['host'],
|
38
62
|
disk: options['disks']
|
@@ -41,6 +65,30 @@ module Fog
|
|
41
65
|
task.wait_for_completion
|
42
66
|
{ 'task_state' => task.info.state }
|
43
67
|
end
|
68
|
+
|
69
|
+
def get_vm_datacenter(vm_mob_ref)
|
70
|
+
parent = vm_mob_ref.parent
|
71
|
+
until parent.is_a?(RbVmomi::VIM::Datacenter)
|
72
|
+
if vm_mob_ref.respond_to?(:parent)
|
73
|
+
parent = parent.parent
|
74
|
+
else
|
75
|
+
return
|
76
|
+
end
|
77
|
+
end
|
78
|
+
parent.name
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_vm_cluster(vm_mob_ref)
|
82
|
+
parent = vm_mob_ref.runtime.host.parent
|
83
|
+
until parent.is_a?(RbVmomi::VIM::ClusterComputeResource)
|
84
|
+
if vm_mob_ref.respond_to?(:parent)
|
85
|
+
parent = parent.parent
|
86
|
+
else
|
87
|
+
return
|
88
|
+
end
|
89
|
+
end
|
90
|
+
parent.name
|
91
|
+
end
|
44
92
|
end
|
45
93
|
|
46
94
|
class Mock
|
data/lib/fog/vsphere/version.rb
CHANGED
data/tests/compute_tests.rb
CHANGED
@@ -14,7 +14,7 @@ Shindo.tests('Fog::Compute[:vsphere] | vm_power_off request', ['vsphere']) do
|
|
14
14
|
{ true => 'cut_power', false => 'shutdown_guest' }.each do |force, expected|
|
15
15
|
tests("When 'force' => #{force}") do
|
16
16
|
response = compute.vm_power_off('instance_uuid' => powered_on_vm, 'force' => force)
|
17
|
-
test(
|
17
|
+
test("should retur power_off_type of #{expected}") { response['power_off_type'] == expected }
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -13,7 +13,7 @@ Shindo.tests('Fog::Compute[:vsphere] | vm_suspend request', ['vsphere']) do
|
|
13
13
|
{ true => 'suspend', false => 'standby_guest' }.each do |force, expected|
|
14
14
|
tests("When 'force' => #{force}") do
|
15
15
|
response = compute.vm_suspend('instance_uuid' => powered_on_vm, 'force' => force)
|
16
|
-
test(
|
16
|
+
test("should return suspend_type of #{expected}") { response['suspend_type'] == expected }
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fog-vsphere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- J.R. Garcia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-core
|
@@ -328,7 +328,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
328
328
|
version: '0'
|
329
329
|
requirements: []
|
330
330
|
rubyforge_project:
|
331
|
-
rubygems_version: 2.7.
|
331
|
+
rubygems_version: 2.7.7
|
332
332
|
signing_key:
|
333
333
|
specification_version: 4
|
334
334
|
summary: Module for the 'fog' gem to support VMware vSphere.
|