Skip to content

Commit

Permalink
Parse parent for most collections
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed May 3, 2018
1 parent 452740e commit 99388b2
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 121 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module ManageIQ::Providers::Vmware::InfraManager::Inventory::Collector::PropertyCollector
EmsRefreshPropMap = {
:ManagedEntity => [
"name",
"parent",
],
:VirtualMachine => [
"availableField",
"config.cpuAffinity.affinitySet",
Expand Down Expand Up @@ -48,9 +52,7 @@ module ManageIQ::Providers::Vmware::InfraManager::Inventory::Collector::Property
"summary.storage.committed",
],
:ComputeResource => [
"name",
"host",
"parent",
"resourcePool",
],
:ClusterComputeResource => [
Expand All @@ -64,13 +66,9 @@ module ManageIQ::Providers::Vmware::InfraManager::Inventory::Collector::Property
"summary.effectiveCpu",
"summary.effectiveMemory",
"host",
"name",
"parent",
"resourcePool",
],
:ResourcePool => [
"name",
"parent",
"resourcePool",
"summary.config.cpuAllocation.expandableReservation",
"summary.config.cpuAllocation.limit",
Expand All @@ -85,16 +83,11 @@ module ManageIQ::Providers::Vmware::InfraManager::Inventory::Collector::Property
"vm",
],
:Folder => [
"childEntity",
"name",
"parent",
],
:Datacenter => [
"datastoreFolder",
"hostFolder",
"name",
"networkFolder",
"parent",
"vmFolder",
],
:HostSystem => [
Expand All @@ -115,7 +108,6 @@ module ManageIQ::Providers::Vmware::InfraManager::Inventory::Collector::Property
"config.storageDevice.scsiTopology.adapter",
"datastore",
"hardware.systemInfo.otherIdentifyingInfo",
"name",
"summary.host",
"summary.config.name",
"summary.config.product.build",
Expand Down Expand Up @@ -153,22 +145,18 @@ module ManageIQ::Providers::Vmware::InfraManager::Inventory::Collector::Property
"summary.type",
"summary.uncommitted",
"summary.url",
"parent",
],
:StoragePod => [
"summary.capacity",
"summary.freeSpace",
"summary.name",
"childEntity",
"parent",
],
:DistributedVirtualPortgroup => [
"summary.name",
"config.key",
"config.defaultPortConfig",
"config.distributedVirtualSwitch",
"config.name",
"parent",
"host",
"tag",
],
Expand All @@ -180,7 +168,6 @@ module ManageIQ::Providers::Vmware::InfraManager::Inventory::Collector::Property
"summary.uuid",
"summary.host",
"summary.hostMember",
"parent",
]
}.freeze

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
class ManageIQ::Providers::Vmware::InfraManager::Inventory::Parser
include_concern :ComputeResource
include_concern :Datacenter
include_concern :Datastore
include_concern :DistributedVirtualSwitch
include_concern :Folder
include_concern :HostSystem
include_concern :ResourcePool
include_concern :VirtualMachine
Expand Down Expand Up @@ -32,6 +30,7 @@ def parse_compute_resource(object, props)
:ems_ref => object._ref,
:uid_ems => object._ref,
:name => CGI.unescape(props[:name]),
:parent => parse_parent(props[:parent]),
}

parse_compute_resource_summary(cluster_hash, props)
Expand All @@ -48,15 +47,13 @@ def parse_datacenter(object, props)
return if props.nil?

dc_hash = {
:ems_ref => object._ref,
:uid_ems => object._ref,
:type => "Datacenter",
:name => CGI.unescape(props[:name]),
:ems_children => {},
:ems_ref => object._ref,
:uid_ems => object._ref,
:type => "Datacenter",
:name => CGI.unescape(props[:name]),
:parent => parse_parent(props[:parent]),
}

parse_datacenter_children(dc_hash, props)

persister.ems_folders.build(dc_hash)
end

Expand All @@ -66,6 +63,7 @@ def parse_datastore(object, props)

storage_hash = {
:ems_ref => object._ref,
:parent => parse_parent(props[:parent]),
}

parse_datastore_summary(storage_hash, props)
Expand All @@ -86,6 +84,7 @@ def parse_distributed_virtual_switch(object, props)
:uid_ems => object._ref,
:type => type,
:shared => true,
:parent => parse_parent(props[:parent]),
}

parse_dvs_config(switch_hash, props[:config])
Expand All @@ -102,15 +101,13 @@ def parse_folder(object, props)
return if props.nil?

folder_hash = {
:ems_ref => object._ref,
:uid_ems => object._ref,
:type => "EmsFolder",
:name => CGI.unescape(props[:name]),
:ems_children => {},
:ems_ref => object._ref,
:uid_ems => object._ref,
:type => "EmsFolder",
:name => CGI.unescape(props[:name]),
:parent => parse_parent(props[:parent]),
}

parse_folder_children(folder_hash, props)

persister.ems_folders.build(folder_hash)
end

Expand Down Expand Up @@ -186,6 +183,7 @@ def parse_resource_pool(object, props)
:uid_ems => object._ref,
:name => CGI.unescape(props[:name]),
:vapp => object.kind_of?(RbVmomi::VIM::VirtualApp),
:parent => parse_parent(props[:parent]),
}

parse_resource_pool_memory_allocation(rp_hash, props)
Expand All @@ -207,6 +205,7 @@ def parse_storage_pod(object, props)
:uid_ems => object._ref,
:type => "StorageCluster",
:name => CGI.unescape(name),
:parent => parse_parent(props[:parent]),
}

persister.ems_folders.build(pod_hash)
Expand All @@ -219,6 +218,7 @@ def parse_virtual_machine(object, props)
vm_hash = {
:ems_ref => object._ref,
:vendor => "vmware",
:parent => parse_parent(props[:parent]),
}

parse_virtual_machine_config(vm_hash, props)
Expand All @@ -232,4 +232,11 @@ def parse_virtual_machine(object, props)
parse_virtual_machine_custom_attributes(vm, props)
parse_virtual_machine_snapshots(vm, props)
end

def parse_parent(managed_object)
return if managed_object.nil?

parent_collection = persister.vim_class_to_collection(managed_object)
parent_collection.lazy_find(managed_object._ref)
end
end

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,19 @@ def inventory_collection_options
:targeted => targeted,
}
end

def vim_class_to_collection(managed_object)
case managed_object
when RbVmomi::VIM::ComputeResource
ems_clusters
when RbVmomi::VIM::Datacenter
ems_folders
when RbVmomi::VIM::HostSystem
hosts
when RbVmomi::VIM::Folder
ems_folders
when RbVmomi::VIM::ResourcePool
resource_pools
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ def assert_specific_datacenter
:uid_ems => "datacenter-2",
)

# TODO: check relationships
expect(datacenter.parent.ems_ref).to eq("group-d1")

expect(datacenter.children.count).to eq(4)
expect(datacenter.children.map(&:name)).to match_array(%w(host network datastore vm))
end

def assert_specific_folder
Expand All @@ -163,7 +166,9 @@ def assert_specific_folder
:uid_ems => "group-d1",
)

# TODO: check relationships
expect(folder.parent).to be_nil
expect(folder.children.count).to eq(4)
expect(folder.children.map(&:name)).to match_array(%w(DC0 DC1 DC2 DC3))
end

def assert_specific_host
Expand Down Expand Up @@ -214,6 +219,9 @@ def assert_specific_cluster
:name => "DC0_C0",
:uid_ems => "domain-c12",
)

expect(cluster.children.count).to eq(1)
expect(cluster.children.first.ems_ref).to eq("resgroup-13")
end

def assert_specific_resource_pool
Expand All @@ -234,6 +242,13 @@ def assert_specific_resource_pool
:name => "Resources",
:vapp => false,
)

expect(resource_pool.parent.ems_ref).to eq("domain-c91")

expect(resource_pool.children.count).to eq(8)
expect(resource_pool.children.map(&:ems_ref)).to match_array(
%w(resgroup-106 resgroup-115 resgroup-124 resgroup-133 resgroup-142 resgroup-151 resgroup-160 resgroup-97)
)
end

def assert_specific_dvswitch
Expand Down
Loading

0 comments on commit 99388b2

Please sign in to comment.