diff --git a/app/models/manageiq/providers/cloud_manager/provision_workflow.rb b/app/models/manageiq/providers/cloud_manager/provision_workflow.rb index 0821296f42a..c28c751d4bd 100644 --- a/app/models/manageiq/providers/cloud_manager/provision_workflow.rb +++ b/app/models/manageiq/providers/cloud_manager/provision_workflow.rb @@ -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? @@ -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') @@ -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 diff --git a/spec/models/manageiq/providers/cloud_manager/provision_workflow_spec.rb b/spec/models/manageiq/providers/cloud_manager/provision_workflow_spec.rb index 5f5bd9ec2e5..441d7d6793a 100644 --- a/spec/models/manageiq/providers/cloud_manager/provision_workflow_spec.rb +++ b/spec/models/manageiq/providers/cloud_manager/provision_workflow_spec.rb @@ -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