52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
# Copyright 2013 Cloudscaling Group, Inc
|
|
#
|
|
# 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.
|
|
|
|
"""
|
|
SQLAlchemy models for ec2api data.
|
|
"""
|
|
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy import Column, Integer, PrimaryKeyConstraint, String, Text
|
|
from sqlalchemy import UniqueConstraint
|
|
|
|
from ec2api.openstack.common.db.sqlalchemy import models
|
|
|
|
BASE = declarative_base()
|
|
|
|
|
|
class EC2Base(models.ModelBase):
|
|
metadata = None
|
|
|
|
def save(self, session=None):
|
|
from ec2api.db.sqlalchemy import api
|
|
|
|
if session is None:
|
|
session = api.get_session()
|
|
|
|
super(EC2Base, self).save(session=session)
|
|
|
|
|
|
class Item(BASE, EC2Base):
|
|
__tablename__ = 'items'
|
|
__table_args__ = (
|
|
PrimaryKeyConstraint('id'),
|
|
UniqueConstraint('id', name='items_os_id_idx'),
|
|
)
|
|
id = Column(Integer, autoincrement=True)
|
|
project_id = Column(String(length=64))
|
|
vpc_id = Column(Integer)
|
|
kind = Column(String(length=20))
|
|
os_id = Column(String(length=36))
|
|
data = Column(Text())
|