Skip to content

Commit

Permalink
Add resource_pools relationship collection
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed May 7, 2018
1 parent c562137 commit b5002fe
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module ManageIQ::Providers::Vmware::InfraManager::Inventory::Collector::Property
"resourceConfig.memoryAllocation.reservation",
"resourceConfig.memoryAllocation.shares.level",
"resourceConfig.memoryAllocation.shares.shares",
"resourcePool",
"snapshot",
"summary.vm",
"summary.config.annotation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def vms_and_templates(extra_attributes = {})
attributes = {
:model_class => ::VmOrTemplate,
:association => :vms_and_templates,
:attributes_blacklist => %i(parent),
:attributes_blacklist => %i(parent resource_pool),
:builder_params => {
:ems_id => ->(persister) { persister.manager.id },
},
Expand Down Expand Up @@ -62,5 +62,13 @@ def guest_devices(extra_attributes = {})
attributes = {:parent_inventory_collections => [:vms_and_templates]}
super(attributes.merge(extra_attributes))
end

def parent_blue_folders(extra_attributes = {})
relationships(:parent, :ems_metadata, :parent_blue_folders, extra_attributes)
end

def vm_resource_pools(extra_attributes = {})
relationships(:resource_pool, :ems_metadata, :vm_resource_pools, extra_attributes)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +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]),
:parent => lazy_find_managed_object(props[:parent]),
}

parse_compute_resource_summary(cluster_hash, props)
Expand All @@ -51,7 +51,7 @@ def parse_datacenter(object, props)
:uid_ems => object._ref,
:type => "Datacenter",
:name => CGI.unescape(props[:name]),
:parent => parse_parent(props[:parent]),
:parent => lazy_find_managed_object(props[:parent]),
}

persister.ems_folders.build(dc_hash)
Expand All @@ -63,7 +63,7 @@ def parse_datastore(object, props)

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

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

parse_dvs_config(switch_hash, props[:config])
Expand All @@ -105,7 +105,7 @@ def parse_folder(object, props)
:uid_ems => object._ref,
:type => "EmsFolder",
:name => CGI.unescape(props[:name]),
:parent => parse_parent(props[:parent]),
:parent => lazy_find_managed_object(props[:parent]),
}

persister.ems_folders.build(folder_hash)
Expand All @@ -117,7 +117,7 @@ def parse_host_system(object, props)

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

parse_host_system_config(host_hash, props)
Expand Down Expand Up @@ -184,7 +184,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]),
:parent => lazy_find_managed_object(props[:parent]),
}

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

persister.ems_folders.build(pod_hash)
Expand All @@ -217,9 +217,10 @@ def parse_virtual_machine(object, props)
return if props.nil?

vm_hash = {
:ems_ref => object._ref,
:vendor => "vmware",
:parent => parse_parent(props[:parent]),
:ems_ref => object._ref,
:vendor => "vmware",
:parent => lazy_find_managed_object(props[:parent]),
:resource_pool => lazy_find_managed_object(props[:resourcePool]),
}

parse_virtual_machine_config(vm_hash, props)
Expand All @@ -234,7 +235,7 @@ def parse_virtual_machine(object, props)
parse_virtual_machine_snapshots(vm, props)
end

def parse_parent(managed_object)
def lazy_find_managed_object(managed_object)
return if managed_object.nil?

parent_collection = persister.vim_class_to_collection(managed_object)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ def initialize_inventory_collections
end

add_inventory_collection(
default_inventory_collections.relationships(
:parent, :ems_metadata, :relationships, :dependency_attributes => dependency_attributes
default_inventory_collections.parent_blue_folders(:dependency_attributes => dependency_attributes)
)

add_inventory_collection(
default_inventory_collections.vm_resource_pools(
:dependency_attributes => {:vms_and_templates => [collections[:vms_and_templates]]}
)
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,13 @@ def assert_specific_vm
# TODO: expect(vm.ems_cluster).not_to be_nil

expect(vm.host).not_to be_nil
expect(vm.host.ems_ref).to eq("host-16")
expect(vm.host.ems_ref).to eq("host-17")

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

# TODO: expect(vm.parent_yellow_folder).not_to be_nil
# TODO: expect(vm.parent_resource_pool).not_to be_nil
expect(vm.parent_resource_pool).not_to be_nil
end
end
end

Large diffs are not rendered by default.

0 comments on commit b5002fe

Please sign in to comment.