Skip to content

Commit

Permalink
Merge pull request #256 from agrare/datastore_url
Browse files Browse the repository at this point in the history
Fix storage parsing to use datastore url
  • Loading branch information
Ladas authored May 14, 2018
2 parents e2e2b80 + 7c0a965 commit 11058cd
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def parse_datacenter(object, kind, props)
end

def parse_datastore(object, kind, props)
persister.storages.targeted_scope << object._ref
persister.storages.targeted_scope << parse_datastore_location(props)
return if kind == "leave"

storage_hash = {
Expand Down Expand Up @@ -226,6 +226,7 @@ def parse_virtual_machine(object, kind, props)
parse_virtual_machine_config(vm_hash, props)
parse_virtual_machine_resource_config(vm_hash, props)
parse_virtual_machine_summary(vm_hash, props)
parse_virtual_machine_storage(vm_hash, props)

vm = persister.vms_and_templates.build(vm_hash)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ def parse_datastore_summary(storage_hash, props)
return if summary.nil?

storage_hash[:name] = summary[:name]
storage_hash[:location] = normalize_storage_uid(summary[:url])
storage_hash[:location] = parse_datastore_location(props)
storage_hash[:store_type] = summary[:type].to_s.upcase
storage_hash[:total_space] = summary[:capacity]
storage_hash[:free_space] = summary[:freeSpace]
storage_hash[:uncommitted] = summary[:uncommitted]
storage_hash[:multiplehostaccess] = summary[:multipleHostAccess].to_s.downcase == "true"
end

def parse_datastore_location(props)
url = props.fetch_path(:summary, :url)
normalize_storage_uid(url) if url
end

def parse_datastore_capability(storage_hash, props)
capability = props[:capability]
return if capability.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ def parse_virtual_machine_summary(vm_hash, props)
parse_virtual_machine_summary_runtime(vm_hash, props)
end

def parse_virtual_machine_storage(vm_hash, props)
vm_path_name = props.fetch_path(:summary, :config, :vmPathName)
return if vm_path_name.nil?

datastore_name = vm_path_name.gsub(/^\[([^\]]*)\].*/, '\1')
return if datastore_name.nil?

datastore = props[:datastore].to_a.detect do |ds|
cache.find(ds)&.dig(:summary, :name) == datastore_name
end

datastore_props = cache.find(datastore) if datastore
vm_hash[:storage] = persister.storages.lazy_find(parse_datastore_location(datastore_props)) if datastore_props
end

def parse_virtual_machine_summary_runtime(vm_hash, props)
runtime = props.fetch_path(:summary, :runtime)
return if runtime.nil?
Expand Down Expand Up @@ -187,7 +202,13 @@ def parse_virtual_machine_disks(hardware, props)
case backing
when RbVmomi::VIM::VirtualDeviceFileBackingInfo
disk_hash[:filename] = backing.fileName
disk_hash[:storage] = persister.storages.lazy_find(backing.datastore._ref) unless backing.datastore.nil?

if backing.datastore
datastore_props = cache.find(backing.datastore)
datastore_location = parse_datastore_location(datastore_props) if datastore_props

disk_hash[:storage] = persister.storages.lazy_find(datastore_location) if datastore_location
end
when RbVmomi::VIM::VirtualDeviceRemoteDeviceBackingInfo
disk_hash[:filename] = backing.deviceName
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

assert_ems
assert_specific_datacenter
assert_specific_datastore
assert_specific_folder
assert_specific_host
assert_specific_cluster
Expand Down Expand Up @@ -72,9 +73,9 @@
it "deleting a virtual machine" do
vm = ems.vms.find_by(:ems_ref => 'vm-107')

expect(vm.archived?).to be_falsy
expect(vm.orphaned?).to be_falsy
run_targeted_refresh(targeted_update_set(vm_delete_object_updates))
expect(vm.reload.archived?).to be_truthy
expect(vm.reload.orphaned?).to be_truthy
end

def run_targeted_refresh(update_set)
Expand Down Expand Up @@ -200,6 +201,26 @@ def assert_specific_datacenter
expect(datacenter.children.map(&:name)).to match_array(%w(host network datastore vm))
end

def assert_specific_datastore
storage = ems.storages.find_by(:location => "ds:///vmfs/volumes/5280a4c3-b5e2-7dc7-5c31-7a344d35466c/")

expect(storage).to have_attributes(
:location => "ds:///vmfs/volumes/5280a4c3-b5e2-7dc7-5c31-7a344d35466c/",
:name => "GlobalDS_0",
:store_type => "VMFS",
:total_space => 1_099_511_627_776,
:free_space => 824_633_720_832,
:multiplehostaccess => 1,
:directory_hierarchy_supported => true,
:thin_provisioning_supported => true,
:raw_disk_mappings_supported => true,
)

expect(storage.hosts.count).to eq(32)
expect(storage.disks.count).to eq(512)
expect(storage.vms.count).to eq(512)
end

def assert_specific_folder
folder = ems.ems_folders.find_by(:ems_ref => "group-d1")

Expand Down Expand Up @@ -388,6 +409,9 @@ def assert_specific_vm
expect(vm.host).not_to be_nil
expect(vm.host.ems_ref).to eq("host-17")

expect(vm.storage).not_to be_nil
expect(vm.storage.name).to eq("GlobalDS_0")

expect(vm.parent_blue_folder).not_to be_nil
expect(vm.parent_blue_folder.ems_ref).to eq("group-v3")

Expand Down

0 comments on commit 11058cd

Please sign in to comment.