Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VMware content library refresh #444

Merged
merged 4 commits into from
Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/manageiq/providers/vmware/infra_manager.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ManageIQ::Providers
class Vmware::InfraManager < InfraManager
require_nested :DistributedVirtualSwitch
require_nested :OrchestrationTemplate
require_nested :EventCatcher
require_nested :EventParser
require_nested :RefreshWorker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def full_refresh(vim, property_filter)

parse_updates(vim, parser, updated_objects)
parse_storage_profiles(vim, parser)
if vim.rev >= '6.0' && vim.serviceContent.about.apiType == 'VirtualCenter'
parse_content_libraries(parser)
end
save_inventory(persister)

self.last_full_refresh = Time.now.utc
Expand Down Expand Up @@ -239,6 +242,31 @@ def uncached_prop_set(obj)
@uncached_prop_set[obj.class.wsdl_name]
end

def parse_content_libraries(parser)
require 'vsphere-automation-content'
require 'vsphere-automation-cis'

configuration = VSphereAutomation::Configuration.new.tap do |c|
c.host = ems.hostname
c.username = ems.auth_user_pwd.first
c.password = ems.auth_user_pwd.last
c.scheme = 'https'
c.verify_ssl = false
c.verify_ssl_host = false
end

api_client = VSphereAutomation::ApiClient.new(configuration)
VSphereAutomation::CIS::SessionApi.new(api_client).create('')
api_libs = VSphereAutomation::Content::LibraryApi.new(api_client)
api_items = VSphereAutomation::Content::LibraryItemApi.new(api_client)

api_libs.list.value.each do |lib_id|
api_items.list(lib_id).value.each do |item_id|
parser.parse_content_library_item(api_items.get(item_id).value)
end
end
end

def parse_storage_profiles(vim, parser)
pbm = pbm_connect(vim)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ def parse_virtual_machine(object, kind, props)
parse_virtual_machine_snapshots(vm, props)
end

def parse_content_library_item(library_item)
props = {
:ems_ref => library_item.id,
:name => library_item.name,
:description => library_item.description,
:content => library_item.type # TODO: currently 'ovf|iso|file'
}
persister.orchestration_templates.build(props)
end

def lazy_find_managed_object(managed_object)
return if managed_object.nil?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def initialize_inventory_collections
add_collection(infra, :vm_parent_blue_folders)
add_collection(infra, :vm_resource_pools)
add_collection(infra, :root_folder_relationship)
add_collection(infra, :orchestration_templates) do |builder|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this to work we need to add the has_many :orchestration_templates association to the vmware infra_manager

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I have it in manageiq repo.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 that works too, we'll just need to add that assoc to the base InfraManager class then too

Copy link
Contributor Author

@jameswnl jameswnl Sep 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about having it here. But the CloudManager has the corresponding one in manageiq.

builder.add_default_values(:ems_id => manager.id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a helper method for this, builder.add_common_default_values

end
end

def vim_class_to_collection(managed_object)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ManageIQ::Providers::Vmware::InfraManager::OrchestrationTemplate < OrchestrationTemplate
def unique_md5?
false
end
end
1 change: 1 addition & 0 deletions manageiq-providers-vmware.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Gem::Specification.new do |s|
s.add_dependency("fog-vcloud-director", ["~> 0.3.0"])
s.add_dependency "vmware_web_service", "~>0.4.3"
s.add_dependency "rbvmomi", "~>2.0.0"
s.add_dependency "vsphere-automation-sdk", "~>0.2.1"

s.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
s.add_development_dependency "simplecov"
Expand Down