Skip to content

Commit

Permalink
Puts this method where I really think it should be!
Browse files Browse the repository at this point in the history
  • Loading branch information
d-m-u committed Jan 11, 2018
1 parent 29992d8 commit 4097620
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def allowed_floating_ip_addresses(_options = {})
end
end

def allowed_cloud_networks(_options = {})
source = load_ar_obj(get_source_vm)
targets = get_targets_for_source(source, :cloud_filter, CloudNetwork, 'cloud_network_id')
allowed_ci(:cloud_network, [:availability_zone], targets.map(&:id))
end

def allowed_availability_zones(_options = {})
source = load_ar_obj(get_source_vm)
targets = get_targets_for_ems(source, :cloud_filter, AvailabilityZone, 'availability_zones.available')
Expand All @@ -57,6 +63,20 @@ def self.provider_model
ManageIQ::Providers::Amazon::CloudManager
end

def availability_zone_to_cloud_network(src)
if src[:availability_zone]
load_ar_obj(src[:availability_zone]).cloud_subnets.each_with_object({}) do |cs, hash|
cn = cs.cloud_network
hash[cn.id] = cn.name
end
else
return {} unless load_ar_obj(src[:ems]).cloud_subnets
load_ar_obj(src[:ems]).cloud_subnets.collect(&:cloud_network).each_with_object({}) do |cn, hash|
hash[cn.id] = cn.name
end
end
end

def security_group_to_availability_zones(src)
return nil unless src[:cloud_network]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
@az3 = FactoryGirl.create(:availability_zone_amazon, :ext_management_system => ems)

@cn1 = FactoryGirl.create(:cloud_network, :ext_management_system => ems.network_manager)
@cn2 = FactoryGirl.create(:cloud_network, :ext_management_system => ems.network_manager)

@cs1 = FactoryGirl.create(:cloud_subnet, :cloud_network => @cn1,
:availability_zone => @az1,
Expand All @@ -216,11 +217,23 @@
@sg1 = FactoryGirl.create(:security_group_amazon, :name => "sgn_1",
:ext_management_system => ems.network_manager,
:cloud_network => @cn1)
@cs3 = FactoryGirl.create(:cloud_subnet, :cloud_network => @cn2,
:availability_zone => @az2,
:ext_management_system => ems.network_manager)

@sg2 = FactoryGirl.create(:security_group_amazon, :name => "sgn_2", :ext_management_system => ems.network_manager)
end

it "#allowed_cloud_networks" do
expect(workflow.allowed_cloud_networks.length).to eq(1)
context "#allowed_cloud_networks" do
it "without a zone" do
expect(workflow.allowed_cloud_networks.length).to eq(2)
end

it "with a zone" do
workflow.values[:placement_availability_zone] = [@az1.id, @az1.name]
expect(workflow.allowed_cloud_networks.length).to eq(1)
expect(workflow.allowed_cloud_networks).to eq(@cn1.id => @cn1.name)
end
end

context "#allowed_availability_zones" do
Expand Down

0 comments on commit 4097620

Please sign in to comment.