summaryrefslogtreecommitdiffstats
path: root/nova/compute
diff options
context:
space:
mode:
authorKen Pepple <ken.pepple@gmail.com>2011-04-07 15:09:48 -0700
committerKen Pepple <ken.pepple@gmail.com>2011-04-07 15:09:48 -0700
commit3c67f142e5587641e45fcf05d98fddffa0d67d9f (patch)
treeb4e27f3643da04294f8cbbff19a175a870e59965 /nova/compute
parent59b460e98c5b8f718a654539c5788e8775126dfd (diff)
parent9616fba3e13567b1e84d951857eaf0463161fdbe (diff)
merged trunk and resolved conflict
Diffstat (limited to 'nova/compute')
-rw-r--r--nova/compute/api.py24
-rw-r--r--nova/compute/instance_types.py60
2 files changed, 46 insertions, 38 deletions
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 1dbd73f8f..83ad6b0c9 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -37,10 +37,14 @@ from nova.compute import instance_types
from nova.scheduler import api as scheduler_api
from nova.db import base
-FLAGS = flags.FLAGS
+
LOG = logging.getLogger('nova.compute.api')
+FLAGS = flags.FLAGS
+flags.DECLARE('vncproxy_topic', 'nova.vnc')
+
+
def generate_default_hostname(instance_id):
"""Default function to generate a hostname given an instance reference."""
return str(instance_id)
@@ -110,8 +114,11 @@ class API(base.Base):
"""Create the number of instances requested if quota and
other arguments check out ok."""
- type_data = instance_types.get_instance_type(instance_type)
- num_instances = quota.allowed_instances(context, max_count, type_data)
+ if not instance_type:
+ instance_type = instance_types.get_default_instance_type()
+
+ num_instances = quota.allowed_instances(context, max_count,
+ instance_type)
if num_instances < min_count:
pid = context.project_id
LOG.warn(_("Quota exceeeded for %(pid)s,"
@@ -197,10 +204,10 @@ class API(base.Base):
'user_id': context.user_id,
'project_id': context.project_id,
'launch_time': time.strftime('%Y-%m-%dT%H:%M:%SZ', time.gmtime()),
- 'instance_type': instance_type,
- 'memory_mb': type_data['memory_mb'],
- 'vcpus': type_data['vcpus'],
- 'local_gb': type_data['local_gb'],
+ 'instance_type_id': instance_type['id'],
+ 'memory_mb': instance_type['memory_mb'],
+ 'vcpus': instance_type['vcpus'],
+ 'local_gb': instance_type['local_gb'],
'display_name': display_name,
'display_description': display_description,
'user_data': user_data or '',
@@ -517,8 +524,7 @@ class API(base.Base):
def resize(self, context, instance_id, flavor_id):
"""Resize a running instance."""
instance = self.db.instance_get(context, instance_id)
- current_instance_type = self.db.instance_type_get_by_name(
- context, instance['instance_type'])
+ current_instance_type = instance['instance_type']
new_instance_type = self.db.instance_type_get_by_flavor_id(
context, flavor_id)
diff --git a/nova/compute/instance_types.py b/nova/compute/instance_types.py
index bfa120675..70b43540f 100644
--- a/nova/compute/instance_types.py
+++ b/nova/compute/instance_types.py
@@ -74,8 +74,8 @@ def destroy(name):
try:
db.instance_type_destroy(context.get_admin_context(), name)
except exception.NotFound:
- LOG.exception(_('Instance type %s not found for deletion' % name))
- raise exception.ApiError(_("Unknown instance type: %s" % name))
+ LOG.exception(_('Instance type %s not found for deletion') % name)
+ raise exception.ApiError(_("Unknown instance type: %s") % name)
def purge(name):
@@ -87,8 +87,8 @@ def purge(name):
try:
db.instance_type_purge(context.get_admin_context(), name)
except exception.NotFound:
- LOG.exception(_('Instance type %s not found for purge' % name))
- raise exception.ApiError(_("Unknown instance type: %s" % name))
+ LOG.exception(_('Instance type %s not found for purge') % name)
+ raise exception.ApiError(_("Unknown instance type: %s") % name)
def get_all_types(inactive=0):
@@ -103,41 +103,43 @@ def get_all_flavors():
return get_all_types(context.get_admin_context())
-def get_instance_type(name):
- """Retrieves single instance type by name"""
- if name is None:
- return FLAGS.default_instance_type
+def get_default_instance_type():
+ name = FLAGS.default_instance_type
try:
- ctxt = context.get_admin_context()
- inst_type = db.instance_type_get_by_name(ctxt, name)
- return inst_type
+ return get_instance_type_by_name(name)
except exception.DBError:
- raise exception.ApiError(_("Unknown instance type: %s" % name))
+ raise exception.ApiError(_("Unknown instance type: %s") % name)
+
+def get_instance_type(id):
+ """Retrieves single instance type by id"""
+ if id is None:
+ return get_default_instance_type()
+ try:
+ ctxt = context.get_admin_context()
+ return db.instance_type_get_by_id(ctxt, id)
+ except exception.DBError:
+ raise exception.ApiError(_("Unknown instance type: %s") % name)
-def get_by_type(instance_type):
- """retrieve instance type name"""
- if instance_type is None:
- return FLAGS.default_instance_type
+def get_instance_type_by_name(name):
+ """Retrieves single instance type by name"""
+ if name is None:
+ return get_default_instance_type()
try:
ctxt = context.get_admin_context()
- inst_type = db.instance_type_get_by_name(ctxt, instance_type)
- return inst_type['name']
- except exception.DBError, e:
- LOG.exception(_('DB error: %s' % e))
- raise exception.ApiError(_("Unknown instance type: %s" %\
- instance_type))
+ return db.instance_type_get_by_name(ctxt, name)
+ except exception.DBError:
+ raise exception.ApiError(_("Unknown instance type: %s") % name)
-def get_by_flavor_id(flavor_id):
- """retrieve instance type's name by flavor_id"""
+def get_instance_type_by_flavor_id(flavor_id):
+ """retrieve instance type by flavor_id"""
if flavor_id is None:
- return FLAGS.default_instance_type
+ return get_default_instance_type()
try:
ctxt = context.get_admin_context()
- flavor = db.instance_type_get_by_flavor_id(ctxt, flavor_id)
- return flavor['name']
+ return db.instance_type_get_by_flavor_id(ctxt, flavor_id)
except exception.DBError, e:
- LOG.exception(_('DB error: %s' % e))
- raise exception.ApiError(_("Unknown flavor: %s" % flavor_id))
+ LOG.exception(_('DB error: %s') % e)
+ raise exception.ApiError(_("Unknown flavor: %s") % flavor_id)