-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from sandwichcloud/regionzone
add regions and zones
- Loading branch information
Showing
12 changed files
with
192 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
ingredients_db/alembic/versions/ba75fca08593_create_regions_and_zones.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"""create regions and zones | ||
Revision ID: ba75fca08593 | ||
Revises: 3ce1572cbc6b | ||
Create Date: 2017-11-04 09:08:59.648307 | ||
""" | ||
import sqlalchemy as sa | ||
import sqlalchemy_utils as sau | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
from ingredients_db.models.region import RegionState | ||
from ingredients_db.models.zones import ZoneState | ||
|
||
revision = 'ba75fca08593' | ||
down_revision = '3ce1572cbc6b' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.create_table( | ||
'regions', | ||
sa.Column('id', sau.UUIDType, server_default=sa.text("uuid_generate_v4()"), primary_key=True), | ||
sa.Column('name', sa.String, unique=True, nullable=False), | ||
sa.Column('datacenter', sa.String, unique=True, nullable=False), | ||
sa.Column('image_datastore', sa.String, nullable=False), | ||
sa.Column('image_folder', sa.String), | ||
sa.Column('schedulable', sa.Boolean, nullable=False), | ||
|
||
sa.Column('state', sa.Enum(RegionState), default=RegionState.CREATING, nullable=False), | ||
sa.Column('current_task_id', sau.UUIDType, sa.ForeignKey('tasks.id')), | ||
|
||
sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), | ||
nullable=False, index=True), | ||
sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), | ||
onupdate=sa.text('clock_timestamp()'), | ||
nullable=False), | ||
|
||
) | ||
|
||
op.create_table( | ||
'zones', | ||
sa.Column('id', sau.UUIDType, server_default=sa.text("uuid_generate_v4()"), primary_key=True), | ||
sa.Column('name', sa.String, unique=True, nullable=False), | ||
sa.Column('region_id', sau.UUIDType, sa.ForeignKey('regions.id', ondelete='RESTRICT'), nullable=False), | ||
sa.Column('vm_cluster', sa.String, nullable=False), | ||
sa.Column('vm_datastore', sa.String, nullable=False), | ||
sa.Column('vm_folder', sa.String), | ||
sa.Column('core_provision_percent', sa.Integer, nullable=False), | ||
sa.Column('ram_provision_percent', sa.Integer, nullable=False), | ||
sa.Column('schedulable', sa.Boolean, nullable=False), | ||
|
||
sa.Column('state', sa.Enum(ZoneState), default=ZoneState.CREATING, nullable=False), | ||
sa.Column('current_task_id', sau.UUIDType, sa.ForeignKey('tasks.id')), | ||
|
||
sa.Column('created_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), | ||
nullable=False, index=True), | ||
sa.Column('updated_at', sau.ArrowType(timezone=True), server_default=sa.text('clock_timestamp()'), | ||
onupdate=sa.text('clock_timestamp()'), | ||
nullable=False), | ||
|
||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_table('zones') | ||
op.drop_table('regions') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import enum | ||
|
||
from sqlalchemy import Column, text, String, Boolean, Enum, ForeignKey | ||
from sqlalchemy.ext.declarative import declared_attr | ||
from sqlalchemy_utils import generic_repr, UUIDType, ArrowType | ||
|
||
from ingredients_db.database import Base | ||
from ingredients_db.models.task import TaskMixin | ||
|
||
|
||
class RegionState(enum.Enum): | ||
CREATING = 'CREATING' | ||
CREATED = 'CREATED' | ||
DELETING = 'DELETING' | ||
DELETED = 'DELETED' | ||
ERROR = 'ERROR' | ||
|
||
|
||
@generic_repr | ||
class Region(Base, TaskMixin): | ||
__tablename__ = 'regions' | ||
|
||
id = Column(UUIDType, server_default=text("uuid_generate_v4()"), primary_key=True) | ||
name = Column(String, unique=True, nullable=False) | ||
datacenter = Column(String, unique=True, nullable=False) | ||
image_datastore = Column(String, nullable=False) | ||
image_folder = Column(String) | ||
schedulable = Column(Boolean, nullable=False) | ||
|
||
state = Column(Enum(RegionState), default=RegionState.CREATING, nullable=False) | ||
|
||
created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False, index=True) | ||
updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), | ||
onupdate=text('clock_timestamp()'), nullable=False) | ||
|
||
|
||
class RegionableNixin(object): | ||
@declared_attr | ||
def region_id(cls): | ||
return Column(UUIDType, ForeignKey('regions.id', ondelete='RESTRICT'), nullable=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import enum | ||
|
||
from sqlalchemy import Column, text, String, Boolean, ForeignKey, Integer, Enum | ||
from sqlalchemy.ext.declarative import declared_attr | ||
from sqlalchemy_utils import generic_repr, UUIDType, ArrowType | ||
|
||
from ingredients_db.database import Base | ||
from ingredients_db.models.region import RegionableNixin | ||
from ingredients_db.models.task import TaskMixin | ||
|
||
|
||
class ZoneState(enum.Enum): | ||
CREATING = 'CREATING' | ||
CREATED = 'CREATED' | ||
DELETING = 'DELETING' | ||
DELETED = 'DELETED' | ||
ERROR = 'ERROR' | ||
|
||
|
||
@generic_repr | ||
class Zone(Base, TaskMixin, RegionableNixin): | ||
__tablename__ = 'zones' | ||
|
||
id = Column(UUIDType, server_default=text("uuid_generate_v4()"), primary_key=True) | ||
name = Column(String, unique=True, nullable=False) | ||
vm_cluster = Column(String, nullable=False) | ||
vm_datastore = Column(String, nullable=False) | ||
vm_folder = Column(String) | ||
core_provision_percent = Column(Integer, nullable=False) | ||
ram_provision_percent = Column(Integer, nullable=False) | ||
schedulable = Column(Boolean, nullable=False) | ||
|
||
state = Column(Enum(ZoneState), default=ZoneState.CREATING, nullable=False) | ||
|
||
created_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), nullable=False, index=True) | ||
updated_at = Column(ArrowType(timezone=True), server_default=text('clock_timestamp()'), | ||
onupdate=text('clock_timestamp()'), nullable=False) | ||
|
||
|
||
class ZonableMixin(object): | ||
@declared_attr | ||
def zone_id(cls): | ||
return Column(UUIDType, ForeignKey('zones.id', ondelete='RESTRICT')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters