Skip to content

Commit

Permalink
Versioned CloudManager and NetworkManager collectors
Browse files Browse the repository at this point in the history
This commit refactors collectors for CloudManager and Networkmanager,
so that the differences in collector methods due to our support for
two version profiles are accounted for in seperate subclasses of
manager's collector. We introduce one new class per API version profile
per manager. Behavior for the latest supported profile is kept in
Collector::CloudManager and Collector::NetworkManager, the profile
version-specific differences are covered in their subclasses. The
Inventory class now overrides `collector_class_for` method so that
the appropriate version of collector is constructed for CloudManager
and NetworkManager targets.

Signed-off-by: Manca Bizjak <[email protected]>
  • Loading branch information
mancabizjak committed Sep 27, 2019
1 parent 4dca041 commit ce1ea69
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 ce1ea69

Please sign in to comment.