Adds flavor access support for Nova V3 API
Adds the remaining flavors support for the Nova V3 API. Partially implements blueprint v3-api Change-Id: I46cdec8999f74af37a9ca4280d123907124bad39
This commit is contained in:
parent
9329f435bf
commit
72b1862c97
@ -105,3 +105,9 @@ class FakeHTTPClient(fakes_v1_1.FakeHTTPClient):
|
|||||||
]
|
]
|
||||||
|
|
||||||
return (200, {}, flavors)
|
return (200, {}, flavors)
|
||||||
|
|
||||||
|
#
|
||||||
|
# Flavor access
|
||||||
|
#
|
||||||
|
get_flavors_2_flavor_access = (
|
||||||
|
fakes_v1_1.FakeHTTPClient.get_flavors_2_os_flavor_access)
|
||||||
|
63
novaclient/tests/v3/test_flavor_access.py
Normal file
63
novaclient/tests/v3/test_flavor_access.py
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
# Copyright 2012 OpenStack Foundation
|
||||||
|
# Copyright 2013 IBM Corp.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
from novaclient.tests import utils
|
||||||
|
from novaclient.tests.v3 import fakes
|
||||||
|
from novaclient.v3 import flavor_access
|
||||||
|
|
||||||
|
|
||||||
|
cs = fakes.FakeClient()
|
||||||
|
|
||||||
|
|
||||||
|
class FlavorAccessTest(utils.TestCase):
|
||||||
|
|
||||||
|
def test_list_access_by_flavor_private(self):
|
||||||
|
kwargs = {'flavor': cs.flavors.get(2)}
|
||||||
|
r = cs.flavor_access.list(**kwargs)
|
||||||
|
cs.assert_called('GET', '/flavors/2/flavor-access')
|
||||||
|
for access_list in r:
|
||||||
|
self.assertTrue(isinstance(access_list,
|
||||||
|
flavor_access.FlavorAccess))
|
||||||
|
|
||||||
|
def test_add_tenant_access(self):
|
||||||
|
flavor = cs.flavors.get(2)
|
||||||
|
tenant = 'proj2'
|
||||||
|
r = cs.flavor_access.add_tenant_access(flavor, tenant)
|
||||||
|
|
||||||
|
body = {
|
||||||
|
"add_tenant_access": {
|
||||||
|
"tenant_id": "proj2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cs.assert_called('POST', '/flavors/2/action', body)
|
||||||
|
for a in r:
|
||||||
|
self.assertTrue(isinstance(a, flavor_access.FlavorAccess))
|
||||||
|
|
||||||
|
def test_remove_tenant_access(self):
|
||||||
|
flavor = cs.flavors.get(2)
|
||||||
|
tenant = 'proj2'
|
||||||
|
r = cs.flavor_access.remove_tenant_access(flavor, tenant)
|
||||||
|
|
||||||
|
body = {
|
||||||
|
"remove_tenant_access": {
|
||||||
|
"tenant_id": "proj2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cs.assert_called('POST', '/flavors/2/action', body)
|
||||||
|
for a in r:
|
||||||
|
self.assertTrue(isinstance(a, flavor_access.FlavorAccess))
|
@ -15,6 +15,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from novaclient import client
|
from novaclient import client
|
||||||
|
from novaclient.v3 import flavor_access
|
||||||
from novaclient.v3 import flavors
|
from novaclient.v3 import flavors
|
||||||
from novaclient.v3 import hosts
|
from novaclient.v3 import hosts
|
||||||
|
|
||||||
@ -53,6 +54,7 @@ class Client(object):
|
|||||||
#TODO(bnemec): Add back in v3 extensions
|
#TODO(bnemec): Add back in v3 extensions
|
||||||
self.hosts = hosts.HostManager(self)
|
self.hosts = hosts.HostManager(self)
|
||||||
self.flavors = flavors.FlavorManager(self)
|
self.flavors = flavors.FlavorManager(self)
|
||||||
|
self.flavor_access = flavor_access.FlavorAccessManager(self)
|
||||||
|
|
||||||
# Add in any extensions...
|
# Add in any extensions...
|
||||||
if extensions:
|
if extensions:
|
||||||
|
45
novaclient/v3/flavor_access.py
Normal file
45
novaclient/v3/flavor_access.py
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# Copyright 2012 OpenStack Foundation
|
||||||
|
# Copyright 2013 IBM Corp.
|
||||||
|
# All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
# not use this file except in compliance with the License. You may obtain
|
||||||
|
# a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
# License for the specific language governing permissions and limitations
|
||||||
|
# under the License.
|
||||||
|
|
||||||
|
"""Flavor access interface."""
|
||||||
|
|
||||||
|
from novaclient import base
|
||||||
|
from novaclient.v1_1 import flavor_access
|
||||||
|
|
||||||
|
|
||||||
|
class FlavorAccess(flavor_access.FlavorAccess):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class FlavorAccessManager(flavor_access.FlavorAccessManager):
|
||||||
|
"""
|
||||||
|
Manage :class:`FlavorAccess` resources.
|
||||||
|
"""
|
||||||
|
resource_class = FlavorAccess
|
||||||
|
|
||||||
|
def _list_by_flavor(self, flavor):
|
||||||
|
return self._list('/flavors/%s/flavor-access' % base.getid(flavor),
|
||||||
|
'flavor_access')
|
||||||
|
|
||||||
|
def add_tenant_access(self, flavor, tenant):
|
||||||
|
"""Add a tenant to the given flavor access list."""
|
||||||
|
info = {'tenant_id': tenant}
|
||||||
|
return self._action('add_tenant_access', flavor, info)
|
||||||
|
|
||||||
|
def remove_tenant_access(self, flavor, tenant):
|
||||||
|
"""Remove a tenant from the given flavor access list."""
|
||||||
|
info = {'tenant_id': tenant}
|
||||||
|
return self._action('remove_tenant_access', flavor, info)
|
Loading…
Reference in New Issue
Block a user