Module: VagrantPlugins::VSphere::Util::VimHelpers
- Included in:
- Action::Clone, Action::Destroy, Action::GetSshInfo, Action::GetState, Action::PowerOff, Action::PowerOn, Action::Resume, Action::SnapshotDelete, Action::SnapshotList, Action::SnapshotRestore, Action::SnapshotSave, Action::Suspend
- Defined in:
- lib/vSphere/util/vim_helpers.rb
Instance Method Summary collapse
- #find_clustercompute_or_compute_resource(datacenter, path) ⇒ Object
- #get_compute_resource(datacenter, machine) ⇒ Object
- #get_customization_spec_info_by_name(connection, machine) ⇒ Object
- #get_datacenter(connection, machine) ⇒ Object
- #get_datastore(datacenter, machine) ⇒ Object
- #get_network_by_name(dc, name) ⇒ Object
- #get_resource_pool(datacenter, machine) ⇒ Object
- #get_vm_by_uuid(connection, machine) ⇒ Object
Instance Method Details
#find_clustercompute_or_compute_resource(datacenter, path) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/vSphere/util/vim_helpers.rb', line 50 def find_clustercompute_or_compute_resource(datacenter, path) case path when String es = path.split('/').reject(&:empty?) when Enumerable es = path else raise "unexpected path class #{path.class}" end return datacenter.hostFolder if es.empty? final = es.pop p = es.inject(datacenter.hostFolder) do |f, e| f.find(e, RbVmomi::VIM::Folder) || return end begin if (x = p.find(final, RbVmomi::VIM::ComputeResource)) x elsif (x = p.find(final, RbVmomi::VIM::ClusterComputeResource)) x end rescue Exception # When looking for the ClusterComputeResource there seems to be some parser error in RbVmomi Folder.find, try this instead x = p.childEntity.find { |x2| x2.name == final } if x.is_a?(RbVmomi::VIM::ClusterComputeResource) || x.is_a?(RbVmomi::VIM::ComputeResource) x else puts "ex unknown type #{x.to_json}" nil end end end |
#get_compute_resource(datacenter, machine) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/vSphere/util/vim_helpers.rb', line 43 def get_compute_resource(datacenter, machine) cr = find_clustercompute_or_compute_resource(datacenter, machine.provider_config.compute_resource_name) raise Errors::VSphereError, :missing_compute_resource if cr.nil? cr end |
#get_customization_spec_info_by_name(connection, machine) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/vSphere/util/vim_helpers.rb', line 85 def get_customization_spec_info_by_name(connection, machine) name = machine.provider_config.customization_spec_name return if name.nil? || name.empty? manager = connection.serviceContent.customizationSpecManager raise Errors::VSphereError, :null_configuration_spec_manager if manager.nil? spec = manager.GetCustomizationSpec(name: name) raise Errors::VSphereError, :missing_configuration_spec if spec.nil? spec end |
#get_datacenter(connection, machine) ⇒ Object
9 10 11 |
# File 'lib/vSphere/util/vim_helpers.rb', line 9 def get_datacenter(connection, machine) connection.serviceInstance.find_datacenter(machine.provider_config.data_center_name) || raise(Errors::VSphereError, :missing_datacenter) end |
#get_datastore(datacenter, machine) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/vSphere/util/vim_helpers.rb', line 98 def get_datastore(datacenter, machine) name = machine.provider_config.data_store_name return if name.nil? || name.empty? # find_datastore uses folder datastore that only lists Datastore and not StoragePod, if not found also try datastoreFolder which contains StoragePod(s) datacenter.find_datastore(name) || datacenter.datastoreFolder.traverse(name) || raise(Errors::VSphereError, :missing_datastore) end |
#get_network_by_name(dc, name) ⇒ Object
106 107 108 |
# File 'lib/vSphere/util/vim_helpers.rb', line 106 def get_network_by_name(dc, name) dc.network.find { |f| f.name == name } || raise(Errors::VSphereError, :missing_vlan) end |
#get_resource_pool(datacenter, machine) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vSphere/util/vim_helpers.rb', line 17 def get_resource_pool(datacenter, machine) rp = get_compute_resource(datacenter, machine) resource_pool_name = machine.provider_config.resource_pool_name || '' entity_array = resource_pool_name.split('/') entity_array.each do |entity_array_item| next if entity_array_item.empty? case rp when RbVmomi::VIM::Folder rp = rp.childEntity.find { |f| f.name == entity_array_item } || raise(Errors::VSphereError, :missing_resource_pool) when RbVmomi::VIM::ClusterComputeResource rp = rp.resourcePool.resourcePool.find { |f| f.name == entity_array_item } || raise(Errors::VSphereError, :missing_resource_pool) when RbVmomi::VIM::ResourcePool rp = rp.resourcePool.find { |f| f.name == entity_array_item } || raise(Errors::VSphereError, :missing_resource_pool) when RbVmomi::VIM::ComputeResource rp = rp.resourcePool.find(resource_pool_name) || raise(Errors::VSphereError, :missing_resource_pool) else raise Errors::VSphereError, :missing_resource_pool end end rp = rp.resourcePool if !rp.is_a?(RbVmomi::VIM::ResourcePool) && rp.respond_to?(:resourcePool) rp end |
#get_vm_by_uuid(connection, machine) ⇒ Object
13 14 15 |
# File 'lib/vSphere/util/vim_helpers.rb', line 13 def get_vm_by_uuid(connection, machine) get_datacenter(connection, machine).vmFolder.findByUuid machine.id end |