Skip to content

Commit

Permalink
Collect customization_specs
Browse files Browse the repository at this point in the history
The collection of customization_spces with streaming refresh was missed
when moving from legacy refresh
  • Loading branch information
agrare committed Aug 26, 2020
1 parent d6f7878 commit 3055c37
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 182 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,12 @@ def parse_updates(vim, parser, updated_objects)
parser.parse_ext_management_system(ems, vim.serviceContent.about)

updated_objects.each do |managed_object, update_kind, cached_props|
props = cached_props

uncached_props = retrieve_uncached_props(managed_object)
props = uncached_props.present? ? cached_props.deep_merge(uncached_props) : cached_props
props = props.deep_merge(uncached_props) if uncached_props.present?

retrieve_extra_props(managed_object, props)

parser.parse(managed_object, update_kind, props)
end
Expand Down Expand Up @@ -261,6 +265,22 @@ def uncached_prop_set(obj)
@uncached_prop_set[obj.class.wsdl_name]
end

def retrieve_extra_props(obj, cached_props)
case obj.class.wsdl_name
when "CustomizationSpecManager"
retrieve_customization_spec(obj, cached_props)
end
end

def retrieve_customization_spec(spec_manager, cached_props)
cached_props[:info].to_a.each do |spec_info|
spec_info.props[:spec] = spec_manager.GetCustomizationSpec(:name => spec_info.name)&.spec
rescue RbVmomi::Fault => err
# Don't fail the refresh for issues with specific items
_log.warn("Failed to get customization spec for [#{spec_info.name}]: #{err}")
end
end

def parse_content_libraries(parser)
require 'vsphere-automation-content'
require 'vsphere-automation-cis'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ def destroy_property_filter(property_filter)
def ems_inventory_filter_spec(vim)
RbVmomi::VIM.PropertyFilterSpec(
:objectSet => [
extension_manager_object_spec(vim.serviceContent.extensionManager),
root_folder_object_spec(vim.serviceContent.rootFolder),
license_manager_object_spec(vim.serviceContent.licenseManager),
RbVmomi::VIM.ObjectSpec(:obj => vim.serviceContent.customizationSpecManager),
RbVmomi::VIM.ObjectSpec(:obj => vim.serviceContent.extensionManager),
RbVmomi::VIM.ObjectSpec(:obj => vim.serviceContent.rootFolder, :selectSet => root_folder_select_set),
RbVmomi::VIM.ObjectSpec(:obj => vim.serviceContent.licenseManager),
],
:propSet => ems_inventory_prop_set
)
end

def extension_manager_object_spec(extension_manager)
RbVmomi::VIM.ObjectSpec(:obj => extension_manager)
end

def ems_inventory_prop_set
property_set_from_file("ems_inventory")
end
Expand All @@ -41,18 +38,10 @@ def property_set_from_file(file_name)
end
end

def root_folder_object_spec(root)
RbVmomi::VIM.ObjectSpec(:obj => root, :selectSet => root_folder_select_set)
end

def root_folder_select_set
traversal_spec_from_file("root_folder")
end

def license_manager_object_spec(license_manager)
RbVmomi::VIM.ObjectSpec(:obj => license_manager)
end

def traversal_spec_from_file(file_name)
engine_root = ManageIQ::Providers::Vmware::Engine.root
hash = YAML.load_file(engine_root.join("config", "traversal_specs", "#{file_name}.yml"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ def parse_compute_resource(object, kind, props)
end
alias parse_cluster_compute_resource parse_compute_resource

def parse_customization_spec_manager(_object, kind, props)
return if kind == "leave"

props[:info].to_a.each do |spec_info|
persister.customization_specs.build(
:name => spec_info[:name],
:typ => spec_info[:type],
:description => spec_info[:description],
:last_update_time => spec_info[:last_update_time].to_s,
:spec => rbvmomi_to_vim_types(spec_info[:spec])
)
end
end

def parse_datacenter(object, kind, props)
persister.ems_folders.targeted_scope << object._ref
return if kind == "leave"
Expand Down Expand Up @@ -377,4 +391,17 @@ 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 rbvmomi_to_vim_types(obj)
case obj
when RbVmomi::BasicTypes::DataObject
VimHash.new(obj.class.wsdl_name) do |new_obj|
obj.props.each { |k, v| new_obj[k.to_s] = rbvmomi_to_vim_types(v) }
end
when Array
obj.map { |v| rbvmomi_to_basic_types(v) }
else
obj
end
end
end
2 changes: 2 additions & 0 deletions config/property_specs/ems_inventory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,5 @@
- licenses
:ExtensionManager:
- extensionList
:CustomizationSpecManager:
- info
Loading

0 comments on commit 3055c37

Please sign in to comment.