fog-vsphere 2.0.0 → 2.0.1

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: d0dddb289327d2871f911801e572de9b9f3301a1eb3b0da0e9aeb60f8660fc3d
4
- data.tar.gz: 2ed6a2f1ac3c94187cfdfc9dcc683f09c32c382c89872da97914754b4c567514
3
+ metadata.gz: 4991c02472ff132b2a1edef665c3dee7ee98ecec1a98bbad65947e574a9d6957
4
+ data.tar.gz: e484ae1b367e65fd7d799d1f50673a6584221da5e52ad610cd525e1d32e7de42
5
5
  SHA512:
6
- metadata.gz: 01ca149030adc6f5d6b76b2ee2f4c9e7986dd533f99ab49cea195f6cb8ec56da761851e577f93dab33fbcb3d4e044637b7f0b98dfbee105a2f87fc4f1c4b52da
7
- data.tar.gz: c0eb59366051e13703bf0a81ba091e84796dd1f1aae5e31260eb0bc9fa4dca46d56e4e1514daf06691b497b367b7735bb85f1fd102d4d8ad87c34e708e641ba9
6
+ metadata.gz: 0aed9e163c96fadd05853581565a520e841b4df4ff2509b5c8952ee9421f65ebd35d03cd4f94366708d866e97c9b068221818cc02c1e9848fec2041217122d23
7
+ data.tar.gz: d22e96a6ccaa8bdfd0a1c6ae564ba50317e08b6ab718ce78e1ace8c0422a05ea56fc9590e2ecc341b86ef6d5808b6289874f4b3312542f00c126187c108c3a4f
@@ -1,3 +1,8 @@
1
+ ## v2.0.1
2
+
3
+ * Ensure views are destroyed after use (#122)
4
+ * rescue nil for retrieving vm.config.instanceUuid (#123)
5
+
1
6
  ## v2.0.0
2
7
 
3
8
  * Drop support for ruby versions < 2.0.0
@@ -4,6 +4,7 @@
4
4
  * Ben Talbot - btalbot <ben_t48@hotmail.com>
5
5
  * Carl Caum <carl@carlcaum.com>
6
6
  * Carlos Sanchez <csanchez@maestrodev.com>
7
+ * Chris Roberts <chrobert@redhat.com>
7
8
  * Chris Thompson <chris.thompson@govdelivery.com>
8
9
  * Chris Thompson <teaforthecat@gmail.com>
9
10
  * Christopher Oliver <coliver@datapipe.com>
@@ -648,6 +648,30 @@ module Fog
648
648
  raise Fog::Vsphere::Errors::SecurityError, "The remote system presented a public key with hash #{pubkey_hash} but we're expecting a hash of #{expected_pubkey_hash || '<unset>'}. If you are sure the remote system is authentic set vsphere_expected_pubkey_hash: <the hash printed in this message> in ~/.fog"
649
649
  end
650
650
  end
651
+
652
+ def list_container_view(datacenter_obj_or_name, type, container_object = nil)
653
+ dc = if datacenter_obj_or_name.kind_of?(String)
654
+ find_raw_datacenter(datacenter_obj_or_name)
655
+ else
656
+ datacenter_obj_or_name
657
+ end
658
+
659
+ container = if container_object
660
+ dc.public_send(container_object)
661
+ else
662
+ dc
663
+ end
664
+
665
+ container_view = connection.serviceContent.viewManager.CreateContainerView(
666
+ :container => dc,
667
+ :type => [type],
668
+ :recursive => true
669
+ )
670
+
671
+ result = container_view.view
672
+ container_view.DestroyView
673
+ result
674
+ end
651
675
  end
652
676
  end
653
677
  end
@@ -11,13 +11,11 @@ module Fog
11
11
  protected
12
12
 
13
13
  def get_raw_datastore(name, datacenter_name)
14
- dc = find_raw_datacenter(datacenter_name)
14
+ get_raw_datastores(datacenter_name).detect { |ds| ds.name == name }
15
+ end
15
16
 
16
- connection.serviceContent.viewManager.CreateContainerView({
17
- :container => dc.datastoreFolder,
18
- :type => ["Datastore"],
19
- :recursive => true
20
- }).view.select{|ds| ds.name == name}.first
17
+ def get_raw_datastores(datacenter_name)
18
+ list_container_view(datacenter_name, 'Datastore', :datastoreFolder)
21
19
  end
22
20
  end
23
21
 
@@ -12,8 +12,7 @@ module Fog
12
12
 
13
13
  def get_raw_network(name, datacenter_name, distributedswitch=nil)
14
14
  finder = choose_finder(name, distributedswitch)
15
- networks = get_all_raw_networks(datacenter_name)
16
- networks.find { |n| finder.call(n) }
15
+ get_all_raw_networks(datacenter_name).find { |n| finder.call(n) }
17
16
  end
18
17
  end
19
18
 
@@ -22,13 +21,7 @@ module Fog
22
21
  protected
23
22
 
24
23
  def get_all_raw_networks(datacenter_name)
25
- dc = find_raw_datacenter(datacenter_name)
26
- connection.serviceContent.viewManager.
27
- CreateContainerView({
28
- :container => dc.networkFolder,
29
- :type => ["Network"],
30
- :recursive => true
31
- }).view
24
+ list_container_view(datacenter_name, 'Network', :networkFolder)
32
25
  end
33
26
 
34
27
  def choose_finder(name, distributedswitch)
@@ -11,19 +11,13 @@ module Fog
11
11
  protected
12
12
 
13
13
  def get_raw_storage_pod(name, datacenter_name)
14
- dc = find_raw_datacenter(datacenter_name)
15
-
16
- connection.serviceContent.viewManager.CreateContainerView({
17
- :container => dc,
18
- :type => ["StoragePod"],
19
- :recursive => true
20
- }).view.select{|pod| pod.name == name}.first
14
+ raw_storage_pods(datacenter_name).detect { |pod| pod.name == name}
21
15
  end
22
16
  end
23
17
 
24
18
  class Mock
25
19
  def get_storage_pod(name, datacenter_name)
26
- list_storage_pods({datacenter: datacenter_name}).select{|h| h[:name] == name }.first
20
+ list_storage_pods({datacenter: datacenter_name}).detect { |h| h[:name] == name }
27
21
  end
28
22
  end
29
23
  end
@@ -27,7 +27,7 @@ module Fog
27
27
  product_version: host.summary.config.product.version,
28
28
  hostname: (host.config.network.dnsConfig.hostName rescue nil),
29
29
  domainname: (host.config.network.dnsConfig.domainName rescue nil),
30
- vm_ids: Proc.new { host[:vm].map {|vm| vm.config.instanceUuid } }
30
+ vm_ids: Proc.new { host[:vm].map {|vm| vm.config.instanceUuid rescue nil} }
31
31
  }
32
32
  end
33
33
  end
@@ -10,18 +10,14 @@ module Fog
10
10
  end
11
11
 
12
12
  private
13
- def raw_storage_pods(datacenter_name)
14
- dc = find_raw_datacenter(datacenter_name)
15
13
 
16
- connection.serviceContent.viewManager.CreateContainerView({
17
- :container => dc,
18
- :type => ["StoragePod"],
19
- :recursive => true
20
- }).view
14
+ def raw_storage_pods(datacenter_name)
15
+ list_container_view(datacenter_name, 'StoragePod')
21
16
  end
17
+
22
18
  protected
23
19
 
24
- def storage_pod_attributes storage_pod, datacenter
20
+ def storage_pod_attributes(storage_pod, datacenter)
25
21
  {
26
22
  :id => managed_obj_id(storage_pod),
27
23
  :name => storage_pod.name,
@@ -27,14 +27,10 @@ module Fog
27
27
  datacenters = find_datacenters(options[:datacenter])
28
28
 
29
29
  vms = datacenters.map do |dc|
30
- connection.serviceContent.viewManager.CreateContainerView({
31
- :container => dc.vmFolder,
32
- :type => ["VirtualMachine"],
33
- :recursive => true
34
- }).view
30
+ list_container_view(dc, 'VirtualMachine', :vmFolder)
35
31
  end.flatten
36
32
  # remove all virtual machines that are not templates
37
- vms.delete_if { |v| v.config.nil? or not v.config.template }
33
+ vms.delete_if { |v| v.config.nil? || !v.config.template }
38
34
 
39
35
  vms.map(&method(:convert_vm_mob_ref_to_attr_hash))
40
36
  end
@@ -23,15 +23,15 @@ module Fog
23
23
  def list_all_virtual_machines_in_folder(path, datacenter_name, recursive)
24
24
  vms = raw_list_all_virtual_machines_in_folder(path, datacenter_name, recursive).to_a
25
25
  # remove all template based virtual machines
26
- vms.delete_if { |v| v.config.nil? or v.config.template }
26
+ vms.delete_if { |v| v.config.nil? || v.config.template }
27
27
  vms.map(&method(:convert_vm_mob_ref_to_attr_hash))
28
28
  end
29
-
29
+
30
30
  def raw_list_all_virtual_machines_in_folder(path, datacenter_name, recursive)
31
31
  folder = get_raw_vmfolder(path, datacenter_name)
32
32
  folder_enumerator(folder, recursive)
33
33
  end
34
-
34
+
35
35
  # An enumerator for a folder. Enumerates all the VMs in the folder, recursively if
36
36
  # passed recursive=true
37
37
  def folder_enumerator(raw_folder, recursive)
@@ -46,7 +46,7 @@ module Fog
46
46
  end
47
47
  end
48
48
  end
49
-
49
+
50
50
  def list_all_virtual_machines(options = { })
51
51
  raw_vms = raw_list_all_virtual_machines(options[:datacenter])
52
52
  vms = convert_vm_view_to_attr_hash(raw_vms)
@@ -62,17 +62,11 @@ module Fog
62
62
  ## much faster to interact for some functions.
63
63
  datacenters = find_datacenters(datacenter_name)
64
64
  datacenters.map do |dc|
65
- connection.serviceContent.viewManager.CreateContainerView({
66
- :container => dc.vmFolder,
67
- :type => ["VirtualMachine"],
68
- :recursive => true
69
- }).view
65
+ list_container_view(dc, 'VirtualMachine', :vmFolder)
70
66
  end.flatten
71
67
  end
72
68
  def get_folder_path(folder, root = nil)
73
- if (not folder.methods.include?('parent')) or (folder == root)
74
- return
75
- end
69
+ return if (!folder.methods.include?('parent')) || (folder == root)
76
70
  "#{get_folder_path(folder.parent)}/#{folder.name}"
77
71
  end
78
72
  end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Vsphere
3
- VERSION = '2.0.0'.freeze
3
+ VERSION = '2.0.1'.freeze
4
4
  end
5
5
  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: 2.0.0
4
+ version: 2.0.1
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-02-28 00:00:00.000000000 Z
11
+ date: 2018-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-core