Skip to content

Commit

Permalink
Merge "Rename zones table to cells and Instance.zone_name to cell_name"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Feb 28, 2012
2 parents 8e9f7f0 + 78df211 commit f9d23c6
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 43 deletions.
30 changes: 15 additions & 15 deletions nova/db/api.py
Expand Up @@ -1448,29 +1448,29 @@ def instance_type_destroy(context, name):
####################


def zone_create(context, values):
"""Create a new child Zone entry."""
return IMPL.zone_create(context, values)
def cell_create(context, values):
"""Create a new child Cell entry."""
return IMPL.cell_create(context, values)


def zone_update(context, zone_id, values):
"""Update a child Zone entry."""
return IMPL.zone_update(context, zone_id, values)
def cell_update(context, cell_id, values):
"""Update a child Cell entry."""
return IMPL.cell_update(context, cell_id, values)


def zone_delete(context, zone_id):
"""Delete a child Zone."""
return IMPL.zone_delete(context, zone_id)
def cell_delete(context, cell_id):
"""Delete a child Cell."""
return IMPL.cell_delete(context, cell_id)


def zone_get(context, zone_id):
"""Get a specific child Zone."""
return IMPL.zone_get(context, zone_id)
def cell_get(context, cell_id):
"""Get a specific child Cell."""
return IMPL.cell_get(context, cell_id)


def zone_get_all(context):
"""Get all child Zones."""
return IMPL.zone_get_all(context)
def cell_get_all(context):
"""Get all child Cells."""
return IMPL.cell_get_all(context)


####################
Expand Down
40 changes: 20 additions & 20 deletions nova/db/sqlalchemy/api.py
Expand Up @@ -3539,47 +3539,47 @@ def instance_type_destroy(context, name):


@require_admin_context
def zone_create(context, values):
zone = models.Zone()
zone.update(values)
zone.save()
return zone
def cell_create(context, values):
cell = models.Cell()
cell.update(values)
cell.save()
return cell


def _zone_get_by_id_query(context, zone_id, session=None):
return model_query(context, models.Zone, session=session).\
filter_by(id=zone_id)
def _cell_get_by_id_query(context, cell_id, session=None):
return model_query(context, models.Cell, session=session).\
filter_by(id=cell_id)


@require_admin_context
def zone_update(context, zone_id, values):
zone = zone_get(context, zone_id)
zone.update(values)
zone.save()
return zone
def cell_update(context, cell_id, values):
cell = cell_get(context, cell_id)
cell.update(values)
cell.save()
return cell


@require_admin_context
def zone_delete(context, zone_id):
def cell_delete(context, cell_id):
session = get_session()
with session.begin():
_zone_get_by_id_query(context, zone_id, session=session).\
_cell_get_by_id_query(context, cell_id, session=session).\
delete()


@require_admin_context
def zone_get(context, zone_id):
result = _zone_get_by_id_query(context, zone_id).first()
def cell_get(context, cell_id):
result = _cell_get_by_id_query(context, cell_id).first()

if not result:
raise exception.ZoneNotFound(zone_id=zone_id)
raise exception.CellNotFound(cell_id=cell_id)

return result


@require_admin_context
def zone_get_all(context):
return model_query(context, models.Zone, read_deleted="no").all()
def cell_get_all(context):
return model_query(context, models.Cell, read_deleted="no").all()


####################
Expand Down
35 changes: 35 additions & 0 deletions nova/db/sqlalchemy/migrate_repo/versions/082_zone_to_cell.py
@@ -0,0 +1,35 @@
# Copyright 2012 OpenStack LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from sqlalchemy import MetaData, Table


def upgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
instances = Table('instances', meta, autoload=True)
zone_name = instances.c.zone_name
zone_name.alter(name='cell_name')
zones = Table('zones', meta, autoload=True)
zones.rename('cells')


def downgrade(migrate_engine):
meta = MetaData()
meta.bind = migrate_engine
instances = Table('instances', meta, autoload=True)
cell_name = instances.c.cell_name
cell_name.alter(name='zone_name')
cells = Table('cells', meta, autoload=True)
cells.rename('zones')
10 changes: 5 additions & 5 deletions nova/db/sqlalchemy/models.py
Expand Up @@ -278,8 +278,8 @@ def name(self):
# EC2 disable_api_termination
disable_terminate = Column(Boolean(), default=False, nullable=False)

# Openstack zone name
zone_name = Column(String(255))
# Openstack compute cell name
cell_name = Column(String(255))


class InstanceInfoCache(BASE, NovaBase):
Expand Down Expand Up @@ -870,9 +870,9 @@ class InstanceTypeExtraSpecs(BASE, NovaBase):
'InstanceTypeExtraSpecs.deleted == False)')


class Zone(BASE, NovaBase):
"""Represents a child zone of this zone."""
__tablename__ = 'zones'
class Cell(BASE, NovaBase):
"""Represents parent and child cells of this cell."""
__tablename__ = 'cells'
id = Column(Integer, primary_key=True)
name = Column(String(255))
api_url = Column(String(255))
Expand Down
6 changes: 3 additions & 3 deletions nova/exception.py
Expand Up @@ -748,8 +748,8 @@ class FlavorNotFound(NotFound):
message = _("Flavor %(flavor_id)s could not be found.")


class ZoneNotFound(NotFound):
message = _("Zone %(zone_id)s could not be found.")
class CellNotFound(NotFound):
message = _("Cell %(cell_id)s could not be found.")


class SchedulerHostFilterNotFound(NotFound):
Expand Down Expand Up @@ -1006,4 +1006,4 @@ class InstanceNotFound(NotFound):


class InvalidInstanceIDMalformed(Invalid):
message = _("Invalid id: %(val) (expecting \"i-...\").")
message = _("Invalid id: %(val) (expecting \"i-...\").")

0 comments on commit f9d23c6

Please sign in to comment.