Merge "Adds support for admin to create flavors through mgmt API"
This commit is contained in:
@@ -21,6 +21,7 @@ from troveclient.instances import Instances # noqa
|
||||
from troveclient.hosts import Hosts # noqa
|
||||
from troveclient.management import Management # noqa
|
||||
from troveclient.management import RootHistory # noqa
|
||||
from troveclient.management import MgmtFlavors # noqa
|
||||
from troveclient.root import Root # noqa
|
||||
from troveclient.storage import StorageInfo # noqa
|
||||
from troveclient.users import Users # noqa
|
||||
|
||||
@@ -313,6 +313,7 @@ class Dbaas(object):
|
||||
from troveclient.security_groups import SecurityGroupRules
|
||||
from troveclient.storage import StorageInfo
|
||||
from troveclient.management import Management
|
||||
from troveclient.management import MgmtFlavors
|
||||
from troveclient.accounts import Accounts
|
||||
from troveclient.diagnostics import DiagnosticsInterrogator
|
||||
from troveclient.diagnostics import HwInfoInterrogator
|
||||
@@ -338,6 +339,7 @@ class Dbaas(object):
|
||||
self.security_group_rules = SecurityGroupRules(self)
|
||||
self.storage = StorageInfo(self)
|
||||
self.management = Management(self)
|
||||
self.mgmt_flavor = MgmtFlavors(self)
|
||||
self.accounts = Accounts(self)
|
||||
self.diagnostics = DiagnosticsInterrogator(self)
|
||||
self.hwinfo = HwInfoInterrogator(self)
|
||||
|
||||
@@ -20,6 +20,7 @@ from troveclient.common import check_for_exceptions
|
||||
from troveclient.common import limit_url
|
||||
from troveclient.common import Paginated
|
||||
from troveclient.instances import Instance
|
||||
from troveclient.flavors import Flavor
|
||||
|
||||
|
||||
class RootHistory(base.Resource):
|
||||
@@ -134,3 +135,41 @@ class Management(base.ManagerWithFind):
|
||||
"""
|
||||
body = {'reset-task-status': {}}
|
||||
self._action(instance_id, body)
|
||||
|
||||
|
||||
class MgmtFlavors(base.ManagerWithFind):
|
||||
"""
|
||||
Manage :class:`Flavor` resources.
|
||||
"""
|
||||
resource_class = Flavor
|
||||
|
||||
def __repr__(self):
|
||||
return "<Flavors Manager at %s>" % id(self)
|
||||
|
||||
def create(self, name, ram, disk, vcpus,
|
||||
flavorid="auto", ephemeral=None, swap=None, rxtx_factor=None,
|
||||
service_type=None):
|
||||
"""
|
||||
Create a new flavor.
|
||||
"""
|
||||
body = {"flavor": {
|
||||
"flavor_id": flavorid,
|
||||
"name": name,
|
||||
"ram": ram,
|
||||
"disk": disk,
|
||||
"vcpu": vcpus,
|
||||
"ephemeral": 0,
|
||||
"swap": 0,
|
||||
"rxtx_factor": "1.0",
|
||||
"is_public": "True"
|
||||
}}
|
||||
if ephemeral:
|
||||
body["flavor"]["ephemeral"] = ephemeral
|
||||
if swap:
|
||||
body["flavor"]["swap"] = swap
|
||||
if rxtx_factor:
|
||||
body["flavor"]["rxtx_factor"] = rxtx_factor
|
||||
if service_type:
|
||||
body["flavor"]["service_type"] = service_type
|
||||
|
||||
return self._create("/mgmt/flavors", body, "flavor")
|
||||
|
||||
@@ -182,6 +182,31 @@ class StorageCommands(common.AuthedCommandsBase):
|
||||
self._pretty_list(self.dbaas.storage.index)
|
||||
|
||||
|
||||
class FlavorsCommands(common.AuthedCommandsBase):
|
||||
"""Commands for managing Flavors"""
|
||||
|
||||
params = [
|
||||
'name',
|
||||
'ram',
|
||||
'disk',
|
||||
'vcpus',
|
||||
'flavor_id',
|
||||
'ephemeral',
|
||||
'swap',
|
||||
'rxtx_factor',
|
||||
'service_type'
|
||||
]
|
||||
|
||||
def create(self):
|
||||
"""Create a new flavor"""
|
||||
self._require('name', 'ram', 'disk', 'vcpus',
|
||||
'flavor_id', 'service_type')
|
||||
self._pretty_print(self.dbaas.mgmt_flavor.create, self.name,
|
||||
self.ram, self.disk, self.vcpus, self.flavor_id,
|
||||
self.ephemeral, self.swap, self.rxtx_factor,
|
||||
self.service_type)
|
||||
|
||||
|
||||
def config_options(oparser):
|
||||
oparser.add_option("-u", "--url", default="http://localhost:5000/v1.1",
|
||||
help="Auth API endpoint URL with port and version. \
|
||||
@@ -195,6 +220,7 @@ COMMANDS = {
|
||||
'root': RootCommands,
|
||||
'storage': StorageCommands,
|
||||
'quota': QuotaCommands,
|
||||
'flavor': FlavorsCommands,
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -142,3 +142,35 @@ class ManagementTest(TestCase):
|
||||
self.management.reset_task_status(1)
|
||||
self.assertEqual(1, self.management._action.call_count)
|
||||
self.assertEqual({'reset-task-status': {}}, self.body_)
|
||||
|
||||
|
||||
class MgmtFlavorsTest(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(MgmtFlavorsTest, self).setUp()
|
||||
self.orig__init = management.MgmtFlavors.__init__
|
||||
management.MgmtFlavors.__init__ = Mock(return_value=None)
|
||||
self.flavors = management.MgmtFlavors()
|
||||
self.flavors.api = Mock()
|
||||
self.flavors.api.client = Mock()
|
||||
self.flavors.resource_class = Mock(return_value="flavor-1")
|
||||
self.orig_base_getid = base.getid
|
||||
base.getid = Mock(return_value="flavor1")
|
||||
|
||||
def tearDown(self):
|
||||
super(MgmtFlavorsTest, self).tearDown()
|
||||
management.MgmtFlavors.__init__ = self.orig__init
|
||||
base.getid = self.orig_base_getid
|
||||
|
||||
def test_create(self):
|
||||
def side_effect_func(path, body, inst):
|
||||
return path, body, inst
|
||||
|
||||
self.flavors._create = Mock(side_effect=side_effect_func)
|
||||
p, b, i = self.flavors.create("test-name", 1024, 30, 2, 1)
|
||||
self.assertEqual("/mgmt/flavors", p)
|
||||
self.assertEqual("flavor", i)
|
||||
self.assertEqual("test-name", b["flavor"]["name"])
|
||||
self.assertEqual(1024, b["flavor"]["ram"])
|
||||
self.assertEqual(2, b["flavor"]["vcpu"])
|
||||
self.assertEqual(1, b["flavor"]["flavor_id"])
|
||||
|
||||
Reference in New Issue
Block a user