summaryrefslogtreecommitdiff
path: root/troveclient/v1
diff options
context:
space:
mode:
Diffstat (limited to 'troveclient/v1')
-rw-r--r--troveclient/v1/client.py2
-rw-r--r--troveclient/v1/flavors.py58
-rw-r--r--troveclient/v1/management.py39
-rw-r--r--troveclient/v1/shell.py56
4 files changed, 150 insertions, 5 deletions
diff --git a/troveclient/v1/client.py b/troveclient/v1/client.py
index 88a7257..c34915f 100644
--- a/troveclient/v1/client.py
+++ b/troveclient/v1/client.py
@@ -21,6 +21,7 @@ from troveclient.v1 import clusters
from troveclient.v1 import configurations
from troveclient.v1 import databases
from troveclient.v1 import datastores
+from troveclient.v1 import flavors
from troveclient.v1 import instances
from troveclient.v1 import limits
from troveclient.v1 import management
@@ -64,6 +65,7 @@ class Client(object):
# self.limits = limits.LimitsManager(self)
# extensions
+ self.flavors = flavors.Flavors(self)
self.volume_types = volume_types.VolumeTypes(self)
self.users = users.Users(self)
self.databases = databases.Databases(self)
diff --git a/troveclient/v1/flavors.py b/troveclient/v1/flavors.py
new file mode 100644
index 0000000..7b1d72f
--- /dev/null
+++ b/troveclient/v1/flavors.py
@@ -0,0 +1,58 @@
+# Copyright 2011 OpenStack Foundation
+# Copyright 2013 Rackspace Hosting
+# 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 troveclient import base
+
+
+class Flavor(base.Resource):
+ """A Flavor is an Instance type, specifying other things, like RAM size."""
+
+ def __init__(self, manager, info, loaded=False):
+ super(Flavor, self).__init__(manager, info, loaded)
+ if self.id is None and self.str_id is not None:
+ self.id = self.str_id
+
+ def __repr__(self):
+ return "<Flavor: %s>" % self.name
+
+
+class Flavors(base.ManagerWithFind):
+ """Manage :class:`Flavor` resources."""
+ resource_class = Flavor
+
+ def list(self):
+ """Get a list of all flavors.
+ :rtype: list of :class:`Flavor`.
+ """
+ return self._list("/flavors", "flavors")
+
+ def list_datastore_version_associated_flavors(self, datastore,
+ version_id):
+ """Get a list of all flavors for the specified datastore type
+ and datastore version .
+ :rtype: list of :class:`Flavor`.
+ """
+ return self._list("/datastores/%s/versions/%s/flavors" %
+ (datastore, version_id),
+ "flavors")
+
+ def get(self, flavor):
+ """Get a specific flavor.
+
+ :rtype: :class:`Flavor`
+ """
+ return self._get("/flavors/%s" % base.getid(flavor),
+ "flavor")
diff --git a/troveclient/v1/management.py b/troveclient/v1/management.py
index 38923ad..478d086 100644
--- a/troveclient/v1/management.py
+++ b/troveclient/v1/management.py
@@ -21,6 +21,7 @@ from troveclient import common
from troveclient.v1 import clusters
from troveclient.v1 import configurations
from troveclient.v1 import datastores
+from troveclient.v1 import flavors
from troveclient.v1 import instances
@@ -149,6 +150,44 @@ class MgmtClusters(base.ManagerWithFind):
self._action(cluster_id, body)
+class MgmtFlavors(base.ManagerWithFind):
+ """Manage :class:`Flavor` resources."""
+ resource_class = flavors.Flavor
+
+ def __repr__(self):
+ return "<Flavors Manager at %s>" % id(self)
+
+ # Appease the abc gods
+ def list(self):
+ pass
+
+ 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")
+
+
class MgmtConfigurationParameters(configurations.ConfigurationParameters):
def create(self, version, name, restart_required, data_type,
max_size=None, min_size=None):
diff --git a/troveclient/v1/shell.py b/troveclient/v1/shell.py
index d7e81db..4c6ffd7 100644
--- a/troveclient/v1/shell.py
+++ b/troveclient/v1/shell.py
@@ -187,6 +187,11 @@ def _find_cluster(cs, cluster):
return utils.find_resource(cs.clusters, cluster)
+def _find_flavor(cs, flavor):
+ """Get a flavor by ID."""
+ return utils.find_resource(cs.flavors, flavor)
+
+
def _find_volume_type(cs, volume_type):
"""Get a volume type by ID."""
return utils.find_resource(cs.volume_types, volume_type)
@@ -217,6 +222,46 @@ def _find_configuration(cs, configuration):
return utils.find_resource(cs.configurations, configuration)
+# Flavor related calls
+@utils.arg('--datastore_type', metavar='<datastore_type>',
+ default=None,
+ help=_('Type of the datastore. For eg: mysql.'))
+@utils.arg("--datastore_version_id", metavar="<datastore_version_id>",
+ default=None, help=_("ID of the datastore version."))
+@utils.service_type('database')
+def do_flavor_list(cs, args):
+ """Lists available flavors."""
+ if args.datastore_type and args.datastore_version_id:
+ flavors = cs.flavors.list_datastore_version_associated_flavors(
+ args.datastore_type, args.datastore_version_id)
+ elif not args.datastore_type and not args.datastore_version_id:
+ flavors = cs.flavors.list()
+ else:
+ raise exceptions.MissingArgs(['datastore_type',
+ 'datastore_version_id'])
+
+ # Fallback to str_id where necessary.
+ _flavors = []
+ for f in flavors:
+ if not f.id and hasattr(f, 'str_id'):
+ f.id = f.str_id
+ _flavors.append(f)
+
+ utils.print_list(_flavors, ['id', 'name', 'ram', 'vcpus', 'disk',
+ 'ephemeral'],
+ labels={'ram': 'RAM', 'vcpus': 'vCPUs', 'disk': 'Disk'},
+ order_by='ram')
+
+
+@utils.arg('flavor', metavar='<flavor>', type=str,
+ help=_('ID or name of the flavor.'))
+@utils.service_type('database')
+def do_flavor_show(cs, args):
+ """Shows details of a flavor."""
+ flavor = _find_flavor(cs, args.flavor)
+ _print_object(flavor)
+
+
# Volume type related calls
@utils.arg('--datastore_type', metavar='<datastore_type>',
default=None,
@@ -508,7 +553,7 @@ def do_update(cs, args):
@utils.arg('flavor',
metavar='<flavor>',
type=str,
- help=_('A flavor ID.'))
+ help=_('A flavor name or ID.'))
@utils.arg('--databases', metavar='<database>',
help=_('Optional list of databases.'),
nargs="+", default=[])
@@ -576,7 +621,7 @@ def do_update(cs, args):
@utils.service_type('database')
def do_create(cs, args):
"""Creates a new instance."""
- flavor_id = args.flavor
+ flavor_id = _find_flavor(cs, args.flavor).id
volume = None
if args.size is not None and args.size <= 0:
raise exceptions.ValidationError(
@@ -639,7 +684,8 @@ def _validate_nic_info(nic_info, nic_str):
def _get_flavor(cs, opts_str):
- flavor_id, opts_str = _strip_option(opts_str, 'flavor', True)
+ flavor_name, opts_str = _strip_option(opts_str, 'flavor', True)
+ flavor_id = _find_flavor(cs, flavor_name).id
return str(flavor_id), opts_str
@@ -881,12 +927,12 @@ def do_cluster_create(cs, args):
@utils.arg('flavor',
metavar='<flavor>',
type=str,
- help=_('New flavor ID for the instance.'))
+ help=_('New flavor of the instance.'))
@utils.service_type('database')
def do_resize_instance(cs, args):
"""Resizes an instance with a new flavor."""
instance = _find_instance(cs, args.instance)
- flavor_id = args.flavor
+ flavor_id = _find_flavor(cs, args.flavor).id
cs.instances.resize_instance(instance, flavor_id)