Merge "Enhance nova-manage to set flavor extra specs"

This commit is contained in:
Jenkins
2012-07-26 22:14:12 +00:00
committed by Gerrit Code Review

View File

@@ -910,10 +910,10 @@ class InstanceTypeCommands(object):
def _print_instance_types(self, name, val):
deleted = ('', ', inactive')[val["deleted"] == 1]
print ("%s: Memory: %sMB, VCPUS: %s, Root: %sGB, Ephemeral: %sGb, "
"FlavorID: %s, Swap: %sMB, RXTX Factor: %s") % (
"FlavorID: %s, Swap: %sMB, RXTX Factor: %s, ExtraSpecs %s") % (
name, val["memory_mb"], val["vcpus"], val["root_gb"],
val["ephemeral_gb"], val["flavorid"], val["swap"],
val["rxtx_factor"])
val["rxtx_factor"], val["extra_specs"])
@args('--name', dest='name', metavar='<name>',
help='Name of instance type/flavor')
@@ -986,6 +986,51 @@ class InstanceTypeCommands(object):
else:
self._print_instance_types(name, inst_types)
@args('--name', dest='name', metavar='<name>',
help='Name of instance type/flavor')
@args('--key', dest='key', metavar='<key>',
help='The key of the key/value pair')
@args('--value', dest='value', metavar='<value>',
help='The value of the key/value pair')
def set_key(self, name, key, value=None):
"""Add key/value pair to specified instance type's extra_specs"""
try:
try:
inst_type = instance_types.get_instance_type_by_name(name)
except exception.InstanceTypeNotFoundByName, e:
print e
sys.exit(2)
ctxt = context.get_admin_context()
ext_spec = {key: value}
db.instance_type_extra_specs_update_or_create(ctxt,
inst_type["id"],
ext_spec)
print _("Key %(key)s set to %(value)s on instance"
" type %(name)s") % locals()
except exception.DBError, e:
_db_error(e)
@args('--name', dest='name', metavar='<name>',
help='Name of instance type/flavor')
@args('--key', dest='key', metavar='<key>',
help='The key to be deleted')
def unset_key(self, name, key):
"""Delete the specified extra spec for instance type"""
try:
try:
inst_type = instance_types.get_instance_type_by_name(name)
except exception.InstanceTypeNotFoundByName, e:
print e
sys.exit(2)
ctxt = context.get_admin_context()
db.instance_type_extra_specs_delete(ctxt, inst_type["id"], key)
print _("Key %(key)s on instance type %(name)s unset") % locals()
except exception.DBError, e:
_db_error(e)
class StorageManagerCommands(object):
"""Class for mangaging Storage Backends and Flavors"""