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

Changes allowed cloud network to be updated by zone #391

Closed
wants to merge 1 commit into from
Closed
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 @@ -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