Skip to content

Commit

Permalink
Merge pull request #6233 from djberg96/azure_nic_refactor
Browse files Browse the repository at this point in the history
Refactor Azure refresh parser to make a single call to get network interfaces
  • Loading branch information
chessbyte committed Jan 22, 2016
2 parents 02568c8 + 73625f0 commit 43e3386
Show file tree
Hide file tree
Showing 3 changed files with 7,640 additions and 3,459 deletions.
51 changes: 26 additions & 25 deletions app/models/manageiq/providers/azure/cloud_manager/refresh_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,30 @@ def self.ems_inv_to_hashes(ems, options = nil)
end

def initialize(ems, options = nil)
@ems = ems
@config = ems.connect
@subscription_id = @config.subscription_id
@vmm = ::Azure::Armrest::VirtualMachineService.new(@config)
@asm = ::Azure::Armrest::AvailabilitySetService.new(@config)
@tds = ::Azure::Armrest::TemplateDeploymentService.new(@config)
@vns = ::Azure::Armrest::Network::VirtualNetworkService.new(@config)
@ips = ::Azure::Armrest::Network::IpAddressService.new(@config)
@nis = ::Azure::Armrest::Network::NetworkInterfaceService.new(@config)
@rgs = ::Azure::Armrest::ResourceGroupService.new(@config)
@sas = ::Azure::Armrest::StorageAccountService.new(@config)
@options = options || {}
@data = {}
@data_index = {}
@resource_to_stack = {}
@ems = ems
@config = ems.connect
@subscription_id = @config.subscription_id
@vmm = ::Azure::Armrest::VirtualMachineService.new(@config)
@asm = ::Azure::Armrest::AvailabilitySetService.new(@config)
@tds = ::Azure::Armrest::TemplateDeploymentService.new(@config)
@vns = ::Azure::Armrest::Network::VirtualNetworkService.new(@config)
@ips = ::Azure::Armrest::Network::IpAddressService.new(@config)
@nis = ::Azure::Armrest::Network::NetworkInterfaceService.new(@config)
@rgs = ::Azure::Armrest::ResourceGroupService.new(@config)
@sas = ::Azure::Armrest::StorageAccountService.new(@config)
@options = options || {}
@data = {}
@data_index = {}
@resource_to_stack = {}
@network_interfaces = []
end

def ems_inv_to_hashes
log_header = "Collecting data for EMS : [#{@ems.name}] id: [#{@ems.id}]"

_log.info("#{log_header}...")
get_resource_groups
get_network_interfaces
get_series
get_availability_zones
get_stacks
Expand All @@ -46,6 +48,10 @@ def ems_inv_to_hashes

private

def get_network_interfaces
@network_interfaces = gather_data_for_this_region(@nis)
end

def get_resource_groups
resource_groups = @rgs.list.select do |resource_group|
resource_group.location == @ems.provider_region
Expand Down Expand Up @@ -126,11 +132,8 @@ def get_images
end

def get_vm_nics(instance)
instance.properties.network_profile.network_interfaces.collect do |nic|
group = nic.id[%r{resourceGroups/(.*?)/}, 1]
nic_name = File.basename(nic.id)
@nis.get(nic_name, group)
end
nic_ids = instance.properties.network_profile.network_interfaces.collect(&:id)
@network_interfaces.find_all { |nic| nic_ids.include?(nic.id) }
end

def process_collection(collection, key)
Expand All @@ -146,11 +149,9 @@ def process_collection(collection, key)
end

def gather_data_for_this_region(arm_service, method = "list")
results = []
@data[:resource_groups].each do |resource_group|
results << arm_service.send(method, resource_group[:name])
end
results.flatten
@data[:resource_groups].collect do |resource_group|
arm_service.send(method, resource_group[:name])
end.flatten
end

def parse_resource_group(resource_group)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ def join; end

def assert_table_counts
expect(ExtManagementSystem.count).to eql(1)
expect(Flavor.count).to eql(33)
expect(Flavor.count).to eql(42)
expect(AvailabilityZone.count).to eql(1)
expect(VmOrTemplate.count).to eql(13)
expect(Vm.count).to eql(9)
expect(VmOrTemplate.count).to eql(17)
expect(Vm.count).to eql(13)
expect(MiqTemplate.count).to eql(4)
expect(Disk.count).to eql(11)
expect(Disk.count).to eql(15)
expect(GuestDevice.count).to eql(0)
expect(Hardware.count).to eql(13)
expect(Network.count).to eql(15)
expect(OperatingSystem.count).to eql(9)
expect(Hardware.count).to eql(17)
expect(Network.count).to eql(23)
expect(OperatingSystem.count).to eql(13)
expect(Relationship.count).to eql(0)
expect(MiqQueue.count).to eql(13)
expect(OrchestrationTemplate.count).to eql(3)
expect(MiqQueue.count).to eql(17)
expect(OrchestrationTemplate.count).to eql(2)
expect(OrchestrationStack.count).to eql(7)
expect(OrchestrationStackParameter.count).to eql(72)
expect(OrchestrationStackOutput.count).to eql(5)
Expand All @@ -72,20 +72,20 @@ def assert_ems
:api_version => nil,
:uid_ems => "a50f9983-d1a2-4a8d-be7d-123456789012"
)
expect(@ems.flavors.size).to eql(33)
expect(@ems.flavors.size).to eql(42)
expect(@ems.availability_zones.size).to eql(1)
expect(@ems.vms_and_templates.size).to eql(13)
expect(@ems.vms.size).to eql(9)
expect(@ems.vms_and_templates.size).to eql(17)
expect(@ems.vms.size).to eql(13)
expect(@ems.miq_templates.size).to eq(4)

expect(@ems.orchestration_stacks.size).to eql(7)
expect(@ems.direct_orchestration_stacks.size).to eql(6)
end

def assert_specific_flavor
@flavor = ManageIQ::Providers::Azure::CloudManager::Flavor.where(:name => "Standard_A0").first
@flavor = ManageIQ::Providers::Azure::CloudManager::Flavor.where(:name => "Basic_A0").first
expect(@flavor).to have_attributes(
:name => "Standard_A0",
:name => "Basic_A0",
:description => nil,
:enabled => true,
:cpus => 1,
Expand Down Expand Up @@ -199,7 +199,7 @@ def assert_specific_hardware_networks(v)
network = v.hardware.networks.where(:description => "public").first
expect(network).to have_attributes(
:description => "public",
:ipaddress => "40.76.199.78",
:ipaddress => "40.121.149.27",
:hostname => "ipconfig1"
)
network = v.hardware.networks.where(:description => "private").first
Expand Down Expand Up @@ -344,7 +344,7 @@ def assert_specific_template
def assert_specific_orchestration_template
@orch_template = OrchestrationTemplateAzure.where(:name => "spec-deployment1-dont-delete").first
expect(@orch_template).to have_attributes(
:md5 => "83c7f9914808a5ca7c000477a6daa7df"
:md5 => "b5711eee5c9e35a7108f19ff078b7ffa"
)
expect(@orch_template.description).to eql('contentVersion: 1.0.0.0')
expect(@orch_template.content).to start_with("{\n \"$schema\": \"http://schema.management.azure.com"\
Expand Down
Loading

0 comments on commit 43e3386

Please sign in to comment.