diff --git a/app/models/cloud_volume.rb b/app/models/cloud_volume.rb index 5dfb587e540..a1bc30800ce 100644 --- a/app/models/cloud_volume.rb +++ b/app/models/cloud_volume.rb @@ -130,4 +130,7 @@ def raw_delete_volume raise NotImplementedError, _("raw_delete_volume must be implemented in a subclass") end + def available_vms + raise NotImplementedError, _("available_vms must be implemented in a subclass") + end end diff --git a/app/models/manageiq/providers/openstack/cloud_manager/cloud_volume.rb b/app/models/manageiq/providers/openstack/cloud_manager/cloud_volume.rb index c3d5b675de4..0b8c8c1fc42 100644 --- a/app/models/manageiq/providers/openstack/cloud_manager/cloud_volume.rb +++ b/app/models/manageiq/providers/openstack/cloud_manager/cloud_volume.rb @@ -120,6 +120,10 @@ def create_volume_snapshot_queue(userid, options) .create_snapshot_queue(userid, self, options) end + def available_vms + cloud_tenant.vms + end + def provider_object(connection) connection.volumes.get(ems_ref) end diff --git a/spec/models/manageiq/providers/openstack/cloud_manager/cloud_volume_spec.rb b/spec/models/manageiq/providers/openstack/cloud_manager/cloud_volume_spec.rb index e03da15c6ee..d0662be3365 100644 --- a/spec/models/manageiq/providers/openstack/cloud_manager/cloud_volume_spec.rb +++ b/spec/models/manageiq/providers/openstack/cloud_manager/cloud_volume_spec.rb @@ -135,4 +135,15 @@ end end end + + describe "instance linsting for attaching volumes" do + let(:first_instance) { FactoryGirl.create(:vm_openstack, :ext_management_system => ems, :ems_ref => "instance_0", :cloud_tenant => tenant) } + let(:second_instance) { FactoryGirl.create(:vm_openstack, :ext_management_system => ems, :ems_ref => "instance_1", :cloud_tenant => tenant) } + let(:other_tenant) { FactoryGirl.create(:cloud_tenant_openstack, :ext_management_system => ems) } + let(:other_instance) { FactoryGirl.create(:vm_openstack, :ext_management_system => ems, :ems_ref => "instance_2", :cloud_tenant => other_tenant) } + + it "supports attachment to only those instances that are in the same tenant" do + expect(cloud_volume.available_vms).to contain_exactly(first_instance, second_instance) + end + end end