Skip to content

Commit

Permalink
Add ems_ref_obj to streaming refresh parser
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed May 22, 2018
1 parent 961d960 commit 600c08b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'VMwareWebService/VimTypes'

class ManageIQ::Providers::Vmware::InfraManager::Inventory::Parser
include_concern :ComputeResource
include_concern :Datastore
Expand Down Expand Up @@ -28,10 +30,11 @@ def parse_compute_resource(object, kind, props)
return if kind == "leave"

cluster_hash = {
:ems_ref => object._ref,
:uid_ems => object._ref,
:name => CGI.unescape(props[:name]),
:parent => lazy_find_managed_object(props[:parent]),
:ems_ref => object._ref,
:ems_ref_obj => managed_object_to_vim_string(object),
:uid_ems => object._ref,
:name => CGI.unescape(props[:name]),
:parent => lazy_find_managed_object(props[:parent]),
}

parse_compute_resource_summary(cluster_hash, props)
Expand All @@ -47,11 +50,12 @@ def parse_datacenter(object, kind, props)
return if kind == "leave"

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

persister.ems_folders.build(dc_hash)
Expand All @@ -62,8 +66,9 @@ def parse_datastore(object, kind, props)
return if kind == "leave"

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

parse_datastore_summary(storage_hash, props)
Expand Down Expand Up @@ -106,12 +111,13 @@ def parse_folder(object, kind, props)
hidden = props[:parent].nil? || props[:parent].kind_of?(RbVmomi::VIM::Datacenter)

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

persister.ems_folders.build(folder_hash)
Expand All @@ -123,8 +129,9 @@ def parse_host_system(object, kind, props)

cluster = lazy_find_managed_object(props[:parent])
host_hash = {
:ems_cluster => cluster,
:ems_ref => object._ref,
:ems_ref_obj => managed_object_to_vim_string(object),
:ems_cluster => cluster,
:parent => cluster,
}

Expand Down Expand Up @@ -205,12 +212,13 @@ def parse_resource_pool(object, kind, props)
end

rp_hash = {
:ems_ref => object._ref,
:uid_ems => object._ref,
:name => name,
:vapp => object.kind_of?(RbVmomi::VIM::VirtualApp),
:parent => lazy_find_managed_object(parent),
:is_default => is_default,
:ems_ref => object._ref,
:ems_ref_obj => managed_object_to_vim_string(object),
:uid_ems => object._ref,
:name => name,
:vapp => object.kind_of?(RbVmomi::VIM::VirtualApp),
:parent => lazy_find_managed_object(parent),
:is_default => is_default,
}

parse_resource_pool_memory_allocation(rp_hash, props)
Expand Down Expand Up @@ -243,6 +251,7 @@ def parse_virtual_machine(object, kind, props)

vm_hash = {
:ems_ref => object._ref,
:ems_ref_obj => managed_object_to_vim_string(object),
:vendor => "vmware",
:parent => lazy_find_managed_object(props[:parent]),
:resource_pool => lazy_find_managed_object(props[:resourcePool]),
Expand All @@ -267,4 +276,12 @@ def lazy_find_managed_object(managed_object)
parent_collection = persister.vim_class_to_collection(managed_object)
parent_collection.lazy_find(managed_object._ref)
end

def managed_object_to_vim_string(object)
ref = object._ref
vim_type = object.class.wsdl_name.to_sym
xsi_type = :ManagedObjectReference

VimString.new(ref, vim_type, xsi_type)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,22 @@ def parse_virtual_machine_snapshots(vm, props)
end

def parse_virtual_machine_snapshot(vm, snapshot, current, parent_uid = nil)
snap_ref = snapshot[:snapshot]&._ref
return if snap_ref.nil?
snap = snapshot[:snapshot]
return if snap.nil?

create_time = snapshot[:createTime]

snapshot_hash = {
:vm_or_template => vm,
:ems_ref => snap_ref,
:ems_ref => snap._ref,
:ems_ref_obj => managed_object_to_vim_string(snap),
:uid_ems => create_time.to_s,
:uid => create_time.iso8601(6),
:parent_uid => parent_uid,
:name => CGI.unescape(snapshot[:name]),
:description => snapshot[:description],
:create_time => create_time.to_s,
:current => snap_ref == current._ref,
:current => snap._ref == current._ref,
}

persister.snapshots.build(snapshot_hash)
Expand Down

0 comments on commit 600c08b

Please sign in to comment.