fog-vsphere 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f0eaac527da91308fec5066b89407f48b10c7ec
4
- data.tar.gz: 150e3dc5e72cb0c27d617bf65b2d7db259edb609
3
+ metadata.gz: f3ecf2e2e7786673208a3301191bc8a2ccd5fc1f
4
+ data.tar.gz: c4282d6b04ab981c10e65d63ad071091743ece0e
5
5
  SHA512:
6
- metadata.gz: c03d49413d12ba37d6a02365932583cafc87634cafaf55c8bceadc687ef08a9e0f9134b7928eb2aed94099ef01ee395340d5b10f76351e3870c0e7e409baec5a
7
- data.tar.gz: 2d78b5e76edff6315f2601fc1830ae395c2419b3e159632a3ad0261d2309c7271d3a303c16ad1b5883fa40ef73e43bfa8958ec92c868d1e0c32d3e78e7124da1
6
+ metadata.gz: 49594f0acf240a9e7e8e49d8a0729f040c714de249e610c73cb6e2212e6a51c1cdc2340ea8bf493a2edfeb21f4e85fe3bcae2880dffe19a631256d8f7c1ca085
7
+ data.tar.gz: 19532eac88ce221bb6d0bdeef0511f399552625d5677faba6ca0c024bb0ebd24112d54acfd821d80d005fa76ef678e9e6f30464dfefb24c7d47cf5b6bcb43e85
data/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## v0.4.0 12/15/2015
2
+
3
+ * Fix cannot create vm on "Resources" resource pool
4
+ * Fix Fog::Mock.reset
5
+ * Implement support for DRS rules
6
+ * Fix issues with boot options
7
+ * Add boot retry support
8
+ * Add support for annotation and extra_config
9
+
10
+ ## v0.3.0 12/3/2015
11
+
1
12
  * Fix update_vm_interface
2
13
  * Add add folder.destroy
3
14
  * Implement CD-ROM options
data/lib/fog/vsphere.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  require 'fog/core'
2
2
 
3
3
  module Fog
4
- module Vsphere
5
- autoload :Compute, File.expand_path('../vsphere/compute', __FILE__)
4
+ module Compute
5
+ autoload :Vsphere, File.expand_path('../vsphere/compute.rb', __FILE__)
6
+ end
6
7
 
8
+ module Vsphere
7
9
  extend Fog::Provider
8
10
 
9
11
  module Errors
@@ -45,6 +45,8 @@ module Fog
45
45
  model :process
46
46
  model :cdrom
47
47
  collection :cdroms
48
+ model :rule
49
+ collection :rules
48
50
 
49
51
  request_path 'fog/vsphere/requests/compute'
50
52
  request :current_time
@@ -104,6 +106,9 @@ module Fog
104
106
  request :list_processes
105
107
  request :upload_iso
106
108
  request :folder_destroy
109
+ request :create_rule
110
+ request :list_rules
111
+ request :destroy_rule
107
112
 
108
113
  module Shared
109
114
  attr_reader :vsphere_is_vcenter
@@ -136,6 +141,7 @@ module Fog
136
141
  :cpuHotAddEnabled => 'config.cpuHotAddEnabled',
137
142
  :memoryHotAddEnabled => 'config.memoryHotAddEnabled',
138
143
  :firmware => 'config.firmware',
144
+ :annotation => 'config.annotation',
139
145
  }
140
146
 
141
147
  def convert_vm_view_to_attr_hash(vms)
@@ -400,7 +406,18 @@ module Fog
400
406
  :klass => "RbVmomi::VIM::ComputeResource"}
401
407
  ]
402
408
  }
403
- ]
409
+ ],
410
+ :rules => {
411
+ 'anti-affinity-foo' => {
412
+ :datacenter => 'Solutions',
413
+ :cluster => 'Solutionscluster',
414
+ :key => 4242,
415
+ :name => 'anti-affinity-foo',
416
+ :enabled => true,
417
+ :type => RbVmomi::VIM::ClusterAntiAffinityRuleSpec,
418
+ :vm_ids => ['5032c8a5-9c5e-ba7a-3804-832a03e16381', '502916a3-b42e-17c7-43ce-b3206e9524dc']
419
+ }
420
+ }
404
421
  }
405
422
  end
406
423
  end
@@ -481,6 +498,29 @@ module Fog
481
498
  :ssl => @vsphere_ssl,
482
499
  :insecure => bad_cert,
483
500
  :debug => @vsphere_debug
501
+
502
+ # Create a shadow class to change the behaviour of @connection.obj2xml
503
+ # so that xsd:any types are converted to xsd:int (and not xsd:long).
504
+ #
505
+ # This is a known issue with RbVmomi.
506
+ #
507
+ # See https://communities.vmware.com/message/2505334 for discussion
508
+ # and https://github.com/rlane/rbvmomi/pull/30 for an unmerged
509
+ # pull request that fixes it in RbVmomi.
510
+ #
511
+ class <<@connection
512
+ def obj2xml xml, name, type, is_array, o, attrs={}
513
+ case o
514
+ when Integer
515
+ attrs['xsi:type'] = 'xsd:int' if type(type) == RbVmomi::BasicTypes::AnyType
516
+ xml.tag! name, o.to_s, attrs
517
+ xml
518
+ else
519
+ super xml, name, type, is_array, o, attrs
520
+ end
521
+ end
522
+ end
523
+
484
524
  break
485
525
  rescue OpenSSL::SSL::SSLError
486
526
  raise if bad_cert
@@ -18,6 +18,10 @@ module Fog
18
18
  :datacenter => datacenter
19
19
  }.merge(filters))
20
20
  end
21
+
22
+ def rules
23
+ service.rules(:datacenter => datacenter, :cluster => name)
24
+ end
21
25
 
22
26
  def to_s
23
27
  name
@@ -0,0 +1,46 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ # ClusterRuleInfo
5
+ class Rule < Fog::Model
6
+ identity :key
7
+
8
+ attribute :datacenter
9
+ attribute :cluster
10
+ attribute :name
11
+ attribute :enabled
12
+ # Type should be a class - either
13
+ # - RbVmomi::VIM::ClusterAntiAffinityRuleSpec
14
+ # - RbVmomi::VIM::ClusterAffinityRuleSpec
15
+ attribute :type
16
+ attribute :vm_ids
17
+
18
+ def vms
19
+ vm_ids.map {|id| service.servers.get(id, datacenter) }
20
+ end
21
+
22
+ def vms=(vms)
23
+ self.vm_ids = vms.map(&:instance_uuid)
24
+ end
25
+
26
+ def save
27
+ requires :datacenter, :cluster, :name, :enabled, :type, :vm_ids
28
+ if vm_ids.length < 2
29
+ raise ArgumentError, "A rule must have at least 2 VMs"
30
+ end
31
+ if persisted?
32
+ raise "Update is not supported yet"
33
+ else
34
+ self.key = service.create_rule(attributes)
35
+ end
36
+ reload
37
+ end
38
+
39
+ def destroy
40
+ service.destroy_rule(attributes)
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Rules < Fog::Collection
5
+ autoload :Rule, File.expand_path('../rule', __FILE__)
6
+
7
+ model Fog::Compute::Vsphere::Rule
8
+ attribute :datacenter
9
+ attribute :cluster
10
+
11
+ def all(filters = {})
12
+ requires :datacenter, :cluster
13
+ load service.list_rules(:datacenter => datacenter, :cluster => cluster)
14
+ end
15
+
16
+ def get(key_or_name)
17
+ all.find {|rule| [rule.key, rule.name].include? key_or_name } or
18
+ raise Fog::Compute::Vsphere::NotFound, "no such rule #{key_or_name}"
19
+ end
20
+
21
+ # Pass datacenter/cluster to every new rule
22
+ def new(attributes={})
23
+ requires :datacenter, :cluster
24
+ super(attributes.merge(datacenter: datacenter, cluster: cluster))
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -49,6 +49,7 @@ module Fog
49
49
  attribute :cpuHotAddEnabled
50
50
  attribute :memoryHotAddEnabled
51
51
  attribute :firmware
52
+ attribute :annotation
52
53
 
53
54
  def initialize(attributes={} )
54
55
  super defaults.merge(attributes)
@@ -0,0 +1,46 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def create_rule(attributes={})
6
+ cluster = get_raw_cluster(attributes[:cluster], attributes[:datacenter])
7
+ # Check if it already exists and blow up if it does
8
+ # (otherwise ESX just happily accepts it and then considers it a conflict)
9
+ rule = cluster.configurationEx.rule.find {|n| n[:name] == attributes[:name]}
10
+ if rule
11
+ raise ArgumentError, "Rule #{attributes[:name]} already exists!"
12
+ end
13
+ # First, create the rulespec
14
+ vms = attributes[:vm_ids].to_a.map {|id| get_vm_ref(id, attributes[:datacenter])}
15
+ spec = attributes[:type].new(
16
+ name: attributes[:name],
17
+ enabled: attributes[:enabled],
18
+ vm: vms
19
+ )
20
+ # Now, attach it to the cluster
21
+ cluster_spec = RbVmomi::VIM.ClusterConfigSpecEx(rulesSpec: [
22
+ RbVmomi::VIM.ClusterRuleSpec(
23
+ operation: RbVmomi::VIM.ArrayUpdateOperation('add'),
24
+ info: spec
25
+ )
26
+ ])
27
+ ret = cluster.ReconfigureComputeResource_Task(spec: cluster_spec, modify: true).wait_for_completion
28
+ rule = cluster.configurationEx.rule.find {|n| n[:name] == attributes[:name]}
29
+ if rule
30
+ return rule[:key]
31
+ else
32
+ raise Fog::Vsphere::Errors::ServiceError, "Unknown error creating rule #{attributes[:name]}"
33
+ end
34
+ end
35
+
36
+ end
37
+ class Mock
38
+ def create_rule(attributes={})
39
+ attributes[:key] = rand(9999)
40
+ self.data[:rules][attributes[:name]] = attributes
41
+ attributes[:key]
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -7,6 +7,7 @@ module Fog
7
7
 
8
8
  vm_cfg = {
9
9
  :name => attributes[:name],
10
+ :annotation => attributes[:annotation],
10
11
  :guestId => attributes[:guest_id],
11
12
  :version => attributes[:hardware_version],
12
13
  :files => { :vmPathName => vm_path_name(attributes) },
@@ -19,8 +20,8 @@ module Fog
19
20
  vm_cfg[:cpuHotAddEnabled] = attributes[:cpuHotAddEnabled] if attributes.key?(:cpuHotAddEnabled)
20
21
  vm_cfg[:memoryHotAddEnabled] = attributes[:memoryHotAddEnabled] if attributes.key?(:memoryHotAddEnabled)
21
22
  vm_cfg[:firmware] = attributes[:firmware] if attributes.key?(:firmware)
22
- vm_cfg[:bootOptions] = boot_options(attributes) if attributes.key?(:boot_order)
23
- resource_pool = if attributes[:resource_pool]
23
+ vm_cfg[:bootOptions] = boot_options(attributes) if attributes.key?(:boot_order) || attributes.key?(:boot_retry)
24
+ resource_pool = if attributes[:resource_pool] && attributes[:resource_pool] != 'Resources'
24
25
  get_raw_resource_pool(attributes[:resource_pool], attributes[:cluster], attributes[:datacenter])
25
26
  else
26
27
  get_raw_cluster(attributes[:cluster], attributes[:datacenter]).resourcePool
@@ -106,10 +107,18 @@ module Fog
106
107
  def boot_options attributes
107
108
  # NOTE: you must be using vsphere_rev 5.0 or greater to set boot_order
108
109
  # e.g. Fog::Compute.new(provider: "vsphere", vsphere_rev: "5.5", etc)
109
- return unless @vsphere_rev.to_f >= 5
110
- RbVmomi::VIM::VirtualMachineBootOptions.new(
111
- :bootOrder => boot_order(attributes)
112
- )
110
+ options = {}
111
+ if @vsphere_rev.to_f >= 5 and attributes[:boot_order]
112
+ options[:bootOrder] = boot_order(attributes)
113
+ end
114
+
115
+ # Set attributes[:boot_retry] to a delay in miliseconds to enable boot retries
116
+ if attributes[:boot_retry]
117
+ options[:bootRetryEnabled] = true
118
+ options[:bootRetryDelay] = attributes[:boot_retry]
119
+ end
120
+
121
+ options.empty? ? nil : RbVmomi::VIM::VirtualMachineBootOptions.new(options)
113
122
  end
114
123
 
115
124
  def boot_order attributes
@@ -280,12 +289,8 @@ module Fog
280
289
  end
281
290
 
282
291
  def extra_config attributes
283
- [
284
- {
285
- :key => 'bios.bootOrder',
286
- :value => 'ethernet0'
287
- }
288
- ]
292
+ extra_config = attributes[:extra_config] || {'bios.bootOrder' => 'ethernet0'}
293
+ extra_config.map {|k,v| {:key => k, :value => v.to_s} }
289
294
  end
290
295
  end
291
296
 
@@ -0,0 +1,27 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def destroy_rule(attributes = {})
6
+ cluster = get_raw_cluster(attributes[:cluster], attributes[:datacenter])
7
+ rule = cluster.configurationEx.rule.find {|rule| rule.key == attributes[:key]}
8
+ raise Fog::Vsphere::Error::NotFound, "rule #{attributes[:key]} not found" unless rule
9
+ delete_spec = RbVmomi::VIM.ClusterConfigSpecEx(rulesSpec: [
10
+ RbVmomi::VIM.ClusterRuleSpec(
11
+ operation: RbVmomi::VIM.ArrayUpdateOperation('remove'),
12
+ removeKey: rule.key
13
+ )
14
+ ])
15
+ cluster.ReconfigureComputeResource_Task(spec: delete_spec, modify: true).wait_for_completion
16
+ end
17
+ end
18
+ class Mock
19
+ def destroy_rule(attributes = {})
20
+ rule = self.data[:rules][attributes[:name]]
21
+ raise Fog::Vsphere::Error::NotFound unless rule
22
+ self.data[:rules].delete(attributes[:name])
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -17,7 +17,9 @@ module Fog
17
17
  end
18
18
 
19
19
  class Mock
20
- def get_cluster(id)
20
+ def get_cluster(name, datacenter_name)
21
+ self.data[:clusters].find {|c| c[:name] == name && c[:datacenter] == datacenter_name} or
22
+ raise Fog::Compute::Vsphere::NotFound
21
23
  end
22
24
  end
23
25
  end
@@ -0,0 +1,31 @@
1
+ module Fog
2
+ module Compute
3
+ class Vsphere
4
+ class Real
5
+ def list_rules(filters = {})
6
+ cluster = get_raw_cluster(filters[:cluster], filters[:datacenter])
7
+ cluster.configurationEx.rule.map {|r| rule_attributes r, filters}
8
+ end
9
+
10
+ protected
11
+
12
+ def rule_attributes(rule, filters)
13
+ {
14
+ datacenter: filters[:datacenter],
15
+ cluster: filters[:cluster],
16
+ key: rule[:key],
17
+ name: rule[:name],
18
+ enabled: rule[:enabled],
19
+ type: rule.class,
20
+ vm_ids: rule[:vm].map {|vm| vm.config.instanceUuid }
21
+ }
22
+ end
23
+ end
24
+ class Mock
25
+ def list_rules(filters = {})
26
+ self.data[:rules].values.select {|r| r[:datacenter] == filters[:datacenter] && r[:cluster] == filters[:cluster]}
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -108,7 +108,7 @@ module Fog
108
108
 
109
109
  # Options['resource_pool']<~Array>
110
110
  # Now find _a_ resource pool to use for the clone if one is not specified
111
- if ( options.key?('resource_pool') && options['resource_pool'].is_a?(Array) && options['resource_pool'].length == 2 )
111
+ if ( options.key?('resource_pool') && options['resource_pool'].is_a?(Array) && options['resource_pool'].length == 2 && options['resource_pool'][1] != 'Resources')
112
112
  cluster_name = options['resource_pool'][0]
113
113
  pool_name = options['resource_pool'][1]
114
114
  resource_pool = get_raw_resource_pool(pool_name, cluster_name, options['datacenter'])
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Vsphere
3
- VERSION = '0.3.0'
3
+ VERSION = '0.4.0'
4
4
  end
5
5
  end
@@ -0,0 +1,34 @@
1
+ Shindo.tests('Fog::Compute[:vsphere] | rules collection', ['vsphere']) do
2
+
3
+ compute = Fog::Compute[:vsphere]
4
+ cluster = compute.datacenters.first.clusters.get('Solutionscluster')
5
+ servers = compute.servers
6
+ rules = cluster.rules
7
+
8
+ tests('The rules collection') do
9
+ test('should not be empty') { not rules.empty? }
10
+ test('should be a kind of Fog::Compute::Vsphere::Rules') { rules.kind_of? Fog::Compute::Vsphere::Rules }
11
+ test('should get rules') { rules.get('anti-affinity-foo').key == 4242 }
12
+ test('should destroy rules') { rules.first.destroy; rules.reload; rules.empty? }
13
+ test('should create rules') do
14
+ r = rules.new({
15
+ name: 'affinity-foo',
16
+ enabled: true,
17
+ type: RbVmomi::VIM::ClusterAffinityRuleSpec
18
+ })
19
+ r.vms = [servers.get('5032c8a5-9c5e-ba7a-3804-832a03e16381'), servers.get('502916a3-b42e-17c7-43ce-b3206e9524dc')]
20
+ r.save
21
+ rules.reload
22
+ rules.get('affinity-foo').key > 0
23
+ end
24
+ raises(ArgumentError, 'should not create rules with <2 vms') do
25
+ rules.create({
26
+ name: 'affinity-foo',
27
+ enabled: true,
28
+ type: RbVmomi::VIM::ClusterAffinityRuleSpec,
29
+ vm_ids: ['5032c8a5-9c5e-ba7a-3804-832a03e16381']
30
+ })
31
+ end
32
+ end
33
+
34
+ end
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: 0.3.0
4
+ version: 0.4.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: 2015-12-03 00:00:00.000000000 Z
11
+ date: 2015-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-core
@@ -154,6 +154,8 @@ files:
154
154
  - lib/fog/vsphere/models/compute/process.rb
155
155
  - lib/fog/vsphere/models/compute/resource_pool.rb
156
156
  - lib/fog/vsphere/models/compute/resource_pools.rb
157
+ - lib/fog/vsphere/models/compute/rule.rb
158
+ - lib/fog/vsphere/models/compute/rules.rb
157
159
  - lib/fog/vsphere/models/compute/scsicontroller.rb
158
160
  - lib/fog/vsphere/models/compute/server.rb
159
161
  - lib/fog/vsphere/models/compute/servers.rb
@@ -169,8 +171,10 @@ files:
169
171
  - lib/fog/vsphere/models/compute/volumes.rb
170
172
  - lib/fog/vsphere/requests/compute/cloudinit_to_customspec.rb
171
173
  - lib/fog/vsphere/requests/compute/create_folder.rb
174
+ - lib/fog/vsphere/requests/compute/create_rule.rb
172
175
  - lib/fog/vsphere/requests/compute/create_vm.rb
173
176
  - lib/fog/vsphere/requests/compute/current_time.rb
177
+ - lib/fog/vsphere/requests/compute/destroy_rule.rb
174
178
  - lib/fog/vsphere/requests/compute/folder_destroy.rb
175
179
  - lib/fog/vsphere/requests/compute/get_cluster.rb
176
180
  - lib/fog/vsphere/requests/compute/get_compute_resource.rb
@@ -196,6 +200,7 @@ files:
196
200
  - lib/fog/vsphere/requests/compute/list_networks.rb
197
201
  - lib/fog/vsphere/requests/compute/list_processes.rb
198
202
  - lib/fog/vsphere/requests/compute/list_resource_pools.rb
203
+ - lib/fog/vsphere/requests/compute/list_rules.rb
199
204
  - lib/fog/vsphere/requests/compute/list_server_types.rb
200
205
  - lib/fog/vsphere/requests/compute/list_storage_pods.rb
201
206
  - lib/fog/vsphere/requests/compute/list_templates.rb
@@ -229,6 +234,7 @@ files:
229
234
  - tests/helper.rb
230
235
  - tests/helpers/mock_helper.rb
231
236
  - tests/helpers/succeeds_helper.rb
237
+ - tests/models/compute/rules_tests.rb
232
238
  - tests/models/compute/server_tests.rb
233
239
  - tests/models/compute/servers_tests.rb
234
240
  - tests/requests/compute/current_time_tests.rb
@@ -284,6 +290,7 @@ test_files:
284
290
  - tests/helper.rb
285
291
  - tests/helpers/mock_helper.rb
286
292
  - tests/helpers/succeeds_helper.rb
293
+ - tests/models/compute/rules_tests.rb
287
294
  - tests/models/compute/server_tests.rb
288
295
  - tests/models/compute/servers_tests.rb
289
296
  - tests/requests/compute/current_time_tests.rb