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

Create resource group association for instances and managed images #72

Merged
merged 1 commit into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ def parse_instance(instance)
# unified under the NetworkManager
hardware_network_info = get_hardware_network_info(instance)

rg_ems_ref = get_resource_group_ems_ref(instance)

new_result = {
:type => 'ManageIQ::Providers::Azure::CloudManager::Vm',
:uid_ems => uid,
Expand All @@ -241,6 +243,7 @@ def parse_instance(instance)
:location => instance.location,
:orchestration_stack => @data_index.fetch_path(:orchestration_stacks, @resource_to_stack[uid]),
:availability_zone => @data_index.fetch_path(:availability_zones, 'default'),
:resource_group => @data_index.fetch_path(:resource_groups, rg_ems_ref),
:hardware => {
:disks => [], # Filled in later conditionally on flavor
:networks => hardware_network_info
Expand Down Expand Up @@ -507,6 +510,7 @@ def parse_managed_image(image)
uid = image.id.downcase

os = image.properties.storage_profile.try(:os_disk).try(:os_type) || 'unknown'
rg_ems_ref = get_resource_group_ems_ref(image)

new_result = {
:type => ManageIQ::Providers::Azure::CloudManager::Template.name,
Expand All @@ -520,6 +524,7 @@ def parse_managed_image(image)
:template => true,
:publicly_available => false,
:operating_system => process_os(image),
:resource_group => @data_index.fetch_path(:resource_groups, rg_ems_ref),
:hardware => {
:bitness => 64,
:guest_os => OperatingSystem.normalize_os_name(os)
Expand Down Expand Up @@ -555,6 +560,7 @@ def parse_market_image(image)

def parse_image(image)
uid = image.uri

new_result = {
:type => ManageIQ::Providers::Azure::CloudManager::Template.name,
:uid_ems => uid,
Expand All @@ -571,6 +577,7 @@ def parse_image(image)
:guest_os => image.operating_system
}
}

return uid, new_result
end

Expand Down
5 changes: 0 additions & 5 deletions app/models/manageiq/providers/azure/cloud_manager/vm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ def provider_service(connection = nil)
::Azure::Armrest::VirtualMachineService.new(connection)
end

# The resource group is stored as part of the uid_ems. This splits it out.
def resource_group
uid_ems.split('\\')[1]
end

#
# Relationship methods
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def resource_groups
end
end

# Given an object, return the matching ems_ref for its resource group.
#
def get_resource_group_ems_ref(object)
"/subscriptions/#{object.subscription_id}/resourceGroups/#{object.resource_group.downcase}"
end

# TODO(lsmola) NetworkManager, move below methods under NetworkManager, once it is not needed in Cloudmanager
def get_vm_nics(instance)
nic_ids = instance.properties.network_profile.network_interfaces.collect(&:id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def setup_ems_and_cassette
assert_specific_load_balancer_health_checks
assert_specific_vm_with_managed_disk
assert_specific_managed_disk
assert_specific_resource_group
end
end

Expand Down Expand Up @@ -483,6 +484,17 @@ def assert_specific_managed_disk
expect(disk.size).to eql(1023.megabyte)
end

def assert_specific_resource_group
vm_managed = Vm.find_by(:name => @managed_vm)
vm_unmanaged = Vm.find_by(:name => @device_name)

managed_group = ResourceGroup.find_by(:name => 'miq-azure-test4')
unmanaged_group = ResourceGroup.find_by(:name => 'miq-azure-test1')

expect(vm_managed.resource_group).to eql(managed_group)
expect(vm_unmanaged.resource_group).to eql(unmanaged_group)
end

def assert_specific_vm_powered_off
vm_name = 'miqazure-centos1'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
let(:power_state_off) { "VM deallocated" }
let(:power_state_suspended) { "VM stopping" }

context "resource_group" do
it "defines a resource_group method that returns the expected value based on uid_ems" do
vm.uid_ems = "aaa\\bbb\\ccc\\ddd"
expect(vm).to respond_to(:resource_group)
expect(vm.resource_group).to eq("bbb")
end
end

context "#is_available?" do
context("with :start") do
let(:state) { :start }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
let(:virtual_machine_eastus) { Azure::Armrest::VirtualMachine.new(:name => "foo", :location => "eastus") }
let(:virtual_machine_southindia) { Azure::Armrest::VirtualMachine.new(:name => "bar", :location => "SouthIndia") }

context "get_resource_group_ems_ref" do
it "returns the expected value" do
virtual_machine_eastus.subscription_id = "abc123"
virtual_machine_eastus.resource_group = "Test_Group"

expected = "/subscriptions/abc123/resourceGroups/test_group"
expect(@ems_azure.get_resource_group_ems_ref(virtual_machine_eastus)).to eql(expected)
end
end

context "gather_data_for_region" do
it "requires a service name" do
expect { @ems_azure.gather_data_for_this_region }.to raise_error(ArgumentError)
Expand Down