Converted a few more ec2 calls to use compute api.

This commit is contained in:
Eric Day
2010-12-29 21:41:42 -08:00
parent b1a08af498
commit 750a0c9b41
2 changed files with 13 additions and 12 deletions

View File

@@ -138,7 +138,7 @@ class CloudController(object):
def get_metadata(self, address):
ctxt = context.get_admin_context()
instance_ref = db.fixed_ip_get_instance(ctxt, address)
instance_ref = self.compute_api.get(ctxt, fixed_ip=address)
if instance_ref is None:
return None
mpi = self._get_mpi_data(ctxt, instance_ref['project_id'])
@@ -555,13 +555,9 @@ class CloudController(object):
assert len(i) == 1
return i[0]
def _format_instances(self, context, reservation_id=None):
def _format_instances(self, context, **kwargs):
reservations = {}
if reservation_id:
instances = db.instance_get_all_by_reservation(context,
reservation_id)
else:
instances = self.compute_api.get(context)
instances = self.compute_api.get(context, **kwargs)
for instance in instances:
if not context.user.is_admin():
if instance['image_id'] == FLAGS.vpn_image_id:
@@ -747,8 +743,7 @@ class CloudController(object):
changes[field] = kwargs[field]
if changes:
instance_id = ec2_id_to_id(ec2_id)
inst = self.compute_api.get(context, instance_id)
db.instance_update(context, inst['id'], kwargs)
self.compute_api.update(context, instance_id, **kwargs)
return True
def describe_images(self, context, image_id=None, **kwargs):

View File

@@ -243,12 +243,18 @@ class API(base.Base):
else:
self.db.instance_destroy(context, instance['id'])
def get(self, context, instance_id=None, project_id=None):
"""Get one or more instances, possibly filtered by project
ID or user ID. If there is no filter and the context is
def get(self, context, instance_id=None, project_id=None,
reservation_id=None, fixed_ip=None):
"""Get one or more instances, possibly filtered by one of the
given parameters. If there is no filter and the context is
an admin, it will retreive all instances in the system."""
if instance_id is not None:
return self.db.instance_get_by_id(context, instance_id)
if reservation_id is not None:
return self.db.instance_get_all_by_reservation(context,
reservation_id)
if fixed_ip is not None:
return self.db.fixed_ip_get_instance(context, fixed_ip)
if project_id or not context.is_admin:
if not context.project:
return self.db.instance_get_all_by_user(context,