Skip to content

Commit

Permalink
Merge pull request ManageIQ#6 from xlab-si/connect-stack-with-vm
Browse files Browse the repository at this point in the history
Connect orchestration stack to its vms
  • Loading branch information
agrare committed Jul 18, 2019
2 parents efd0a02 + 5cb7d06 commit 88e2155
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 25 deletions.
1 change: 1 addition & 0 deletions app/models/manageiq/providers/azure_stack/cloud_manager.rb
Expand Up @@ -6,6 +6,7 @@ class ManageIQ::Providers::AzureStack::CloudManager < ManageIQ::Providers::Cloud
require_nested :Refresher
require_nested :RefreshWorker
require_nested :Vm
require_nested :OrchestrationStack

include ManageIQ::Providers::AzureStack::ManagerMixin

Expand Down
Expand Up @@ -22,10 +22,16 @@ def vms
end

def orchestration_stacks
resource_groups.map do |group|
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)
end.flatten
azure_resources.deployments.send(meth, 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
Expand Up @@ -79,13 +79,22 @@ def vms
end

def orchestration_stacks
collector.orchestration_stacks.each do |stack|
persister.orchestration_stacks.build(
:ems_ref => stack.id.downcase,
:name => stack.name,
:description => stack.name,
:status => stack.properties.provisioning_state
collector.orchestration_stacks.each do |resource_group, deployment, operations|
stack = persister.orchestration_stacks.build(
:ems_ref => deployment.id.downcase,
:name => deployment.name,
:description => deployment.name,
:status => deployment.properties.provisioning_state,
:resource_group => resource_group.name
)

# Connect VMs with orchestration stack.
operations.each do |op|
next unless (resource = op.properties.target_resource)
next unless resource.resource_type.downcase == 'microsoft.compute/virtualmachines'

persister.vms.find(resource.id.downcase)&.assign_attributes(:orchestration_stack => stack)
end
end
end

Expand Down
Expand Up @@ -8,12 +8,12 @@ def initialize_cloud_inventory_collections
operating_systems
flavors
vms
orchestration_stacks
].each do |name|
add_collection(cloud, name)
end

add_resource_groups
add_orchestration_stacks
end

def add_resource_groups
Expand All @@ -22,10 +22,4 @@ def add_resource_groups
builder.add_default_values(:ems_id => manager.id)
end
end

def add_orchestration_stacks
add_collection(cloud, :orchestration_stacks) do |builder|
builder.add_properties(:model_class => ::ManageIQ::Providers::AzureStack::CloudManager::OrchestrationStack)
end
end
end
Expand Up @@ -110,14 +110,15 @@ def assert_specific_vm
expect(ems_ref_suffix(vm.uid_ems)).to match(%r{^/providers/microsoft.compute/virtualmachines/[^/]+$})

expect(vm).to have_attributes(
:vendor => 'azure_stack',
:connection_state => 'connected',
:raw_power_state => 'PowerState/running',
:power_state => 'on',
:location => 'westus',
:availability_zone => zone,
:resource_group => resource_group,
:flavor => flavor
:vendor => 'azure_stack',
:connection_state => 'connected',
:raw_power_state => 'PowerState/running',
:power_state => 'on',
:location => 'westus',
:availability_zone => zone,
:resource_group => resource_group,
:flavor => flavor,
:orchestration_stack => stack
)

expect(vm.operating_system).not_to be_nil
Expand All @@ -135,7 +136,11 @@ def assert_specific_vm
def assert_specific_orchestration_stack
expect(stack).not_to be_nil
expect(ems_ref_suffix(stack.ems_ref)).to match(%r{^/providers/microsoft.resources/deployments/[^/]+$})
expect(stack).to have_attributes(:status => 'Succeeded', :description => stack.name)
expect(stack).to have_attributes(
:status => 'Succeeded',
:description => stack.name,
:resource_group => resource_group.name
)
end

def assert_security_group
Expand Down

0 comments on commit 88e2155

Please sign in to comment.