Skip to content

Commit

Permalink
Merge pull request ManageIQ#11 from xlab-si/versioned-collectors
Browse files Browse the repository at this point in the history
Versioned CloudManager and NetworkManager collectors
  • Loading branch information
Ladas authored Sep 30, 2019
2 parents 4dca041 + ce1ea69 commit d7e4503
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 78 deletions.
8 changes: 8 additions & 0 deletions app/models/manageiq/providers/azure_stack/inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ class ManageIQ::Providers::AzureStack::Inventory < ManageIQ::Providers::Inventor
def self.default_manager_name
'CloudManager'
end

# Sets the appropriate class of versioned collector for
# CloudManager and NetworkManager targets
def self.collector_class_for(ems, target = nil, manager_name = nil)
target = ems if target.nil?
manager_name = "#{target.class.name.demodulize}::#{ems.api_version}" if manager_name.nil?
class_for(ems, target, 'Collector', manager_name)
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# This class contains a reference implementation of collector for CloudManager.
# The methods implemented here are completely aligned with the V2018_03_01 version profile.
class ManageIQ::Providers::AzureStack::Inventory::Collector::CloudManager < ManageIQ::Providers::AzureStack::Inventory::Collector
require_nested :V2018_03_01
require_nested :V2017_03_09

def resource_groups
@resource_groups ||= azure_resources.resource_groups.list
end
Expand All @@ -8,24 +13,15 @@ def flavors
end

def vms
if azure_compute.respond_to?(:instance_view)
$azure_stack_log.debug("Fetching VMs, then fetching instance view for each")
azure_compute.virtual_machines.list_all.each do |vm|
vm.instance_view = azure_compute.virtual_machines.instance_view(resource_group_name(vm.id), vm.name)
end
else
$azure_stack_log.debug("Fetching VM ids, then fetching full data for each")
azure_resources.resources.list(:filter => "resourceType eq 'Microsoft.Compute/virtualMachines'").map do |vm|
azure_compute.virtual_machines.get(resource_group_name(vm.id), vm.name, :expand => 'instanceView')
end
$azure_stack_log.debug("Fetching VMs, then fetching instance view for each")
azure_compute.virtual_machines.list_all.each do |vm|
vm.instance_view = azure_compute.virtual_machines.instance_view(resource_group_name(vm.id), vm.name)
end
end

def orchestration_stacks
resource_groups.flat_map do |group|
# Old API names it 'list', recent versions name it 'list_by_resource_group'
meth = azure_resources.deployments.respond_to?(:list_by_resource_group) ? :list_by_resource_group : :list
azure_resources.deployments.send(meth, group.name).map do |deployment|
azure_resources.deployments.list_by_resource_group(group.name).map do |deployment|
[
group, # resource group
deployment, # deployment
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# rubocop:disable Naming/ClassAndModuleCamelCase
class ManageIQ::Providers::AzureStack::Inventory::Collector::CloudManager::V2017_03_09 < ManageIQ::Providers::AzureStack::Inventory::Collector::CloudManager
def vms
$azure_stack_log.debug("Fetching VM ids, then fetching full data for each")
azure_resources.resources.list(:filter => "resourceType eq 'Microsoft.Compute/virtualMachines'").map do |vm|
azure_compute.virtual_machines.get(resource_group_name(vm.id), vm.name, :expand => 'instanceView')
end
end

def orchestration_stacks
resource_groups.flat_map do |group|
azure_resources.deployments.list(group.name).map do |deployment|
[
group, # resource group
deployment, # deployment
azure_resources.deployment_operations.list(group.name, deployment.name) # operations of the deployment
]
end
end
end
end
# rubocop:enable Naming/ClassAndModuleCamelCase
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# rubocop:disable Naming/ClassAndModuleCamelCase
class ManageIQ::Providers::AzureStack::Inventory::Collector::CloudManager::V2018_03_01 < ManageIQ::Providers::AzureStack::Inventory::Collector::CloudManager
end
# rubocop:enable Naming/ClassAndModuleCamelCase
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# This class contains a reference implementation of collector for NetworkManager.
# The methods implemented here are completely aligned with the V2018_03_01 version profile.
class ManageIQ::Providers::AzureStack::Inventory::Collector::NetworkManager < ManageIQ::Providers::AzureStack::Inventory::Collector
require_nested :V2018_03_01
require_nested :V2017_03_09

def networks
azure_network.virtual_networks.list_all
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# rubocop:disable Naming/ClassAndModuleCamelCase
class ManageIQ::Providers::AzureStack::Inventory::Collector::NetworkManager::V2017_03_09 < ManageIQ::Providers::AzureStack::Inventory::Collector::NetworkManager
end
# rubocop:enable Naming/ClassAndModuleCamelCase
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# rubocop:disable Naming/ClassAndModuleCamelCase
class ManageIQ::Providers::AzureStack::Inventory::Collector::NetworkManager::V2018_03_01 < ManageIQ::Providers::AzureStack::Inventory::Collector::NetworkManager
end
# rubocop:enable Naming/ClassAndModuleCamelCase
3 changes: 2 additions & 1 deletion app/models/manageiq/providers/azure_stack/network_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class ManageIQ::Providers::AzureStack::NetworkManager < ManageIQ::Providers::Net
require_nested :NetworkPort
require_nested :SecurityGroup

delegate :authentication_check,
delegate :api_version,
:authentication_check,
:authentication_status,
:authentication_status_ok?,
:authentications,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d7e4503

Please sign in to comment.