Skip to content

Commit

Permalink
Fix rest of API objects usage
Browse files Browse the repository at this point in the history
Change the rest of API to use objects.<Object> vs
objects.<module>.<Object>.

Partial-Blueprint: object-subclassing

Change-Id: I04db37c21547184f5aeb970e69547d6210be0c3e
  • Loading branch information
comstud committed Jun 28, 2014
1 parent 91449a8 commit 51cd3c7
Show file tree
Hide file tree
Showing 17 changed files with 52 additions and 67 deletions.
15 changes: 5 additions & 10 deletions nova/api/ec2/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
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
Expand Down Expand Up @@ -280,7 +276,7 @@ def _describe_availability_zones_verbose(self, context, **kwargs):
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 = {}
Expand Down Expand Up @@ -583,7 +579,7 @@ def _rule_dict_last_step(self, context, to_port=None, from_port=None,
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)
Expand Down Expand Up @@ -852,7 +848,7 @@ def create_volume(self, context, **kwargs):
kwargs.get('description'),
**create_kwargs)

vmap = ec2_obj.EC2VolumeMapping(context)
vmap = objects.EC2VolumeMapping(context)
vmap.uuid = volume['id']
vmap.create()

Expand Down Expand Up @@ -1332,9 +1328,8 @@ def run_instances(self, context, **kwargs):
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),
Expand Down
14 changes: 7 additions & 7 deletions nova/api/ec2/ec2utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand All @@ -315,18 +315,18 @@ 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


@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


Expand Down
3 changes: 1 addition & 2 deletions nova/api/metadata/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
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
Expand Down Expand Up @@ -136,7 +135,7 @@ def __init__(self, instance, address=None, content=None, extra_md=None,
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)
Expand Down
10 changes: 5 additions & 5 deletions nova/api/openstack/compute/contrib/flavor_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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 _


Expand Down Expand Up @@ -89,7 +89,7 @@ def index(self, req, flavor_id):
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)
Expand All @@ -113,7 +113,7 @@ def _check_body(self, body):
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
Expand Down Expand Up @@ -167,7 +167,7 @@ def _addTenantAccess(self, req, id, body):
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:
Expand All @@ -188,7 +188,7 @@ def _removeTenantAccess(self, req, id, body):
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def create(self, req, body):

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')
Expand Down
13 changes: 6 additions & 7 deletions nova/api/openstack/compute/contrib/server_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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

Expand Down Expand Up @@ -209,7 +208,7 @@ def show(self, req, id):
"""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)}
Expand All @@ -218,7 +217,7 @@ def delete(self, req, id):
"""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())
Expand All @@ -230,9 +229,9 @@ def index(self, req):
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)
Expand All @@ -251,13 +250,13 @@ def create(self, req, body):
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)

Expand Down
3 changes: 1 addition & 2 deletions nova/api/openstack/compute/contrib/simple_tenant_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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
Expand Down Expand Up @@ -129,7 +128,7 @@ def _get_flavor(self, context, instance, flavors_cache):
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
Expand Down
10 changes: 5 additions & 5 deletions nova/api/openstack/compute/plugins/v3/flavor_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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'
Expand Down Expand Up @@ -52,7 +52,7 @@ def index(self, req, flavor_id):
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())

Expand All @@ -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
Expand Down Expand Up @@ -115,7 +115,7 @@ def _add_tenant_access(self, req, id, body):
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:
Expand All @@ -136,7 +136,7 @@ def _remove_tenant_access(self, req, id, body):
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,
Expand Down
6 changes: 3 additions & 3 deletions nova/api/openstack/compute/plugins/v3/pci.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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


Expand Down Expand Up @@ -103,7 +103,7 @@ def _get_all_nodes_pci_devices(self, req, detail, action):
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])
Expand All @@ -119,7 +119,7 @@ def show(self, req, id):
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def create(self, req, body):

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')
Expand Down
10 changes: 4 additions & 6 deletions nova/tests/api/ec2/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@
from nova.network import neutronv2
from nova import objects
from nova.objects import base as obj_base
from nova.objects import instance_info_cache as instance_info_cache_obj
from nova.objects import security_group as security_group_obj
from nova.openstack.common import log as logging
from nova.openstack.common import policy as common_policy
from nova.openstack.common import timeutils
Expand Down Expand Up @@ -119,7 +117,7 @@ def get_instances_with_cached_ips(orig_func, get_floating,
instances = orig_func(*args, **kwargs)

if kwargs.get('want_objects', False):
info_cache = instance_info_cache_obj.InstanceInfoCache()
info_cache = objects.InstanceInfoCache()
info_cache.network_info = get_fake_cache(get_floating)
info_cache.obj_reset_changes()
else:
Expand Down Expand Up @@ -2661,11 +2659,11 @@ def fake_get(ctxt, instance_id, want_objects=False):
inst_type = flavors.get_default_flavor()
inst_type['name'] = 'fake_type'
sys_meta = flavors.save_flavor_info({}, inst_type)
secgroups = security_group_obj.SecurityGroupList()
secgroups = objects.SecurityGroupList()
secgroups.objects.append(
security_group_obj.SecurityGroup(name='fake0'))
objects.SecurityGroup(name='fake0'))
secgroups.objects.append(
security_group_obj.SecurityGroup(name='fake1'))
objects.SecurityGroup(name='fake1'))
instance = objects.Instance(ctxt)
instance.id = 0
instance.uuid = 'e5fe5518-0288-4fa3-b0c4-c79764101b85'
Expand Down
6 changes: 3 additions & 3 deletions nova/tests/api/openstack/compute/contrib/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from nova.api.openstack.compute.contrib import migrations
from nova import context
from nova import exception
from nova import objects
from nova.objects import base
from nova.objects import migration
from nova.openstack.common.fixture import moxstubout
from nova import test

Expand Down Expand Up @@ -61,8 +61,8 @@

migrations_obj = base.obj_make_list(
'fake-context',
migration.MigrationList(),
migration.Migration,
objects.MigrationList(),
objects.Migration,
fake_migrations)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import nova.db
from nova import exception
from nova import objects
from nova.objects import instance_group as instance_group_obj
from nova.openstack.common import uuidutils
from nova import test
from nova.tests.api.openstack import fakes
Expand Down Expand Up @@ -114,7 +113,7 @@ def _create_instance(self, context):
return instance

def _create_instance_group(self, context, members):
ig = instance_group_obj.InstanceGroup(name='fake_name',
ig = objects.InstanceGroup(name='fake_name',
user_id='fake_user', project_id='fake',
members=members)
ig.create(context)
Expand Down
Loading

0 comments on commit 51cd3c7

Please sign in to comment.