Skip to content

Commit

Permalink
Allow cloud volume to provide a list of volumes for attach
Browse files Browse the repository at this point in the history
While opening the view to attach a selected volume to a new instance,
the UI will currently ask for the VMs that are available in the cloud
tenant of the chosen volume. While it works for OpenStack, Amazon has no
notion of tenants currently.

Instead of relying on the tenant's VMs, this patch proposes a new method
in the cloud volume allowing it to specify the list of VMs this volume
can be attached to. In case of OpenStack, this will be delagated to
`cloud_tenant` and on Amazon it will be delagated to `availability_zone`
(because the volume has to reside in the same AZ).

A simple spec test is provided to validate the `available_vms` only
return the list of VMs in the same cloud tenant.

Signed-off-by: Gregor Berginc <gregor.berginc@xlab.si>
  • Loading branch information
gberginc committed Feb 23, 2017
1 parent 51c1c07 commit aa343b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/models/cloud_volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit aa343b2

Please sign in to comment.