90
90
setattr(self, k, v)
92
92
def iteritems(self):
93
"""Make the model object behave like a dict"""
97
# TODO(vish): Store images in the database instead of file system
98
#class Image(BASE, NovaBase):
99
# """Represents an image in the datastore"""
100
# __tablename__ = 'images'
101
# id = Column(Integer, primary_key=True)
102
# ec2_id = Column(String(12), unique=True)
103
# user_id = Column(String(255))
104
# project_id = Column(String(255))
105
# image_type = Column(String(255))
106
# public = Column(Boolean, default=False)
107
# state = Column(String(255))
108
# location = Column(String(255))
109
# arch = Column(String(255))
110
# default_kernel_id = Column(String(255))
111
# default_ramdisk_id = Column(String(255))
113
# @validates('image_type')
114
# def validate_image_type(self, key, image_type):
115
# assert(image_type in ['machine', 'kernel', 'ramdisk', 'raw'])
117
# @validates('state')
118
# def validate_state(self, key, state):
119
# assert(state in ['available', 'pending', 'disabled'])
121
# @validates('default_kernel_id')
122
# def validate_kernel_id(self, key, val):
123
# if val != 'machine':
124
# assert(val is None)
126
# @validates('default_ramdisk_id')
127
# def validate_ramdisk_id(self, key, val):
128
# if val != 'machine':
129
# assert(val is None)
132
# TODO(vish): To make this into its own table, we need a good place to
133
# create the host entries. In config somwhere? Or the first
134
# time any object sets host? This only becomes particularly
135
# important if we need to store per-host data.
136
#class Host(BASE, NovaBase):
137
# """Represents a host where services are running"""
138
# __tablename__ = 'hosts'
139
# id = Column(String(255), primary_key=True)
93
"""Make the model object behave like a dict.
95
Includes attributes from joins."""
97
joined = dict([(k, v) for k, v in self.__dict__.iteritems()
100
return local.iteritems()
142
103
class Service(BASE, NovaBase):
149
110
topic = Column(String(255))
150
111
report_count = Column(Integer, nullable=False, default=0)
151
112
disabled = Column(Boolean, default=False)
113
availability_zone = Column(String(255), default='nova')
116
class Certificate(BASE, NovaBase):
117
"""Represents a an x509 certificate"""
118
__tablename__ = 'certificates'
119
id = Column(Integer, primary_key=True)
121
user_id = Column(String(255))
122
project_id = Column(String(255))
123
file_name = Column(String(255))
154
126
class Instance(BASE, NovaBase):
155
127
"""Represents a guest vm."""
156
128
__tablename__ = 'instances'
157
id = Column(Integer, primary_key=True)
158
internal_id = Column(Integer, unique=True)
129
id = Column(Integer, primary_key=True, autoincrement=True)
133
return FLAGS.instance_name_template % self.id
160
135
admin_pass = Column(String(255))
162
136
user_id = Column(String(255))
163
137
project_id = Column(String(255))
210
180
launched_at = Column(DateTime)
211
181
terminated_at = Column(DateTime)
183
availability_zone = Column(String(255))
213
185
# User editable field for display in user-facing UIs
214
186
display_name = Column(String(255))
215
187
display_description = Column(String(255))
189
locked = Column(Boolean)
217
191
# TODO(vish): see Ewan's email about state improvements, probably
218
192
# should be in a driver base class or some such
219
193
# vmstate_state = running, halted, suspended, paused
226
200
# 'shutdown', 'shutoff', 'crashed'])
203
class InstanceActions(BASE, NovaBase):
204
"""Represents a guest VM's actions and results"""
205
__tablename__ = "instance_actions"
206
id = Column(Integer, primary_key=True)
207
instance_id = Column(Integer, ForeignKey('instances.id'))
209
action = Column(String(255))
229
213
class Volume(BASE, NovaBase):
230
214
"""Represents a block storage device that can be attached to a vm."""
231
215
__tablename__ = 'volumes'
232
id = Column(Integer, primary_key=True)
233
ec2_id = Column(String(12), unique=True)
216
id = Column(Integer, primary_key=True, autoincrement=True)
220
return FLAGS.volume_name_template % self.id
235
222
user_id = Column(String(255))
236
223
project_id = Column(String(255))
519
506
host = Column(String(255)) # , ForeignKey('hosts.id'))
509
class ConsolePool(BASE, NovaBase):
510
"""Represents pool of consoles on the same physical node."""
511
__tablename__ = 'console_pools'
512
id = Column(Integer, primary_key=True)
513
address = Column(String(255))
514
username = Column(String(255))
515
password = Column(String(255))
516
console_type = Column(String(255))
517
public_hostname = Column(String(255))
518
host = Column(String(255))
519
compute_host = Column(String(255))
522
class Console(BASE, NovaBase):
523
"""Represents a console session for an instance."""
524
__tablename__ = 'consoles'
525
id = Column(Integer, primary_key=True)
526
instance_name = Column(String(255))
527
instance_id = Column(Integer)
528
password = Column(String(255))
529
port = Column(Integer, nullable=True)
530
pool_id = Column(Integer, ForeignKey('console_pools.id'))
531
pool = relationship(ConsolePool, backref=backref('consoles'))
522
534
def register_models():
523
535
"""Register Models and create metadata.
525
537
Called from nova.db.sqlalchemy.__init__ as part of loading the driver,
526
it will never need to be called explicitly elsewhere.
538
it will never need to be called explicitly elsewhere unless the
539
connection is lost and needs to be reestablished.
528
541
from sqlalchemy import create_engine
529
models = (Service, Instance, Volume, ExportDevice, IscsiTarget, FixedIp,
530
FloatingIp, Network, SecurityGroup,
531
SecurityGroupIngressRule, SecurityGroupInstanceAssociation,
532
AuthToken, User, Project) # , Image, Host
542
models = (Service, Instance, InstanceActions,
543
Volume, ExportDevice, IscsiTarget, FixedIp, FloatingIp,
544
Network, SecurityGroup, SecurityGroupIngressRule,
545
SecurityGroupInstanceAssociation, AuthToken, User,
546
Project, Certificate, ConsolePool, Console) # , Image, Host
533
547
engine = create_engine(FLAGS.sql_connection, echo=False)
534
548
for model in models:
535
549
model.metadata.create_all(engine)