From f857e79cfa71f72cf2c7be0d342f87c4c5a92d89 Mon Sep 17 00:00:00 2001 From: Thomas Kadauke Date: Thu, 30 May 2013 17:37:46 +0200 Subject: [PATCH] Add API calls to manage flavor access across tenants --- lib/fog/openstack/compute.rb | 5 +++ .../requests/compute/add_flavor_access.rb | 31 +++++++++++++++++++ .../list_tenants_with_flavor_access.rb | 26 ++++++++++++++++ .../requests/compute/remove_flavor_access.rb | 31 +++++++++++++++++++ .../requests/compute/flavor_tests.rb | 12 +++++++ 5 files changed, 105 insertions(+) create mode 100644 lib/fog/openstack/requests/compute/add_flavor_access.rb create mode 100644 lib/fog/openstack/requests/compute/list_tenants_with_flavor_access.rb create mode 100644 lib/fog/openstack/requests/compute/remove_flavor_access.rb diff --git a/lib/fog/openstack/compute.rb b/lib/fog/openstack/compute.rb index c9df82620..1a9363bc7 100644 --- a/lib/fog/openstack/compute.rb +++ b/lib/fog/openstack/compute.rb @@ -93,6 +93,11 @@ module Fog request :create_flavor request :delete_flavor + # Flavor Access + request :add_flavor_access + request :remove_flavor_access + request :list_tenants_with_flavor_access + # Metadata request :list_metadata request :get_metadata diff --git a/lib/fog/openstack/requests/compute/add_flavor_access.rb b/lib/fog/openstack/requests/compute/add_flavor_access.rb new file mode 100644 index 000000000..f029fc1b2 --- /dev/null +++ b/lib/fog/openstack/requests/compute/add_flavor_access.rb @@ -0,0 +1,31 @@ +module Fog + module Compute + class OpenStack + class Real + def add_flavor_access(flavor_ref, tenant_id) + request( + :body => MultiJson.encode({ + "addTenantAccess" => { + "tenant" => tenant_id + } + }), + :expects => [200, 203], + :method => 'POST', + :path => "flavors/#{flavor_ref}/action.json" + ) + end + end + + class Mock + def add_flavor_access(flavor_ref, tenant_id) + response = Excon::Response.new + response.status = 200 + response.body = { + "flavor_access" => [{ "tenant_id" => tenant_id, "flavor_id" => flavor_ref }] + } + response + end + end + end + end +end diff --git a/lib/fog/openstack/requests/compute/list_tenants_with_flavor_access.rb b/lib/fog/openstack/requests/compute/list_tenants_with_flavor_access.rb new file mode 100644 index 000000000..99e0c3d53 --- /dev/null +++ b/lib/fog/openstack/requests/compute/list_tenants_with_flavor_access.rb @@ -0,0 +1,26 @@ +module Fog + module Compute + class OpenStack + class Real + def list_tenants_with_flavor_access(flavor_ref) + request( + :expects => [200, 203], + :method => 'GET', + :path => "flavors/#{flavor_ref}/os-flavor-access.json" + ) + end + end + + class Mock + def list_tenants_with_flavor_access(flavor_ref) + response = Excon::Response.new + response.status = 200 + response.body = { + "flavor_access" => [{ "tenant_id" => @tenant_id, "flavor_id" => flavor_ref }] + } + response + end + end + end + end +end diff --git a/lib/fog/openstack/requests/compute/remove_flavor_access.rb b/lib/fog/openstack/requests/compute/remove_flavor_access.rb new file mode 100644 index 000000000..b92b9dfb0 --- /dev/null +++ b/lib/fog/openstack/requests/compute/remove_flavor_access.rb @@ -0,0 +1,31 @@ +module Fog + module Compute + class OpenStack + class Real + def remove_flavor_access(flavor_ref, tenant_id) + request( + :body => MultiJson.encode({ + "removeTenantAccess" => { + "tenant" => tenant_id + } + }), + :expects => [200, 203], + :method => 'POST', + :path => "flavors/#{flavor_ref}/action.json" + ) + end + end + + class Mock + def remove_flavor_access(flavor_ref, tenant_id) + response = Excon::Response.new + response.status = 200 + response.body = { + "flavor_access" => [] + } + response + end + end + end + end +end diff --git a/tests/openstack/requests/compute/flavor_tests.rb b/tests/openstack/requests/compute/flavor_tests.rb index b60d2ecd4..e5bd6eb44 100644 --- a/tests/openstack/requests/compute/flavor_tests.rb +++ b/tests/openstack/requests/compute/flavor_tests.rb @@ -37,6 +37,18 @@ Shindo.tests('Fog::Compute[:openstack] | flavor requests', ['openstack']) do Fog::Compute[:openstack].delete_flavor('100') end + tests('add_flavor_access(flavor_ref, tenant_id)').formats({'flavor_access' => [{'tenant_id' => 1, 'flavor_id' => 1}]}) do + Fog::Compute[:openstack].add_flavor_access(1, 1).body + end + + tests('remove_flavor_access(flavor_ref, tenant_id)').formats({'flavor_access' => []}) do + Fog::Compute[:openstack].remove_flavor_access(1, 1).body + end + + tests('list_tenants_with_flavor_access(flavor_ref)').formats({'flavor_access' => [{'tenant_id' => nil, 'flavor_id' => 1}]}) do + Fog::Compute[:openstack].list_tenants_with_flavor_access(1).body + end + end tests('failure') do