Skip to content

Commit

Permalink
Merge pull request #16688 from d-m-u/bz_1518847
Browse files Browse the repository at this point in the history
Changes cloud network list to follow availability zone rules
  • Loading branch information
gmcculloug authored Jan 10, 2018
2 parents 30631c2 + 5fa2fce commit c11b14e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
28 changes: 20 additions & 8 deletions app/models/manageiq/providers/cloud_manager/provision_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ def allowed_availability_zones(_options = {})
targets.each_with_object({}) { |az, h| h[az.id] = az.name }
end

def allowed_cloud_networks(_options = {})
return {} unless (src_obj = provider_or_tenant_object)

src_obj.all_cloud_networks.each_with_object({}) do |cn, hash|
hash[cn.id] = cn.cidr.blank? ? cn.name : "#{cn.name} (#{cn.cidr})"
end
end

def allowed_cloud_subnets(_options = {})
src = resources_for_ui
return {} if src[:cloud_network_id].nil?
Expand All @@ -33,6 +25,12 @@ def allowed_cloud_subnets(_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_guest_access_key_pairs(_options = {})
source = load_ar_obj(get_source_vm)
targets = get_targets_for_ems(source, :cloud_filter, ManageIQ::Providers, 'key_pairs')
Expand Down Expand Up @@ -90,6 +88,20 @@ def allowed_ci(ci, relats, filtered_ids = nil)
super(ci, relats, sources, filtered_ids)
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 get_source_and_targets(refresh = false)
return @target_resource if @target_resource && refresh == false
result = super
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,18 @@
:ext_management_system => ems.network_manager)
end

context "#allowed_cloud_networks" do
it "without a zone", :skip_before do
expect(workflow.allowed_cloud_networks.length).to be_zero
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_cloud_subnets" do
it "without a cloud_network", :skip_before do
expect(workflow.allowed_cloud_subnets.length).to be_zero
Expand Down

0 comments on commit c11b14e

Please sign in to comment.