diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-06-30 21:07:32 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-06-30 21:07:32 +0000 |
commit | 948ca79ab6c494261a5f808a742bc09139e5e3d2 (patch) | |
tree | ab759aab27889d7c8b2cf0a56612cc3f8ebb4e19 /nova/api | |
parent | b5726f6c14cebedd807564b082ee46ff73d25be8 (diff) | |
parent | 51cd3c75a60be36eded8f2e2e049b2aaffa4a656 (diff) | |
download | nova-948ca79ab6c494261a5f808a742bc09139e5e3d2.tar.gz |
Merge "Fix rest of API objects usage"
Diffstat (limited to 'nova/api')
-rw-r--r-- | nova/api/ec2/cloud.py | 15 | ||||
-rw-r--r-- | nova/api/ec2/ec2utils.py | 14 | ||||
-rw-r--r-- | nova/api/metadata/base.py | 3 | ||||
-rw-r--r-- | nova/api/openstack/compute/contrib/flavor_access.py | 10 | ||||
-rw-r--r-- | nova/api/openstack/compute/contrib/server_external_events.py | 2 | ||||
-rw-r--r-- | nova/api/openstack/compute/contrib/server_groups.py | 13 | ||||
-rw-r--r-- | nova/api/openstack/compute/contrib/simple_tenant_usage.py | 3 | ||||
-rw-r--r-- | nova/api/openstack/compute/plugins/v3/flavor_access.py | 10 | ||||
-rw-r--r-- | nova/api/openstack/compute/plugins/v3/pci.py | 6 | ||||
-rw-r--r-- | nova/api/openstack/compute/plugins/v3/server_external_events.py | 2 |
10 files changed, 35 insertions, 43 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py index 1b22d280b0..478e51d28c 100644 --- a/nova/api/ec2/cloud.py +++ b/nova/api/ec2/cloud.py @@ -43,10 +43,6 @@ from nova import network from nova.network.security_group import neutron_driver from nova import objects from nova.objects import base as obj_base -from nova.objects import ec2 as ec2_obj -from nova.objects import flavor as flavor_obj -from nova.objects import security_group as sec_group_obj -from nova.objects import service as service_obj from nova.openstack.common.gettextutils import _ from nova.openstack.common import log as logging from nova.openstack.common import timeutils @@ -280,7 +276,7 @@ class CloudController(object): availability_zones.get_availability_zones(ctxt) # Available services - enabled_services = service_obj.ServiceList.get_all(context, + enabled_services = objects.ServiceList.get_all(context, disabled=False, set_zones=True) zone_hosts = {} host_services = {} @@ -583,7 +579,7 @@ class CloudController(object): source_project_id = self._get_source_project_id(context, source_security_group_owner_id) - source_security_group = sec_group_obj.SecurityGroup.get_by_name( + source_security_group = objects.SecurityGroup.get_by_name( context.elevated(), source_project_id, source_security_group_name) @@ -852,7 +848,7 @@ class CloudController(object): kwargs.get('description'), **create_kwargs) - vmap = ec2_obj.EC2VolumeMapping(context) + vmap = objects.EC2VolumeMapping(context) vmap.uuid = volume['id'] vmap.create() @@ -1332,9 +1328,8 @@ class CloudController(object): msg = _('Image must be available') raise exception.ImageNotActive(message=msg) - flavor = flavor_obj.Flavor.get_by_name(context, - kwargs.get('instance_type', - None)) + flavor = objects.Flavor.get_by_name(context, + kwargs.get('instance_type', None)) (instances, resv_id) = self.compute_api.create(context, instance_type=obj_base.obj_to_primitive(flavor), diff --git a/nova/api/ec2/ec2utils.py b/nova/api/ec2/ec2utils.py index 5259d5ab0e..97cbe5627a 100644 --- a/nova/api/ec2/ec2utils.py +++ b/nova/api/ec2/ec2utils.py @@ -22,8 +22,8 @@ from nova import context from nova import db from nova import exception from nova.network import model as network_model +from nova import objects from nova.objects import base as obj_base -from nova.objects import ec2 as ec2_obj from nova.openstack.common.gettextutils import _ from nova.openstack.common import log as logging from nova.openstack.common import memorycache @@ -202,7 +202,7 @@ def ec2_inst_id_to_uuid(context, ec2_id): @memoize def get_instance_uuid_from_int_id(context, int_id): - imap = ec2_obj.EC2InstanceMapping.get_by_id(context, int_id) + imap = objects.EC2InstanceMapping.get_by_id(context, int_id) return imap.uuid @@ -301,10 +301,10 @@ def get_int_id_from_instance_uuid(context, instance_uuid): if instance_uuid is None: return try: - imap = ec2_obj.EC2InstanceMapping.get_by_uuid(context, instance_uuid) + imap = objects.EC2InstanceMapping.get_by_uuid(context, instance_uuid) return imap.id except exception.NotFound: - imap = ec2_obj.EC2InstanceMapping(context) + imap = objects.EC2InstanceMapping(context) imap.uuid = instance_uuid imap.create() return imap.id @@ -315,10 +315,10 @@ def get_int_id_from_volume_uuid(context, volume_uuid): if volume_uuid is None: return try: - vmap = ec2_obj.EC2VolumeMapping.get_by_uuid(context, volume_uuid) + vmap = objects.EC2VolumeMapping.get_by_uuid(context, volume_uuid) return vmap.id except exception.NotFound: - vmap = ec2_obj.EC2VolumeMapping(context) + vmap = objects.EC2VolumeMapping(context) vmap.uuid = volume_uuid vmap.create() return vmap.id @@ -326,7 +326,7 @@ def get_int_id_from_volume_uuid(context, volume_uuid): @memoize def get_volume_uuid_from_int_id(context, int_id): - vmap = ec2_obj.EC2VolumeMapping.get_by_id(context, int_id) + vmap = objects.EC2VolumeMapping.get_by_id(context, int_id) return vmap.uuid diff --git a/nova/api/metadata/base.py b/nova/api/metadata/base.py index f8ff52020d..7d77807dba 100644 --- a/nova/api/metadata/base.py +++ b/nova/api/metadata/base.py @@ -32,7 +32,6 @@ from nova import context from nova import network from nova import objects from nova.objects import base as obj_base -from nova.objects import security_group as secgroup_obj from nova.openstack.common import importutils from nova.openstack.common import log as logging from nova.openstack.common import timeutils @@ -136,7 +135,7 @@ class InstanceMetadata(): self.availability_zone = ec2utils.get_availability_zone_by_host( instance['host'], capi) - self.security_groups = secgroup_obj.SecurityGroupList.get_by_instance( + self.security_groups = objects.SecurityGroupList.get_by_instance( ctxt, instance) self.mappings = _format_instance_mapping(ctxt, instance) diff --git a/nova/api/openstack/compute/contrib/flavor_access.py b/nova/api/openstack/compute/contrib/flavor_access.py index f9b06d3f14..ceafd662c1 100644 --- a/nova/api/openstack/compute/contrib/flavor_access.py +++ b/nova/api/openstack/compute/contrib/flavor_access.py @@ -21,7 +21,7 @@ from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import exception -from nova.objects import flavor as flavor_obj +from nova import objects from nova.openstack.common.gettextutils import _ @@ -89,7 +89,7 @@ class FlavorAccessController(object): authorize(context) try: - flavor = flavor_obj.Flavor.get_by_flavor_id(context, flavor_id) + flavor = objects.Flavor.get_by_flavor_id(context, flavor_id) except exception.FlavorNotFound: explanation = _("Flavor not found.") raise webob.exc.HTTPNotFound(explanation=explanation) @@ -113,7 +113,7 @@ class FlavorActionController(wsgi.Controller): def _get_flavor_refs(self, context): """Return a dictionary mapping flavorid to flavor_ref.""" - flavors = flavor_obj.FlavorList.get_all(context) + flavors = objects.FlavorList.get_all(context) rval = {} for flavor in flavors: rval[flavor.flavorid] = flavor @@ -167,7 +167,7 @@ class FlavorActionController(wsgi.Controller): vals = body['addTenantAccess'] tenant = vals['tenant'] - flavor = flavor_obj.Flavor(context=context, flavorid=id) + flavor = objects.Flavor(context=context, flavorid=id) try: flavor.add_access(tenant) except exception.FlavorAccessExists as err: @@ -188,7 +188,7 @@ class FlavorActionController(wsgi.Controller): vals = body['removeTenantAccess'] tenant = vals['tenant'] - flavor = flavor_obj.Flavor(context=context, flavorid=id) + flavor = objects.Flavor(context=context, flavorid=id) try: flavor.remove_access(tenant) except (exception.FlavorNotFound, diff --git a/nova/api/openstack/compute/contrib/server_external_events.py b/nova/api/openstack/compute/contrib/server_external_events.py index e530305cb0..97dd23b532 100644 --- a/nova/api/openstack/compute/contrib/server_external_events.py +++ b/nova/api/openstack/compute/contrib/server_external_events.py @@ -81,7 +81,7 @@ class ServerExternalEventsController(wsgi.Controller): for _event in body_events: client_event = dict(_event) - event = external_event_obj.InstanceExternalEvent() + event = objects.InstanceExternalEvent(context) try: event.instance_uuid = client_event.pop('server_uuid') diff --git a/nova/api/openstack/compute/contrib/server_groups.py b/nova/api/openstack/compute/contrib/server_groups.py index 29255a9756..0d10596ecd 100644 --- a/nova/api/openstack/compute/contrib/server_groups.py +++ b/nova/api/openstack/compute/contrib/server_groups.py @@ -24,7 +24,6 @@ from nova.api.openstack import wsgi from nova.api.openstack import xmlutil import nova.exception from nova import objects -from nova.objects import instance_group as instance_group_obj from nova.openstack.common.gettextutils import _ from nova import utils @@ -209,7 +208,7 @@ class ServerGroupController(wsgi.Controller): """Return data about the given server group.""" context = _authorize_context(req) try: - sg = instance_group_obj.InstanceGroup.get_by_uuid(context, id) + sg = objects.InstanceGroup.get_by_uuid(context, id) except nova.exception.InstanceGroupNotFound as e: raise webob.exc.HTTPNotFound(explanation=e.format_message()) return {'server_group': self._format_server_group(context, sg)} @@ -218,7 +217,7 @@ class ServerGroupController(wsgi.Controller): """Delete an server group.""" context = _authorize_context(req) try: - sg = instance_group_obj.InstanceGroup.get_by_uuid(context, id) + sg = objects.InstanceGroup.get_by_uuid(context, id) sg.destroy(context) except nova.exception.InstanceGroupNotFound as e: raise webob.exc.HTTPNotFound(explanation=e.format_message()) @@ -230,9 +229,9 @@ class ServerGroupController(wsgi.Controller): context = _authorize_context(req) project_id = context.project_id if 'all_projects' in req.GET and context.is_admin: - sgs = instance_group_obj.InstanceGroupList.get_all(context) + sgs = objects.InstanceGroupList.get_all(context) else: - sgs = instance_group_obj.InstanceGroupList.get_by_project_id( + sgs = objects.InstanceGroupList.get_by_project_id( context, project_id) limited_list = common.limited(sgs.objects, req) result = [self._format_server_group(context, group) @@ -251,13 +250,13 @@ class ServerGroupController(wsgi.Controller): raise exc.HTTPBadRequest(explanation=e.format_message()) vals = body['server_group'] - sg = instance_group_obj.InstanceGroup() + sg = objects.InstanceGroup(context) sg.project_id = context.project_id sg.user_id = context.user_id try: sg.name = vals.get('name') sg.policies = vals.get('policies') - sg.create(context) + sg.create() except ValueError as e: raise exc.HTTPBadRequest(explanation=e) diff --git a/nova/api/openstack/compute/contrib/simple_tenant_usage.py b/nova/api/openstack/compute/contrib/simple_tenant_usage.py index 11c6da8b3f..6b9c25cf9b 100644 --- a/nova/api/openstack/compute/contrib/simple_tenant_usage.py +++ b/nova/api/openstack/compute/contrib/simple_tenant_usage.py @@ -24,7 +24,6 @@ from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import exception from nova import objects -from nova.objects import flavor as flavor_obj from nova.objects import instance as instance_obj from nova.openstack.common.gettextutils import _ from nova.openstack.common import timeutils @@ -129,7 +128,7 @@ class SimpleTenantUsageController(object): return flavors_cache[flavor_type] try: - flavor_ref = flavor_obj.Flavor.get_by_id(context, flavor_type) + flavor_ref = objects.Flavor.get_by_id(context, flavor_type) flavors_cache[flavor_type] = flavor_ref except exception.FlavorNotFound: # can't bill if there is no flavor diff --git a/nova/api/openstack/compute/plugins/v3/flavor_access.py b/nova/api/openstack/compute/plugins/v3/flavor_access.py index bccb044e24..762f24f52e 100644 --- a/nova/api/openstack/compute/plugins/v3/flavor_access.py +++ b/nova/api/openstack/compute/plugins/v3/flavor_access.py @@ -22,7 +22,7 @@ from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova.api import validation from nova import exception -from nova.objects import flavor as flavor_obj +from nova import objects from nova.openstack.common.gettextutils import _ ALIAS = 'flavor-access' @@ -52,7 +52,7 @@ class FlavorAccessController(object): authorize(context) try: - flavor = flavor_obj.Flavor.get_by_flavor_id(context, flavor_id) + flavor = objects.Flavor.get_by_flavor_id(context, flavor_id) except exception.FlavorNotFound as e: raise webob.exc.HTTPNotFound(explanation=e.format_message()) @@ -70,7 +70,7 @@ class FlavorActionController(wsgi.Controller): def _get_flavor_refs(self, context): """Return a dictionary mapping flavorid to flavor_ref.""" - flavors = flavor_obj.FlavorList.get_all(context) + flavors = objects.FlavorList.get_all(context) rval = {} for flavor in flavors: rval[flavor.flavorid] = flavor @@ -115,7 +115,7 @@ class FlavorActionController(wsgi.Controller): vals = body['add_tenant_access'] tenant = vals['tenant_id'] - flavor = flavor_obj.Flavor(context=context, flavorid=id) + flavor = objects.Flavor(context=context, flavorid=id) try: flavor.add_access(tenant) except exception.FlavorNotFound as e: @@ -136,7 +136,7 @@ class FlavorActionController(wsgi.Controller): vals = body['remove_tenant_access'] tenant = vals['tenant_id'] - flavor = flavor_obj.Flavor(context=context, flavorid=id) + flavor = objects.Flavor(context=context, flavorid=id) try: flavor.remove_access(tenant) except (exception.FlavorAccessNotFound, diff --git a/nova/api/openstack/compute/plugins/v3/pci.py b/nova/api/openstack/compute/plugins/v3/pci.py index 58e486b8b2..fe32f29afe 100644 --- a/nova/api/openstack/compute/plugins/v3/pci.py +++ b/nova/api/openstack/compute/plugins/v3/pci.py @@ -20,7 +20,7 @@ from nova.api.openstack import extensions from nova.api.openstack import wsgi from nova import compute from nova import exception -from nova.objects import pci_device +from nova import objects from nova.openstack.common import jsonutils @@ -103,7 +103,7 @@ class PciController(object): compute_nodes = self.host_api.compute_node_get_all(context) results = [] for node in compute_nodes: - pci_devs = pci_device.PciDeviceList.get_by_compute_node( + pci_devs = objects.PciDeviceList.get_by_compute_node( context, node['id']) results.extend([self._view_pcidevice(dev, detail) for dev in pci_devs]) @@ -119,7 +119,7 @@ class PciController(object): context = req.environ['nova.context'] authorize(context, action='show') try: - pci_dev = pci_device.PciDevice.get_by_dev_id(context, id) + pci_dev = objects.PciDevice.get_by_dev_id(context, id) except exception.PciDeviceNotFoundById as e: raise webob.exc.HTTPNotFound(explanation=e.format_message()) result = self._view_pcidevice(pci_dev, True) diff --git a/nova/api/openstack/compute/plugins/v3/server_external_events.py b/nova/api/openstack/compute/plugins/v3/server_external_events.py index 30a71805c3..b3f848d145 100644 --- a/nova/api/openstack/compute/plugins/v3/server_external_events.py +++ b/nova/api/openstack/compute/plugins/v3/server_external_events.py @@ -54,7 +54,7 @@ class ServerExternalEventsController(wsgi.Controller): for _event in body_events: client_event = dict(_event) - event = external_event_obj.InstanceExternalEvent() + event = objects.InstanceExternalEvent(context) try: event.instance_uuid = client_event.pop('server_uuid') |