fog-vsphere 2.0.1 → 2.1.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
  SHA256:
3
- metadata.gz: 4991c02472ff132b2a1edef665c3dee7ee98ecec1a98bbad65947e574a9d6957
4
- data.tar.gz: e484ae1b367e65fd7d799d1f50673a6584221da5e52ad610cd525e1d32e7de42
3
+ metadata.gz: f79b2fda04ea3983ad8eb745f642e7b94d10790dfe23d63348aba52dceb1e5bc
4
+ data.tar.gz: aa888887668bf44fec6f238629592174d94d979fa8c986af17adf70a0ce14667
5
5
  SHA512:
6
- metadata.gz: 0aed9e163c96fadd05853581565a520e841b4df4ff2509b5c8952ee9421f65ebd35d03cd4f94366708d866e97c9b068221818cc02c1e9848fec2041217122d23
7
- data.tar.gz: d22e96a6ccaa8bdfd0a1c6ae564ba50317e08b6ab718ce78e1ace8c0422a05ea56fc9590e2ecc341b86ef6d5808b6289874f4b3312542f00c126187c108c3a4f
6
+ metadata.gz: db0e26ac2e3417ce2a8c39369c8f01aba9474200684f07d3392d79a9a589a938daf673fcb54d1f7f710aec8043db856459ebe57d5de96c5232d627b467c5d767
7
+ data.tar.gz: d7304c9307b5eb405e21195c56cbf35c8106be6cfdd00cc91bc2bcaa941f3097867d1b14757420b37a5a81d6b6acf1643263cd492b5e1b78d099e081e40e5957
@@ -1,3 +1,8 @@
1
+ ## v2.1.0
2
+ * fixes two issues that broke vm cloning (#134, #135)
3
+ * performance of host listing was improved (#131)
4
+ * networks have a vlan property (#129)
5
+
1
6
  ## v2.0.1
2
7
 
3
8
  * Ensure views are destroyed after use (#122)
@@ -268,6 +268,12 @@ module Fog
268
268
  "filename" => "[Storage1] rhel6-mfojtik/rhel6-mfojtik.vmdk",
269
269
  "size_gb" => 8
270
270
  }],
271
+ "scsi_controllers" =>
272
+ [{"shared_bus" => "noSharing",
273
+ "type" => "VirtualLsiLogicController",
274
+ "unit_number" => 7,
275
+ "key" => 1000
276
+ }],
271
277
  "interfaces" =>
272
278
  [{"mac" => "00:50:56:a9:00:28",
273
279
  "network" => "dvportgroup-123456",
@@ -320,6 +326,12 @@ module Fog
320
326
  "name" => "Hard disk 1",
321
327
  "mode" => "persistent",
322
328
  "id" => "6000C29b-f364-d073-8316-8e98ac0a0eae" }],
329
+ "scsi_controllers" =>
330
+ [{"shared_bus" => "noSharing",
331
+ "type" => "VirtualLsiLogicController",
332
+ "unit_number" => 7,
333
+ "key" => 1000
334
+ }],
323
335
  "interfaces" =>
324
336
  [{ "summary" => "VM Network",
325
337
  "mac" => "00:50:56:a9:00:00",
@@ -6,13 +6,19 @@ module Fog
6
6
 
7
7
  attribute :datacenter
8
8
  attribute :cluster
9
- attribute :name
10
- attribute :vm_ids
11
9
  attribute :cpu_cores
12
10
  attribute :cpu_sockets
13
11
  attribute :cpu_threads
14
12
  attribute :memory
15
13
  attribute :uuid
14
+ attribute :ipaddress
15
+ attribute :ipaddress6
16
+ attribute :model
17
+ attribute :vendor
18
+ attribute :product_name
19
+ attribute :product_version
20
+ attribute :hostname
21
+ attribute :domainname
16
22
 
17
23
  # Lazy Loaded Attributes
18
24
  [:vm_ids].each do |attr|
@@ -8,6 +8,7 @@ module Fog
8
8
  attribute :datacenter
9
9
  attribute :accessible # reachable by at least one hypervisor
10
10
  attribute :virtualswitch
11
+ attribute :vlanid
11
12
 
12
13
  def to_s
13
14
  name
@@ -4,30 +4,71 @@ module Fog
4
4
  class Real
5
5
  def list_hosts(filters = {})
6
6
  cluster = get_raw_cluster(filters[:cluster], filters[:datacenter])
7
- cluster.host.map {|host| host_attributes(host, filters)}
7
+
8
+ results = property_collector_results(host_system_filter_spec(cluster))
9
+
10
+ results.map do |host|
11
+ hsh = map_attrs_to_hash(host, host_system_attribute_mapping)
12
+ hsh.merge(
13
+ datacenter: filters[:datacenter],
14
+ cluster: filters[:cluster],
15
+ ipaddress: (host['config.network.vnic'].first.spec.ip.ipAddress rescue nil),
16
+ ipaddress6: (host['config.network.vnic'].first.spec.ip.ipV6Config.ipV6Address.first.ipAddress rescue nil),
17
+ vm_ids: Proc.new { host['vm'].map {|vm| vm.config.instanceUuid rescue nil} }
18
+ )
19
+ end
8
20
  end
9
21
 
10
22
  protected
11
23
 
12
- def host_attributes(host, filters)
24
+ def map_attrs_to_hash(obj, attribute_mapping)
25
+ attribute_mapping.each_with_object({}) do |(k, v), hsh|
26
+ hsh[k] = obj[v]
27
+ end
28
+ end
29
+
30
+ def property_collector_results(filter_spec)
31
+ property_collector = connection.serviceContent.propertyCollector
32
+ property_collector.RetrieveProperties(:specSet => [filter_spec])
33
+ end
34
+
35
+ def compute_resource_host_traversal_spec
36
+ RbVmomi::VIM.TraversalSpec(
37
+ :name => 'computeResourceHostTraversalSpec',
38
+ :type => 'ComputeResource',
39
+ :path => 'host',
40
+ :skip => false
41
+ )
42
+ end
43
+
44
+ def host_system_filter_spec(obj)
45
+ RbVmomi::VIM.PropertyFilterSpec(
46
+ :objectSet => [
47
+ :obj => obj,
48
+ :selectSet => [
49
+ compute_resource_host_traversal_spec
50
+ ]
51
+ ],
52
+ :propSet => [
53
+ { :type => 'HostSystem', :pathSet => host_system_attribute_mapping.values + ['config.network.vnic', 'vm'] }
54
+ ]
55
+ )
56
+ end
57
+
58
+ def host_system_attribute_mapping
13
59
  {
14
- datacenter: filters[:datacenter],
15
- cluster: filters[:cluster],
16
- name: host[:name],
17
- cpu_cores: host.hardware.cpuInfo.numCpuCores,
18
- cpu_sockets: host.hardware.cpuInfo.numCpuPackages,
19
- cpu_threads: host.hardware.cpuInfo.numCpuThreads,
20
- memory: host.hardware.memorySize,
21
- uuid: host.hardware.systemInfo.uuid,
22
- model: host.hardware.systemInfo.model,
23
- vendor: host.hardware.systemInfo.vendor,
24
- ipaddress: (host.config.network.vnic.first.spec.ip.ipAddress rescue nil),
25
- ipaddress6: (host.config.network.vnic.first.spec.ip.ipV6Config.ipV6Address.first.ipAddress rescue nil),
26
- product_name: host.summary.config.product.name,
27
- product_version: host.summary.config.product.version,
28
- hostname: (host.config.network.dnsConfig.hostName rescue nil),
29
- domainname: (host.config.network.dnsConfig.domainName rescue nil),
30
- vm_ids: Proc.new { host[:vm].map {|vm| vm.config.instanceUuid rescue nil} }
60
+ name: 'name',
61
+ cpu_cores: 'hardware.cpuInfo.numCpuCores',
62
+ cpu_sockets: 'hardware.cpuInfo.numCpuPackages',
63
+ cpu_threads: 'hardware.cpuInfo.numCpuThreads',
64
+ memory: 'hardware.memorySize',
65
+ uuid: 'hardware.systemInfo.uuid',
66
+ model: 'hardware.systemInfo.model',
67
+ vendor: 'hardware.systemInfo.vendor',
68
+ product_name: 'summary.config.product.name',
69
+ product_version: 'summary.config.product.version',
70
+ hostname: 'config.network.dnsConfig.hostName',
71
+ domainname: 'config.network.dnsConfig.domainName'
31
72
  }
32
73
  end
33
74
  end
@@ -8,7 +8,7 @@ module Fog
8
8
  # default to show all networks
9
9
  only_active = filters[:accessible] || false
10
10
  raw_networks(datacenter_name, cluster_name).map do |network|
11
- next if only_active and !network.summary.accessible
11
+ next if only_active && !network.summary.accessible
12
12
  network_attributes(network, datacenter_name)
13
13
  end.compact
14
14
  end
@@ -23,21 +23,36 @@ module Fog
23
23
 
24
24
  protected
25
25
 
26
- def network_attributes network, datacenter
27
- raw_network = get_raw_network(network.name, datacenter)
28
- if raw_network.kind_of? RbVmomi::VIM::DistributedVirtualPortgroup
29
- id = raw_network.key
26
+ def network_attributes(network, datacenter)
27
+ if network.kind_of?(RbVmomi::VIM::DistributedVirtualPortgroup)
28
+ id = network.key
29
+ virtualswitch = network.config.distributedVirtualSwitch.name
30
+ vlanid = raw_network_vlan_id(network.config.defaultPortConfig.vlan)
30
31
  else
31
32
  id = managed_obj_id(network)
33
+ virtualswitch = nil
34
+ vlanid = nil
32
35
  end
33
36
  {
34
37
  :id => id,
35
38
  :name => network.name,
36
39
  :accessible => network.summary.accessible,
37
40
  :datacenter => datacenter,
38
- :virtualswitch => network.class.name == "DistributedVirtualPortgroup" ? network.config.distributedVirtualSwitch.name : nil
41
+ :virtualswitch => virtualswitch,
42
+ :vlanid => vlanid
39
43
  }
40
44
  end
45
+
46
+ private
47
+
48
+ def raw_network_vlan_id(vlan)
49
+ case vlan
50
+ when RbVmomi::VIM::VmwareDistributedVirtualSwitchVlanIdSpec
51
+ vlan.vlanId
52
+ else
53
+ nil
54
+ end
55
+ end
41
56
  end
42
57
  class Mock
43
58
  def list_networks(filters)
@@ -19,6 +19,13 @@ module Fog
19
19
  end
20
20
  end
21
21
  end
22
+ class Mock
23
+ def list_vm_scsi_controllers(vm_id)
24
+ raise Fog::Compute::Vsphere::NotFound, 'VM not Found' unless self.data[:servers].key?(vm_id)
25
+ return [] unless self.data[:servers][vm_id].key?('scsi_controllers')
26
+ self.data[:servers][vm_id]['scsi_controllers'].map {|h| h.merge(:server_id => vm_id) }
27
+ end
28
+ end
22
29
  end
23
30
  end
24
31
  end
@@ -629,7 +629,10 @@ module Fog
629
629
  relocation_spec[:datastore] = datastore_obj
630
630
  end
631
631
  end
632
- relocation_spec[:disk] = relocate_template_volumes_specs(vm_mob_ref, options['volumes'], options['datacenter'])
632
+ # relocate templates is not supported by fog-vsphere when vm is cloned on a storage pod
633
+ unless options.key?('storage_pod')
634
+ relocation_spec[:disk] = relocate_template_volumes_specs(vm_mob_ref, options['volumes'], options['datacenter'])
635
+ end
633
636
  # And the clone specification
634
637
  clone_spec = RbVmomi::VIM.VirtualMachineCloneSpec(:location => relocation_spec,
635
638
  :config => virtual_machine_config_spec,
@@ -751,7 +754,7 @@ module Fog
751
754
 
752
755
  template_nics.zip(modified_nics).each do |template_nic, new_nic|
753
756
  if new_nic
754
- backing = create_nic_backing(new_nic, {})
757
+ backing = create_nic_backing(new_nic, {datacenter: datacenter})
755
758
  template_nic.backing = backing
756
759
  template_nic.addressType = 'generated'
757
760
  template_nic.macAddress = nil
@@ -801,7 +804,7 @@ module Fog
801
804
  end
802
805
  end
803
806
  specs.concat(new_volumes.map { |volume| create_disk(volume) })
804
- return specs
807
+ specs
805
808
  end
806
809
 
807
810
  def relocate_template_volumes_specs(vm_mob_ref, volumes, datacenter)
@@ -810,11 +813,11 @@ module Fog
810
813
 
811
814
  specs = []
812
815
  template_volumes.zip(modified_volumes).each do |template_volume, new_volume|
813
- if new_volume && new_volume.datastore != template_volume.backing.datastore.name
814
- specs << { :diskId => new_volume.key, :datastore => get_raw_datastore(new_volume.datastore, datacenter) }
816
+ if new_volume && new_volume.datastore && new_volume.datastore != template_volume.backing.datastore.name
817
+ specs << { :diskId => template_volume.key, :datastore => get_raw_datastore(new_volume.datastore, datacenter) }
815
818
  end
816
819
  end
817
- return specs
820
+ specs
818
821
  end
819
822
  end
820
823
 
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Vsphere
3
- VERSION = '2.0.1'.freeze
3
+ VERSION = '2.1.0'.freeze
4
4
  end
5
5
  end
@@ -5,10 +5,12 @@ Shindo.tests('Fog::Compute[:vsphere] | server model', ['vsphere']) do
5
5
  tests('The server model should') do
6
6
  tests('have the action') do
7
7
  test('reload') { server.respond_to? 'reload' }
8
- %w(stop start suspend destroy reboot).each do |action|
8
+ %w(stop suspend destroy reboot).each do |action|
9
9
  test(action) { server.respond_to? action }
10
10
  test("#{action} returns successfully") { server.send(action.to_sym) ? true : false }
11
11
  end
12
+ test('start') { server.respond_to?('start') }
13
+ test("start returns false, because it is already poweredOn") { server.start ? true : false }
12
14
  test('guest_processes') { server.respond_to? 'guest_processes' }
13
15
  test('take_snapshot') do
14
16
  test('responds') { server.respond_to? 'take_snapshot'}
@@ -7,7 +7,7 @@ Shindo.tests('Fog::Compute[:vsphere] | hosts collection', ['vsphere']) do
7
7
  tests('A ticket') do
8
8
  test('should have a ticket') { not ticket.ticket.empty? }
9
9
  test('should have a host') { not ticket.host.empty? }
10
- test('should have a port') { ticket.port.kind_of? Fixnum }
10
+ test('should have a port') { ticket.port.kind_of?(Integer) }
11
11
  test('should have a ssl ssl_thumbprint') { not ticket.ssl_thumbprint.empty? }
12
12
  end
13
13
 
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.0.1
4
+ version: 2.1.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-03-15 00:00:00.000000000 Z
11
+ date: 2018-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-core