OpenStack Compute (Nova)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

1646 lines
63 KiB

  1. # Copyright (c) 2011 X.commerce, a business unit of eBay Inc.
  2. # Copyright 2010 United States Government as represented by the
  3. # Administrator of the National Aeronautics and Space Administration.
  4. # Copyright 2011 Piston Cloud Computing, Inc.
  5. # All Rights Reserved.
  6. #
  7. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  8. # not use this file except in compliance with the License. You may obtain
  9. # a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. # License for the specific language governing permissions and limitations
  17. # under the License.
  18. """
  19. SQLAlchemy models for nova data.
  20. """
  21. from oslo_config import cfg
  22. from oslo_db.sqlalchemy import models
  23. from oslo_utils import timeutils
  24. from sqlalchemy import (Column, Index, Integer, BigInteger, Enum, String,
  25. schema, Unicode)
  26. from sqlalchemy.dialects.mysql import MEDIUMTEXT
  27. from sqlalchemy.ext.declarative import declarative_base
  28. from sqlalchemy import orm
  29. from sqlalchemy import ForeignKey, DateTime, Boolean, Text, Float
  30. from nova.db.sqlalchemy import types
  31. CONF = cfg.CONF
  32. BASE = declarative_base()
  33. def MediumText():
  34. return Text().with_variant(MEDIUMTEXT(), 'mysql')
  35. class NovaBase(models.TimestampMixin,
  36. models.ModelBase):
  37. metadata = None
  38. def __copy__(self):
  39. """Implement a safe copy.copy().
  40. SQLAlchemy-mapped objects travel with an object
  41. called an InstanceState, which is pegged to that object
  42. specifically and tracks everything about that object. It's
  43. critical within all attribute operations, including gets
  44. and deferred loading. This object definitely cannot be
  45. shared among two instances, and must be handled.
  46. The copy routine here makes use of session.merge() which
  47. already essentially implements a "copy" style of operation,
  48. which produces a new instance with a new InstanceState and copies
  49. all the data along mapped attributes without using any SQL.
  50. The mode we are using here has the caveat that the given object
  51. must be "clean", e.g. that it has no database-loaded state
  52. that has been updated and not flushed. This is a good thing,
  53. as creating a copy of an object including non-flushed, pending
  54. database state is probably not a good idea; neither represents
  55. what the actual row looks like, and only one should be flushed.
  56. """
  57. session = orm.Session()
  58. copy = session.merge(self, load=False)
  59. session.expunge(copy)
  60. return copy
  61. class Service(BASE, NovaBase, models.SoftDeleteMixin):
  62. """Represents a running service on a host."""
  63. __tablename__ = 'services'
  64. __table_args__ = (
  65. schema.UniqueConstraint("host", "topic", "deleted",
  66. name="uniq_services0host0topic0deleted"),
  67. schema.UniqueConstraint("host", "binary", "deleted",
  68. name="uniq_services0host0binary0deleted"),
  69. Index('services_uuid_idx', 'uuid', unique=True),
  70. )
  71. id = Column(Integer, primary_key=True)
  72. uuid = Column(String(36), nullable=True)
  73. host = Column(String(255))
  74. binary = Column(String(255))
  75. topic = Column(String(255))
  76. report_count = Column(Integer, nullable=False, default=0)
  77. disabled = Column(Boolean, default=False)
  78. disabled_reason = Column(String(255))
  79. last_seen_up = Column(DateTime, nullable=True)
  80. forced_down = Column(Boolean, default=False)
  81. version = Column(Integer, default=0)
  82. instance = orm.relationship(
  83. "Instance",
  84. backref='services',
  85. primaryjoin='and_(Service.host == Instance.host,'
  86. 'Service.binary == "nova-compute",'
  87. 'Instance.deleted == 0)',
  88. foreign_keys=host,
  89. )
  90. class ComputeNode(BASE, NovaBase, models.SoftDeleteMixin):
  91. """Represents a running compute service on a host."""
  92. __tablename__ = 'compute_nodes'
  93. __table_args__ = (
  94. Index('compute_nodes_uuid_idx', 'uuid', unique=True),
  95. schema.UniqueConstraint(
  96. 'host', 'hypervisor_hostname', 'deleted',
  97. name="uniq_compute_nodes0host0hypervisor_hostname0deleted"),
  98. )
  99. id = Column(Integer, primary_key=True)
  100. service_id = Column(Integer, nullable=True)
  101. # FIXME(sbauza: Host field is nullable because some old Juno compute nodes
  102. # can still report stats from an old ResourceTracker without setting this
  103. # field.
  104. # This field has to be set non-nullable in a later cycle (probably Lxxx)
  105. # once we are sure that all compute nodes in production report it.
  106. host = Column(String(255), nullable=True)
  107. uuid = Column(String(36), nullable=True)
  108. vcpus = Column(Integer, nullable=False)
  109. memory_mb = Column(Integer, nullable=False)
  110. local_gb = Column(Integer, nullable=False)
  111. vcpus_used = Column(Integer, nullable=False)
  112. memory_mb_used = Column(Integer, nullable=False)
  113. local_gb_used = Column(Integer, nullable=False)
  114. hypervisor_type = Column(MediumText(), nullable=False)
  115. hypervisor_version = Column(Integer, nullable=False)
  116. hypervisor_hostname = Column(String(255))
  117. # Free Ram, amount of activity (resize, migration, boot, etc) and
  118. # the number of running VM's are a good starting point for what's
  119. # important when making scheduling decisions.
  120. free_ram_mb = Column(Integer)
  121. free_disk_gb = Column(Integer)
  122. current_workload = Column(Integer)
  123. running_vms = Column(Integer)
  124. # Note(masumotok): Expected Strings example:
  125. #
  126. # '{"arch":"x86_64",
  127. # "model":"Nehalem",
  128. # "topology":{"sockets":1, "threads":2, "cores":3},
  129. # "features":["tdtscp", "xtpr"]}'
  130. #
  131. # Points are "json translatable" and it must have all dictionary keys
  132. # above, since it is copied from <cpu> tag of getCapabilities()
  133. # (See libvirt.virtConnection).
  134. cpu_info = Column(MediumText(), nullable=False)
  135. disk_available_least = Column(Integer)
  136. host_ip = Column(types.IPAddress())
  137. supported_instances = Column(Text)
  138. metrics = Column(Text)
  139. # Note(yongli): json string PCI Stats
  140. # '[{"vendor_id":"8086", "product_id":"1234", "count":3 }, ...]'
  141. pci_stats = Column(Text)
  142. # extra_resources is a json string containing arbitrary
  143. # data about additional resources.
  144. extra_resources = Column(Text)
  145. # json-encode string containing compute node statistics
  146. stats = Column(Text, default='{}')
  147. # json-encoded dict that contains NUMA topology as generated by
  148. # objects.NUMATopology._to_json()
  149. numa_topology = Column(Text)
  150. # allocation ratios provided by the RT
  151. ram_allocation_ratio = Column(Float, nullable=True)
  152. cpu_allocation_ratio = Column(Float, nullable=True)
  153. disk_allocation_ratio = Column(Float, nullable=True)
  154. mapped = Column(Integer, nullable=True, default=0)
  155. class Certificate(BASE, NovaBase, models.SoftDeleteMixin):
  156. """Represents a x509 certificate."""
  157. __tablename__ = 'certificates'
  158. __table_args__ = (
  159. Index('certificates_project_id_deleted_idx', 'project_id', 'deleted'),
  160. Index('certificates_user_id_deleted_idx', 'user_id', 'deleted')
  161. )
  162. id = Column(Integer, primary_key=True)
  163. user_id = Column(String(255))
  164. project_id = Column(String(255))
  165. file_name = Column(String(255))
  166. class Instance(BASE, NovaBase, models.SoftDeleteMixin):
  167. """Represents a guest VM."""
  168. __tablename__ = 'instances'
  169. __table_args__ = (
  170. Index('uuid', 'uuid', unique=True),
  171. Index('instances_project_id_idx', 'project_id'),
  172. Index('instances_project_id_deleted_idx',
  173. 'project_id', 'deleted'),
  174. Index('instances_reservation_id_idx',
  175. 'reservation_id'),
  176. Index('instances_terminated_at_launched_at_idx',
  177. 'terminated_at', 'launched_at'),
  178. Index('instances_uuid_deleted_idx',
  179. 'uuid', 'deleted'),
  180. Index('instances_task_state_updated_at_idx',
  181. 'task_state', 'updated_at'),
  182. Index('instances_host_node_deleted_idx',
  183. 'host', 'node', 'deleted'),
  184. Index('instances_host_deleted_cleaned_idx',
  185. 'host', 'deleted', 'cleaned'),
  186. Index('instances_deleted_created_at_idx',
  187. 'deleted', 'created_at'),
  188. Index('instances_updated_at_project_id_idx',
  189. 'updated_at', 'project_id'),
  190. schema.UniqueConstraint('uuid', name='uniq_instances0uuid'),
  191. )
  192. injected_files = []
  193. id = Column(Integer, primary_key=True, autoincrement=True)
  194. @property
  195. def name(self):
  196. try:
  197. base_name = CONF.instance_name_template % self.id
  198. except TypeError:
  199. # Support templates like "uuid-%(uuid)s", etc.
  200. info = {}
  201. # NOTE(russellb): Don't use self.iteritems() here, as it will
  202. # result in infinite recursion on the name property.
  203. for column in iter(orm.object_mapper(self).columns):
  204. key = column.name
  205. # prevent recursion if someone specifies %(name)s
  206. # %(name)s will not be valid.
  207. if key == 'name':
  208. continue
  209. info[key] = self[key]
  210. try:
  211. base_name = CONF.instance_name_template % info
  212. except KeyError:
  213. base_name = self.uuid
  214. return base_name
  215. @property
  216. def _extra_keys(self):
  217. return ['name']
  218. user_id = Column(String(255))
  219. project_id = Column(String(255))
  220. image_ref = Column(String(255))
  221. kernel_id = Column(String(255))
  222. ramdisk_id = Column(String(255))
  223. hostname = Column(String(255))
  224. launch_index = Column(Integer)
  225. key_name = Column(String(255))
  226. key_data = Column(MediumText())
  227. power_state = Column(Integer)
  228. vm_state = Column(String(255))
  229. task_state = Column(String(255))
  230. memory_mb = Column(Integer)
  231. vcpus = Column(Integer)
  232. root_gb = Column(Integer)
  233. ephemeral_gb = Column(Integer)
  234. ephemeral_key_uuid = Column(String(36))
  235. # This is not related to hostname, above. It refers
  236. # to the nova node.
  237. host = Column(String(255))
  238. # To identify the "ComputeNode" which the instance resides in.
  239. # This equals to ComputeNode.hypervisor_hostname.
  240. node = Column(String(255))
  241. # *not* flavorid, this is the internal primary_key
  242. instance_type_id = Column(Integer)
  243. user_data = Column(MediumText())
  244. reservation_id = Column(String(255))
  245. launched_at = Column(DateTime)
  246. terminated_at = Column(DateTime)
  247. # This always refers to the availability_zone kwarg passed in /servers and
  248. # provided as an API option, not at all related to the host AZ the instance
  249. # belongs to.
  250. availability_zone = Column(String(255))
  251. # User editable field for display in user-facing UIs
  252. display_name = Column(String(255))
  253. display_description = Column(String(255))
  254. # To remember on which host an instance booted.
  255. # An instance may have moved to another host by live migration.
  256. launched_on = Column(MediumText())
  257. # locked is superseded by locked_by and locked is not really
  258. # necessary but still used in API code so it remains.
  259. locked = Column(Boolean)
  260. locked_by = Column(Enum('owner', 'admin', name='instances0locked_by'))
  261. os_type = Column(String(255))
  262. architecture = Column(String(255))
  263. vm_mode = Column(String(255))
  264. uuid = Column(String(36), nullable=False)
  265. root_device_name = Column(String(255))
  266. default_ephemeral_device = Column(String(255))
  267. default_swap_device = Column(String(255))
  268. config_drive = Column(String(255))
  269. # User editable field meant to represent what ip should be used
  270. # to connect to the instance
  271. access_ip_v4 = Column(types.IPAddress())
  272. access_ip_v6 = Column(types.IPAddress())
  273. auto_disk_config = Column(Boolean())
  274. progress = Column(Integer)
  275. # EC2 instance_initiated_shutdown_terminate
  276. # True: -> 'terminate'
  277. # False: -> 'stop'
  278. # Note(maoy): currently Nova will always stop instead of terminate
  279. # no matter what the flag says. So we set the default to False.
  280. shutdown_terminate = Column(Boolean(), default=False)
  281. # EC2 disable_api_termination
  282. disable_terminate = Column(Boolean(), default=False)
  283. # OpenStack compute cell name. This will only be set at the top of
  284. # the cells tree and it'll be a full cell name such as 'api!hop1!hop2'
  285. # TODO(stephenfin): Remove this
  286. cell_name = Column(String(255))
  287. # NOTE(pumaranikar): internal_id attribute is no longer used (bug 1441242)
  288. # Hence, removing from object layer in current release (Ocata) and will
  289. # treated as deprecated. The column can be removed from schema with
  290. # a migration at the start of next release.
  291. # internal_id = Column(Integer)
  292. # Records whether an instance has been deleted from disk
  293. cleaned = Column(Integer, default=0)
  294. hidden = Column(Boolean, default=False)
  295. class InstanceInfoCache(BASE, NovaBase, models.SoftDeleteMixin):
  296. """Represents a cache of information about an instance
  297. """
  298. __tablename__ = 'instance_info_caches'
  299. __table_args__ = (
  300. schema.UniqueConstraint(
  301. "instance_uuid",
  302. name="uniq_instance_info_caches0instance_uuid"),)
  303. id = Column(Integer, primary_key=True, autoincrement=True)
  304. # text column used for storing a json object of network data for api
  305. network_info = Column(MediumText())
  306. instance_uuid = Column(String(36), ForeignKey('instances.uuid'),
  307. nullable=False)
  308. instance = orm.relationship(Instance,
  309. backref=orm.backref('info_cache', uselist=False),
  310. foreign_keys=instance_uuid,
  311. primaryjoin=instance_uuid == Instance.uuid)
  312. class InstanceExtra(BASE, NovaBase, models.SoftDeleteMixin):
  313. __tablename__ = 'instance_extra'
  314. __table_args__ = (
  315. Index('instance_extra_idx', 'instance_uuid'),)
  316. id = Column(Integer, primary_key=True, autoincrement=True)
  317. instance_uuid = Column(String(36), ForeignKey('instances.uuid'),
  318. nullable=False)
  319. device_metadata = orm.deferred(Column(Text))
  320. numa_topology = orm.deferred(Column(Text))
  321. pci_requests = orm.deferred(Column(Text))
  322. flavor = orm.deferred(Column(Text))
  323. vcpu_model = orm.deferred(Column(Text))
  324. migration_context = orm.deferred(Column(Text))
  325. keypairs = orm.deferred(Column(Text))
  326. trusted_certs = orm.deferred(Column(Text))
  327. # NOTE(Luyao): 'vpmems' is still in the database
  328. # and can be removed in the future release.
  329. resources = orm.deferred(Column(Text))
  330. instance = orm.relationship(Instance,
  331. backref=orm.backref('extra',
  332. uselist=False),
  333. foreign_keys=instance_uuid,
  334. primaryjoin=instance_uuid == Instance.uuid)
  335. # NOTE(alaski): This table exists in the nova_api database and its usage here
  336. # is deprecated.
  337. class InstanceTypes(BASE, NovaBase, models.SoftDeleteMixin):
  338. """Represents possible flavors for instances.
  339. Note: instance_type and flavor are synonyms and the term instance_type is
  340. deprecated and in the process of being removed.
  341. """
  342. __tablename__ = "instance_types"
  343. __table_args__ = (
  344. schema.UniqueConstraint("flavorid", "deleted",
  345. name="uniq_instance_types0flavorid0deleted"),
  346. schema.UniqueConstraint("name", "deleted",
  347. name="uniq_instance_types0name0deleted")
  348. )
  349. # Internal only primary key/id
  350. id = Column(Integer, primary_key=True)
  351. name = Column(String(255))
  352. memory_mb = Column(Integer, nullable=False)
  353. vcpus = Column(Integer, nullable=False)
  354. root_gb = Column(Integer)
  355. ephemeral_gb = Column(Integer)
  356. # Public facing id will be renamed public_id
  357. flavorid = Column(String(255))
  358. swap = Column(Integer, nullable=False, default=0)
  359. rxtx_factor = Column(Float, default=1)
  360. vcpu_weight = Column(Integer)
  361. disabled = Column(Boolean, default=False)
  362. is_public = Column(Boolean, default=True)
  363. class Quota(BASE, NovaBase, models.SoftDeleteMixin):
  364. """Represents a single quota override for a project.
  365. If there is no row for a given project id and resource, then the
  366. default for the quota class is used. If there is no row for a
  367. given quota class and resource, then the default for the
  368. deployment is used. If the row is present but the hard limit is
  369. Null, then the resource is unlimited.
  370. """
  371. __tablename__ = 'quotas'
  372. __table_args__ = (
  373. schema.UniqueConstraint("project_id", "resource", "deleted",
  374. name="uniq_quotas0project_id0resource0deleted"
  375. ),
  376. )
  377. id = Column(Integer, primary_key=True)
  378. project_id = Column(String(255))
  379. resource = Column(String(255), nullable=False)
  380. hard_limit = Column(Integer)
  381. class ProjectUserQuota(BASE, NovaBase, models.SoftDeleteMixin):
  382. """Represents a single quota override for a user with in a project."""
  383. __tablename__ = 'project_user_quotas'
  384. uniq_name = "uniq_project_user_quotas0user_id0project_id0resource0deleted"
  385. __table_args__ = (
  386. schema.UniqueConstraint("user_id", "project_id", "resource", "deleted",
  387. name=uniq_name),
  388. Index('project_user_quotas_project_id_deleted_idx',
  389. 'project_id', 'deleted'),
  390. Index('project_user_quotas_user_id_deleted_idx',
  391. 'user_id', 'deleted')
  392. )
  393. id = Column(Integer, primary_key=True, nullable=False)
  394. project_id = Column(String(255), nullable=False)
  395. user_id = Column(String(255), nullable=False)
  396. resource = Column(String(255), nullable=False)
  397. hard_limit = Column(Integer)
  398. class QuotaClass(BASE, NovaBase, models.SoftDeleteMixin):
  399. """Represents a single quota override for a quota class.
  400. If there is no row for a given quota class and resource, then the
  401. default for the deployment is used. If the row is present but the
  402. hard limit is Null, then the resource is unlimited.
  403. """
  404. __tablename__ = 'quota_classes'
  405. __table_args__ = (
  406. Index('ix_quota_classes_class_name', 'class_name'),
  407. )
  408. id = Column(Integer, primary_key=True)
  409. class_name = Column(String(255))
  410. resource = Column(String(255))
  411. hard_limit = Column(Integer)
  412. class QuotaUsage(BASE, NovaBase, models.SoftDeleteMixin):
  413. """Represents the current usage for a given resource."""
  414. __tablename__ = 'quota_usages'
  415. __table_args__ = (
  416. Index('ix_quota_usages_project_id', 'project_id'),
  417. Index('ix_quota_usages_user_id_deleted', 'user_id', 'deleted'),
  418. )
  419. id = Column(Integer, primary_key=True)
  420. project_id = Column(String(255))
  421. user_id = Column(String(255))
  422. resource = Column(String(255), nullable=False)
  423. in_use = Column(Integer, nullable=False)
  424. reserved = Column(Integer, nullable=False)
  425. @property
  426. def total(self):
  427. return self.in_use + self.reserved
  428. until_refresh = Column(Integer)
  429. class Reservation(BASE, NovaBase, models.SoftDeleteMixin):
  430. """Represents a resource reservation for quotas."""
  431. __tablename__ = 'reservations'
  432. __table_args__ = (
  433. Index('ix_reservations_project_id', 'project_id'),
  434. Index('reservations_uuid_idx', 'uuid'),
  435. Index('reservations_deleted_expire_idx', 'deleted', 'expire'),
  436. Index('ix_reservations_user_id_deleted', 'user_id', 'deleted'),
  437. )
  438. id = Column(Integer, primary_key=True, nullable=False)
  439. uuid = Column(String(36), nullable=False)
  440. usage_id = Column(Integer, ForeignKey('quota_usages.id'), nullable=False)
  441. project_id = Column(String(255))
  442. user_id = Column(String(255))
  443. resource = Column(String(255))
  444. delta = Column(Integer, nullable=False)
  445. expire = Column(DateTime)
  446. usage = orm.relationship(
  447. "QuotaUsage",
  448. foreign_keys=usage_id,
  449. primaryjoin='and_(Reservation.usage_id == QuotaUsage.id,'
  450. 'QuotaUsage.deleted == 0)')
  451. # TODO(macsz) This class can be removed. It might need a DB migration to drop
  452. # this.
  453. class Snapshot(BASE, NovaBase, models.SoftDeleteMixin):
  454. """Represents a block storage device that can be attached to a VM."""
  455. __tablename__ = 'snapshots'
  456. __table_args__ = ()
  457. id = Column(String(36), primary_key=True, nullable=False)
  458. deleted = Column(String(36), default="")
  459. @property
  460. def volume_name(self):
  461. return CONF.volume_name_template % self.volume_id
  462. user_id = Column(String(255))
  463. project_id = Column(String(255))
  464. volume_id = Column(String(36), nullable=False)
  465. status = Column(String(255))
  466. progress = Column(String(255))
  467. volume_size = Column(Integer)
  468. scheduled_at = Column(DateTime)
  469. display_name = Column(String(255))
  470. display_description = Column(String(255))
  471. class BlockDeviceMapping(BASE, NovaBase, models.SoftDeleteMixin):
  472. """Represents block device mapping that is defined by EC2."""
  473. __tablename__ = "block_device_mapping"
  474. __table_args__ = (
  475. Index('snapshot_id', 'snapshot_id'),
  476. Index('volume_id', 'volume_id'),
  477. Index('block_device_mapping_instance_uuid_device_name_idx',
  478. 'instance_uuid', 'device_name'),
  479. Index('block_device_mapping_instance_uuid_volume_id_idx',
  480. 'instance_uuid', 'volume_id'),
  481. Index('block_device_mapping_instance_uuid_idx', 'instance_uuid'),
  482. schema.UniqueConstraint('uuid', name='uniq_block_device_mapping0uuid'),
  483. )
  484. id = Column(Integer, primary_key=True, autoincrement=True)
  485. instance_uuid = Column(String(36), ForeignKey('instances.uuid'))
  486. # NOTE(mdbooth): The REST API for BDMs includes a UUID field. That uuid
  487. # refers to an image, volume, or snapshot which will be used in the
  488. # initialisation of the BDM. It is only relevant during the API call, and
  489. # is not persisted directly. This is the UUID of the BDM itself.
  490. # FIXME(danms): This should eventually be non-nullable, but we need a
  491. # transition period first.
  492. uuid = Column(String(36))
  493. instance = orm.relationship(Instance,
  494. backref=orm.backref('block_device_mapping'),
  495. foreign_keys=instance_uuid,
  496. primaryjoin='and_(BlockDeviceMapping.'
  497. 'instance_uuid=='
  498. 'Instance.uuid,'
  499. 'BlockDeviceMapping.deleted=='
  500. '0)')
  501. source_type = Column(String(255))
  502. destination_type = Column(String(255))
  503. guest_format = Column(String(255))
  504. device_type = Column(String(255))
  505. disk_bus = Column(String(255))
  506. boot_index = Column(Integer)
  507. device_name = Column(String(255))
  508. # default=False for compatibility of the existing code.
  509. # With EC2 API,
  510. # default True for ami specified device.
  511. # default False for created with other timing.
  512. # TODO(sshturm) add default in db
  513. delete_on_termination = Column(Boolean, default=False)
  514. snapshot_id = Column(String(36))
  515. volume_id = Column(String(36))
  516. volume_size = Column(Integer)
  517. volume_type = Column(String(255))
  518. image_id = Column(String(36))
  519. # for no device to suppress devices.
  520. no_device = Column(Boolean)
  521. connection_info = Column(MediumText())
  522. tag = Column(String(255))
  523. attachment_id = Column(String(36))
  524. class SecurityGroupInstanceAssociation(BASE, NovaBase, models.SoftDeleteMixin):
  525. __tablename__ = 'security_group_instance_association'
  526. __table_args__ = (
  527. Index('security_group_instance_association_instance_uuid_idx',
  528. 'instance_uuid'),
  529. )
  530. id = Column(Integer, primary_key=True, nullable=False)
  531. security_group_id = Column(Integer, ForeignKey('security_groups.id'))
  532. instance_uuid = Column(String(36), ForeignKey('instances.uuid'))
  533. class SecurityGroup(BASE, NovaBase, models.SoftDeleteMixin):
  534. """Represents a security group."""
  535. __tablename__ = 'security_groups'
  536. __table_args__ = (
  537. schema.UniqueConstraint('project_id', 'name', 'deleted',
  538. name='uniq_security_groups0project_id0'
  539. 'name0deleted'),
  540. )
  541. id = Column(Integer, primary_key=True)
  542. name = Column(String(255))
  543. description = Column(String(255))
  544. user_id = Column(String(255))
  545. project_id = Column(String(255))
  546. instances = orm.relationship(Instance,
  547. secondary="security_group_instance_association",
  548. primaryjoin='and_('
  549. 'SecurityGroup.id == '
  550. 'SecurityGroupInstanceAssociation.security_group_id,'
  551. 'SecurityGroupInstanceAssociation.deleted == 0,'
  552. 'SecurityGroup.deleted == 0)',
  553. secondaryjoin='and_('
  554. 'SecurityGroupInstanceAssociation.instance_uuid == Instance.uuid,'
  555. # (anthony) the condition below shouldn't be necessary now that the
  556. # association is being marked as deleted. However, removing this
  557. # may cause existing deployments to choke, so I'm leaving it
  558. 'Instance.deleted == 0)',
  559. backref='security_groups')
  560. # TODO(stephenfin): Remove this in the V release or later, once we're sure we
  561. # won't want it back (it's for nova-network, so we won't)
  562. class SecurityGroupIngressRule(BASE, NovaBase, models.SoftDeleteMixin):
  563. """Represents a rule in a security group."""
  564. __tablename__ = 'security_group_rules'
  565. __table_args__ = ()
  566. id = Column(Integer, primary_key=True)
  567. parent_group_id = Column(Integer, ForeignKey('security_groups.id'))
  568. parent_group = orm.relationship("SecurityGroup", backref="rules",
  569. foreign_keys=parent_group_id,
  570. primaryjoin='and_('
  571. 'SecurityGroupIngressRule.parent_group_id == SecurityGroup.id,'
  572. 'SecurityGroupIngressRule.deleted == 0)')
  573. protocol = Column(String(255))
  574. from_port = Column(Integer)
  575. to_port = Column(Integer)
  576. cidr = Column(types.CIDR())
  577. # Note: This is not the parent SecurityGroup. It's SecurityGroup we're
  578. # granting access for.
  579. group_id = Column(Integer, ForeignKey('security_groups.id'))
  580. grantee_group = orm.relationship("SecurityGroup",
  581. foreign_keys=group_id,
  582. primaryjoin='and_('
  583. 'SecurityGroupIngressRule.group_id == SecurityGroup.id,'
  584. 'SecurityGroupIngressRule.deleted == 0)')
  585. # TODO(stephenfin): Remove this in the V release or later, once we're sure we
  586. # won't want it back (it's for nova-network, so we won't)
  587. class SecurityGroupIngressDefaultRule(BASE, NovaBase, models.SoftDeleteMixin):
  588. __tablename__ = 'security_group_default_rules'
  589. __table_args__ = ()
  590. id = Column(Integer, primary_key=True, nullable=False)
  591. protocol = Column(String(5)) # "tcp", "udp" or "icmp"
  592. from_port = Column(Integer)
  593. to_port = Column(Integer)
  594. cidr = Column(types.CIDR())
  595. # TODO(stephenfin): Remove this in the V release or later, once we're sure we
  596. # won't want it back (it's for nova-network, so we won't)
  597. class ProviderFirewallRule(BASE, NovaBase, models.SoftDeleteMixin):
  598. """Represents a rule in a security group."""
  599. __tablename__ = 'provider_fw_rules'
  600. __table_args__ = ()
  601. id = Column(Integer, primary_key=True, nullable=False)
  602. protocol = Column(String(5)) # "tcp", "udp", or "icmp"
  603. from_port = Column(Integer)
  604. to_port = Column(Integer)
  605. cidr = Column(types.CIDR())
  606. # NOTE(alaski): This table exists in the nova_api database and its usage here
  607. # is deprecated.
  608. class KeyPair(BASE, NovaBase, models.SoftDeleteMixin):
  609. """Represents a public key pair for ssh / WinRM."""
  610. __tablename__ = 'key_pairs'
  611. __table_args__ = (
  612. schema.UniqueConstraint("user_id", "name", "deleted",
  613. name="uniq_key_pairs0user_id0name0deleted"),
  614. )
  615. id = Column(Integer, primary_key=True, nullable=False)
  616. name = Column(String(255), nullable=False)
  617. user_id = Column(String(255))
  618. fingerprint = Column(String(255))
  619. public_key = Column(MediumText())
  620. type = Column(Enum('ssh', 'x509', name='keypair_types'),
  621. nullable=False, server_default='ssh')
  622. class Migration(BASE, NovaBase, models.SoftDeleteMixin):
  623. """Represents a running host-to-host migration."""
  624. __tablename__ = 'migrations'
  625. __table_args__ = (
  626. Index('migrations_instance_uuid_and_status_idx', 'deleted',
  627. 'instance_uuid', 'status'),
  628. Index('migrations_by_host_nodes_and_status_idx', 'deleted',
  629. 'source_compute', 'dest_compute', 'source_node', 'dest_node',
  630. 'status'),
  631. Index('migrations_uuid', 'uuid', unique=True),
  632. Index('migrations_updated_at_idx', 'updated_at'),
  633. )
  634. id = Column(Integer, primary_key=True, nullable=False)
  635. # NOTE(tr3buchet): the ____compute variables are instance['host']
  636. source_compute = Column(String(255))
  637. dest_compute = Column(String(255))
  638. # nodes are equivalent to a compute node's 'hypervisor_hostname'
  639. source_node = Column(String(255))
  640. dest_node = Column(String(255))
  641. # NOTE(tr3buchet): dest_host, btw, is an ip address
  642. dest_host = Column(String(255))
  643. old_instance_type_id = Column(Integer())
  644. new_instance_type_id = Column(Integer())
  645. instance_uuid = Column(String(36), ForeignKey('instances.uuid'))
  646. uuid = Column(String(36), nullable=True)
  647. # TODO(_cerberus_): enum
  648. status = Column(String(255))
  649. migration_type = Column(Enum('migration', 'resize', 'live-migration',
  650. 'evacuation', name='migration_type'),
  651. nullable=True)
  652. hidden = Column(Boolean, default=False)
  653. memory_total = Column(BigInteger, nullable=True)
  654. memory_processed = Column(BigInteger, nullable=True)
  655. memory_remaining = Column(BigInteger, nullable=True)
  656. disk_total = Column(BigInteger, nullable=True)
  657. disk_processed = Column(BigInteger, nullable=True)
  658. disk_remaining = Column(BigInteger, nullable=True)
  659. cross_cell_move = Column(Boolean, default=False)
  660. user_id = Column(String(255), nullable=True)
  661. project_id = Column(String(255), nullable=True)
  662. instance = orm.relationship("Instance", foreign_keys=instance_uuid,
  663. primaryjoin='and_(Migration.instance_uuid == '
  664. 'Instance.uuid, Instance.deleted == '
  665. '0)')
  666. # TODO(stephenfin): Remove this in the V release or later, once we're sure we
  667. # won't want it back (it's for nova-network, so we won't)
  668. class Network(BASE, NovaBase, models.SoftDeleteMixin):
  669. """Represents a network."""
  670. __tablename__ = 'networks'
  671. __table_args__ = (
  672. schema.UniqueConstraint("vlan", "deleted",
  673. name="uniq_networks0vlan0deleted"),
  674. Index('networks_bridge_deleted_idx', 'bridge', 'deleted'),
  675. Index('networks_host_idx', 'host'),
  676. Index('networks_project_id_deleted_idx', 'project_id', 'deleted'),
  677. Index('networks_uuid_project_id_deleted_idx', 'uuid',
  678. 'project_id', 'deleted'),
  679. Index('networks_vlan_deleted_idx', 'vlan', 'deleted'),
  680. Index('networks_cidr_v6_idx', 'cidr_v6')
  681. )
  682. id = Column(Integer, primary_key=True, nullable=False)
  683. label = Column(String(255))
  684. injected = Column(Boolean, default=False)
  685. cidr = Column(types.CIDR())
  686. cidr_v6 = Column(types.CIDR())
  687. multi_host = Column(Boolean, default=False)
  688. gateway_v6 = Column(types.IPAddress())
  689. netmask_v6 = Column(types.IPAddress())
  690. netmask = Column(types.IPAddress())
  691. bridge = Column(String(255))
  692. bridge_interface = Column(String(255))
  693. gateway = Column(types.IPAddress())
  694. broadcast = Column(types.IPAddress())
  695. dns1 = Column(types.IPAddress())
  696. dns2 = Column(types.IPAddress())
  697. vlan = Column(Integer)
  698. vpn_public_address = Column(types.IPAddress())
  699. vpn_public_port = Column(Integer)
  700. vpn_private_address = Column(types.IPAddress())
  701. dhcp_start = Column(types.IPAddress())
  702. rxtx_base = Column(Integer)
  703. project_id = Column(String(255))
  704. priority = Column(Integer)
  705. host = Column(String(255))
  706. uuid = Column(String(36))
  707. mtu = Column(Integer)
  708. dhcp_server = Column(types.IPAddress())
  709. enable_dhcp = Column(Boolean, default=True)
  710. share_address = Column(Boolean, default=False)
  711. class VirtualInterface(BASE, NovaBase, models.SoftDeleteMixin):
  712. """Represents a virtual interface on an instance."""
  713. __tablename__ = 'virtual_interfaces'
  714. __table_args__ = (
  715. schema.UniqueConstraint("address", "deleted",
  716. name="uniq_virtual_interfaces0address0deleted"),
  717. Index('virtual_interfaces_network_id_idx', 'network_id'),
  718. Index('virtual_interfaces_instance_uuid_fkey', 'instance_uuid'),
  719. Index('virtual_interfaces_uuid_idx', 'uuid'),
  720. )
  721. id = Column(Integer, primary_key=True, nullable=False)
  722. address = Column(String(255))
  723. network_id = Column(Integer)
  724. instance_uuid = Column(String(36), ForeignKey('instances.uuid'))
  725. uuid = Column(String(36))
  726. tag = Column(String(255))
  727. # TODO(stephenfin): Remove this in the V release or later, once we're sure we
  728. # won't want it back (it's for nova-network, so we won't)
  729. class FixedIp(BASE, NovaBase, models.SoftDeleteMixin):
  730. """Represents a fixed IP for an instance."""
  731. __tablename__ = 'fixed_ips'
  732. __table_args__ = (
  733. schema.UniqueConstraint(
  734. "address", "deleted", name="uniq_fixed_ips0address0deleted"),
  735. Index('fixed_ips_virtual_interface_id_fkey', 'virtual_interface_id'),
  736. Index('network_id', 'network_id'),
  737. Index('address', 'address'),
  738. Index('fixed_ips_instance_uuid_fkey', 'instance_uuid'),
  739. Index('fixed_ips_host_idx', 'host'),
  740. Index('fixed_ips_network_id_host_deleted_idx', 'network_id', 'host',
  741. 'deleted'),
  742. Index('fixed_ips_address_reserved_network_id_deleted_idx',
  743. 'address', 'reserved', 'network_id', 'deleted'),
  744. Index('fixed_ips_deleted_allocated_idx', 'address', 'deleted',
  745. 'allocated'),
  746. Index('fixed_ips_deleted_allocated_updated_at_idx', 'deleted',
  747. 'allocated', 'updated_at')
  748. )
  749. id = Column(Integer, primary_key=True)
  750. address = Column(types.IPAddress())
  751. network_id = Column(Integer)
  752. virtual_interface_id = Column(Integer)
  753. instance_uuid = Column(String(36), ForeignKey('instances.uuid'))
  754. # associated means that a fixed_ip has its instance_id column set
  755. # allocated means that a fixed_ip has its virtual_interface_id column set
  756. # TODO(sshturm) add default in db
  757. allocated = Column(Boolean, default=False)
  758. # leased means dhcp bridge has leased the ip
  759. # TODO(sshturm) add default in db
  760. leased = Column(Boolean, default=False)
  761. # TODO(sshturm) add default in db
  762. reserved = Column(Boolean, default=False)
  763. host = Column(String(255))
  764. network = orm.relationship(Network,
  765. backref=orm.backref('fixed_ips'),
  766. foreign_keys=network_id,
  767. primaryjoin='and_('
  768. 'FixedIp.network_id == Network.id,'
  769. 'FixedIp.deleted == 0,'
  770. 'Network.deleted == 0)')
  771. instance = orm.relationship(Instance,
  772. foreign_keys=instance_uuid,
  773. primaryjoin='and_('
  774. 'FixedIp.instance_uuid == Instance.uuid,'
  775. 'FixedIp.deleted == 0,'
  776. 'Instance.deleted == 0)')
  777. virtual_interface = orm.relationship(VirtualInterface,
  778. backref=orm.backref('fixed_ips'),
  779. foreign_keys=virtual_interface_id,
  780. primaryjoin='and_('
  781. 'FixedIp.virtual_interface_id == '
  782. 'VirtualInterface.id,'
  783. 'FixedIp.deleted == 0,'
  784. 'VirtualInterface.deleted == 0)')
  785. # TODO(stephenfin): Remove this in the V release or later, once we're sure we
  786. # won't want it back (it's for nova-network, so we won't)
  787. class FloatingIp(BASE, NovaBase, models.SoftDeleteMixin):
  788. """Represents a floating IP that dynamically forwards to a fixed IP."""
  789. __tablename__ = 'floating_ips'
  790. __table_args__ = (
  791. schema.UniqueConstraint("address", "deleted",
  792. name="uniq_floating_ips0address0deleted"),
  793. Index('fixed_ip_id', 'fixed_ip_id'),
  794. Index('floating_ips_host_idx', 'host'),
  795. Index('floating_ips_project_id_idx', 'project_id'),
  796. Index('floating_ips_pool_deleted_fixed_ip_id_project_id_idx',
  797. 'pool', 'deleted', 'fixed_ip_id', 'project_id')
  798. )
  799. id = Column(Integer, primary_key=True)
  800. address = Column(types.IPAddress())
  801. fixed_ip_id = Column(Integer)
  802. project_id = Column(String(255))
  803. host = Column(String(255))
  804. auto_assigned = Column(Boolean, default=False)
  805. # TODO(sshturm) add default in db
  806. pool = Column(String(255))
  807. interface = Column(String(255))
  808. fixed_ip = orm.relationship(FixedIp,
  809. backref=orm.backref('floating_ips'),
  810. foreign_keys=fixed_ip_id,
  811. primaryjoin='and_('
  812. 'FloatingIp.fixed_ip_id == FixedIp.id,'
  813. 'FloatingIp.deleted == 0,'
  814. 'FixedIp.deleted == 0)')
  815. # TODO(stephenfin): Remove in V or later
  816. class DNSDomain(BASE, NovaBase, models.SoftDeleteMixin):
  817. """Represents a DNS domain with availability zone or project info."""
  818. __tablename__ = 'dns_domains'
  819. __table_args__ = (
  820. Index('dns_domains_project_id_idx', 'project_id'),
  821. Index('dns_domains_domain_deleted_idx', 'domain', 'deleted'),
  822. )
  823. deleted = Column(Boolean, default=False)
  824. domain = Column(String(255), primary_key=True)
  825. scope = Column(String(255))
  826. availability_zone = Column(String(255))
  827. project_id = Column(String(255))
  828. # TODO(stephenfin): Remove in V or later
  829. class ConsolePool(BASE, NovaBase, models.SoftDeleteMixin):
  830. """Represents pool of consoles on the same physical node."""
  831. __tablename__ = 'console_pools'
  832. __table_args__ = (
  833. schema.UniqueConstraint(
  834. "host", "console_type", "compute_host", "deleted",
  835. name="uniq_console_pools0host0console_type0compute_host0deleted"),
  836. )
  837. id = Column(Integer, primary_key=True)
  838. address = Column(types.IPAddress())
  839. username = Column(String(255))
  840. password = Column(String(255))
  841. console_type = Column(String(255))
  842. public_hostname = Column(String(255))
  843. host = Column(String(255))
  844. compute_host = Column(String(255))
  845. # TODO(stephenfin): Remove in V or later
  846. class Console(BASE, NovaBase, models.SoftDeleteMixin):
  847. """Represents a console session for an instance."""
  848. __tablename__ = 'consoles'
  849. __table_args__ = (
  850. Index('consoles_instance_uuid_idx', 'instance_uuid'),
  851. )
  852. id = Column(Integer, primary_key=True)
  853. instance_name = Column(String(255))
  854. instance_uuid = Column(String(36), ForeignKey('instances.uuid'))
  855. password = Column(String(255))
  856. port = Column(Integer)
  857. pool_id = Column(Integer, ForeignKey('console_pools.id'))
  858. pool = orm.relationship(ConsolePool, backref=orm.backref('consoles'))
  859. class InstanceMetadata(BASE, NovaBase, models.SoftDeleteMixin):
  860. """Represents a user-provided metadata key/value pair for an instance."""
  861. __tablename__ = 'instance_metadata'
  862. __table_args__ = (
  863. Index('instance_metadata_instance_uuid_idx', 'instance_uuid'),
  864. )
  865. id = Column(Integer, primary_key=True)
  866. key = Column(String(255))
  867. value = Column(String(255))
  868. instance_uuid = Column(String(36), ForeignKey('instances.uuid'))
  869. instance = orm.relationship(Instance, backref="metadata",
  870. foreign_keys=instance_uuid,
  871. primaryjoin='and_('
  872. 'InstanceMetadata.instance_uuid == '
  873. 'Instance.uuid,'
  874. 'InstanceMetadata.deleted == 0)')
  875. class InstanceSystemMetadata(BASE, NovaBase, models.SoftDeleteMixin):
  876. """Represents a system-owned metadata key/value pair for an instance."""
  877. __tablename__ = 'instance_system_metadata'
  878. __table_args__ = (
  879. Index('instance_uuid', 'instance_uuid'),
  880. )
  881. id = Column(Integer, primary_key=True)
  882. key = Column(String(255), nullable=False)
  883. value = Column(String(255))
  884. instance_uuid = Column(String(36),
  885. ForeignKey('instances.uuid'),
  886. nullable=False)
  887. instance = orm.relationship(Instance, backref="system_metadata",
  888. foreign_keys=instance_uuid)
  889. # NOTE(alaski): This table exists in the nova_api database and its usage here
  890. # is deprecated.
  891. class InstanceTypeProjects(BASE, NovaBase, models.SoftDeleteMixin):
  892. """Represent projects associated instance_types."""
  893. __tablename__ = "instance_type_projects"
  894. __table_args__ = (schema.UniqueConstraint(
  895. "instance_type_id", "project_id", "deleted",
  896. name="uniq_instance_type_projects0instance_type_id0project_id0deleted"
  897. ),
  898. )
  899. id = Column(Integer, primary_key=True)
  900. instance_type_id = Column(Integer, ForeignKey('instance_types.id'),
  901. nullable=False)
  902. project_id = Column(String(255))
  903. instance_type = orm.relationship(InstanceTypes, backref="projects",
  904. foreign_keys=instance_type_id,
  905. primaryjoin='and_('
  906. 'InstanceTypeProjects.instance_type_id == InstanceTypes.id,'
  907. 'InstanceTypeProjects.deleted == 0)')
  908. # NOTE(alaski): This table exists in the nova_api database and its usage here
  909. # is deprecated.
  910. class InstanceTypeExtraSpecs(BASE, NovaBase, models.SoftDeleteMixin):
  911. """Represents additional specs as key/value pairs for an instance_type."""
  912. __tablename__ = 'instance_type_extra_specs'
  913. __table_args__ = (
  914. Index('instance_type_extra_specs_instance_type_id_key_idx',
  915. 'instance_type_id', 'key'),
  916. schema.UniqueConstraint(
  917. "instance_type_id", "key", "deleted",
  918. name=("uniq_instance_type_extra_specs0"
  919. "instance_type_id0key0deleted")
  920. ),
  921. {'mysql_collate': 'utf8_bin'},
  922. )
  923. id = Column(Integer, primary_key=True)
  924. key = Column(String(255))
  925. value = Column(String(255))
  926. instance_type_id = Column(Integer, ForeignKey('instance_types.id'),
  927. nullable=False)
  928. instance_type = orm.relationship(InstanceTypes, backref="extra_specs",
  929. foreign_keys=instance_type_id,
  930. primaryjoin='and_('
  931. 'InstanceTypeExtraSpecs.instance_type_id == InstanceTypes.id,'
  932. 'InstanceTypeExtraSpecs.deleted == 0)')
  933. # TODO(stephenfin): Remove this in the U release or later, once we're sure we
  934. # won't want it back (it's for cells v1, so we won't)
  935. class Cell(BASE, NovaBase, models.SoftDeleteMixin):
  936. """Represents parent and child cells of this cell. Cells can
  937. have multiple parents and children, so there could be any number
  938. of entries with is_parent=True or False
  939. """
  940. __tablename__ = 'cells'
  941. __table_args__ = (schema.UniqueConstraint(
  942. "name", "deleted", name="uniq_cells0name0deleted"
  943. ),
  944. )
  945. id = Column(Integer, primary_key=True)
  946. # Name here is the 'short name' of a cell. For instance: 'child1'
  947. name = Column(String(255))
  948. api_url = Column(String(255))
  949. transport_url = Column(String(255), nullable=False)
  950. weight_offset = Column(Float(), default=0.0)
  951. weight_scale = Column(Float(), default=1.0)
  952. is_parent = Column(Boolean())
  953. # NOTE(alaski): This table exists in the nova_api database and its usage here
  954. # is deprecated.
  955. class AggregateHost(BASE, NovaBase, models.SoftDeleteMixin):
  956. """Represents a host that is member of an aggregate."""
  957. __tablename__ = 'aggregate_hosts'
  958. __table_args__ = (schema.UniqueConstraint(
  959. "host", "aggregate_id", "deleted",
  960. name="uniq_aggregate_hosts0host0aggregate_id0deleted"
  961. ),
  962. )
  963. id = Column(Integer, primary_key=True, autoincrement=True)
  964. host = Column(String(255))
  965. aggregate_id = Column(Integer, ForeignKey('aggregates.id'), nullable=False)
  966. # NOTE(alaski): This table exists in the nova_api database and its usage here
  967. # is deprecated.
  968. class AggregateMetadata(BASE, NovaBase, models.SoftDeleteMixin):
  969. """Represents a metadata key/value pair for an aggregate."""
  970. __tablename__ = 'aggregate_metadata'
  971. __table_args__ = (
  972. schema.UniqueConstraint("aggregate_id", "key", "deleted",
  973. name="uniq_aggregate_metadata0aggregate_id0key0deleted"
  974. ),
  975. Index('aggregate_metadata_key_idx', 'key'),
  976. Index('aggregate_metadata_value_idx', 'value'),
  977. )
  978. id = Column(Integer, primary_key=True)
  979. key = Column(String(255), nullable=False)
  980. value = Column(String(255), nullable=False)
  981. aggregate_id = Column(Integer, ForeignKey('aggregates.id'), nullable=False)
  982. # NOTE(alaski): This table exists in the nova_api database and its usage here
  983. # is deprecated.
  984. class Aggregate(BASE, NovaBase, models.SoftDeleteMixin):
  985. """Represents a cluster of hosts that exists in this zone."""
  986. __tablename__ = 'aggregates'
  987. __table_args__ = (Index('aggregate_uuid_idx', 'uuid'),)
  988. id = Column(Integer, primary_key=True, autoincrement=True)
  989. uuid = Column(String(36))
  990. name = Column(String(255))
  991. _hosts = orm.relationship(AggregateHost,
  992. primaryjoin='and_('
  993. 'Aggregate.id == AggregateHost.aggregate_id,'
  994. 'AggregateHost.deleted == 0,'
  995. 'Aggregate.deleted == 0)')
  996. _metadata = orm.relationship(AggregateMetadata,
  997. primaryjoin='and_('
  998. 'Aggregate.id == AggregateMetadata.aggregate_id,'
  999. 'AggregateMetadata.deleted == 0,'
  1000. 'Aggregate.deleted == 0)')
  1001. @property
  1002. def _extra_keys(self):
  1003. return ['hosts', 'metadetails', 'availability_zone']
  1004. @property
  1005. def hosts(self):
  1006. return [h.host for h in self._hosts]
  1007. @property
  1008. def metadetails(self):
  1009. return {m.key: m.value for m in self._metadata}
  1010. @property
  1011. def availability_zone(self):
  1012. if 'availability_zone' not in self.metadetails:
  1013. return None
  1014. return self.metadetails['availability_zone']
  1015. class AgentBuild(BASE, NovaBase, models.SoftDeleteMixin):
  1016. """Represents an agent build."""
  1017. __tablename__ = 'agent_builds'
  1018. __table_args__ = (
  1019. Index('agent_builds_hypervisor_os_arch_idx', 'hypervisor', 'os',
  1020. 'architecture'),
  1021. schema.UniqueConstraint("hypervisor", "os", "architecture", "deleted",
  1022. name="uniq_agent_builds0hypervisor0os0architecture0deleted"),
  1023. )
  1024. id = Column(Integer, primary_key=True)
  1025. hypervisor = Column(String(255))
  1026. os = Column(String(255))
  1027. architecture = Column(String(255))
  1028. version = Column(String(255))
  1029. url = Column(String(255))
  1030. md5hash = Column(String(255))
  1031. class BandwidthUsage(BASE, NovaBase, models.SoftDeleteMixin):
  1032. """Cache for instance bandwidth usage data pulled from the hypervisor."""
  1033. __tablename__ = 'bw_usage_cache'
  1034. __table_args__ = (
  1035. Index('bw_usage_cache_uuid_start_period_idx', 'uuid',
  1036. 'start_period'),
  1037. )
  1038. id = Column(Integer, primary_key=True, nullable=False)
  1039. uuid = Column(String(36))
  1040. mac = Column(String(255))
  1041. start_period = Column(DateTime, nullable=False)
  1042. last_refreshed = Column(DateTime)
  1043. bw_in = Column(BigInteger)
  1044. bw_out = Column(BigInteger)
  1045. last_ctr_in = Column(BigInteger)
  1046. last_ctr_out = Column(BigInteger)
  1047. class VolumeUsage(BASE, NovaBase, models.SoftDeleteMixin):
  1048. """Cache for volume usage data pulled from the hypervisor."""
  1049. __tablename__ = 'volume_usage_cache'
  1050. __table_args__ = ()
  1051. id = Column(Integer, primary_key=True, nullable=False)
  1052. volume_id = Column(String(36), nullable=False)
  1053. instance_uuid = Column(String(36))
  1054. project_id = Column(String(36))
  1055. user_id = Column(String(64))
  1056. availability_zone = Column(String(255))
  1057. tot_last_refreshed = Column(DateTime)
  1058. tot_reads = Column(BigInteger, default=0)
  1059. tot_read_bytes = Column(BigInteger, default=0)
  1060. tot_writes = Column(BigInteger, default=0)
  1061. tot_write_bytes = Column(BigInteger, default=0)
  1062. curr_last_refreshed = Column(DateTime)
  1063. curr_reads = Column(BigInteger, default=0)
  1064. curr_read_bytes = Column(BigInteger, default=0)
  1065. curr_writes = Column(BigInteger, default=0)
  1066. curr_write_bytes = Column(BigInteger, default=0)
  1067. class S3Image(BASE, NovaBase, models.SoftDeleteMixin):
  1068. """Compatibility layer for the S3 image service talking to Glance."""
  1069. __tablename__ = 's3_images'
  1070. __table_args__ = ()
  1071. id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
  1072. uuid = Column(String(36), nullable=False)
  1073. class VolumeIdMapping(BASE, NovaBase, models.SoftDeleteMixin):
  1074. """Compatibility layer for the EC2 volume service."""
  1075. __tablename__ = 'volume_id_mappings'
  1076. __table_args__ = ()
  1077. id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
  1078. uuid = Column(String(36), nullable=False)
  1079. class SnapshotIdMapping(BASE, NovaBase, models.SoftDeleteMixin):
  1080. """Compatibility layer for the EC2 snapshot service."""
  1081. __tablename__ = 'snapshot_id_mappings'
  1082. __table_args__ = ()
  1083. id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
  1084. uuid = Column(String(36), nullable=False)
  1085. class InstanceFault(BASE, NovaBase, models.SoftDeleteMixin):
  1086. __tablename__ = 'instance_faults'
  1087. __table_args__ = (
  1088. Index('instance_faults_host_idx', 'host'),
  1089. Index('instance_faults_instance_uuid_deleted_created_at_idx',
  1090. 'instance_uuid', 'deleted', 'created_at')
  1091. )
  1092. id = Column(Integer, primary_key=True, nullable=False)
  1093. instance_uuid = Column(String(36),
  1094. ForeignKey('instances.uuid'))
  1095. code = Column(Integer(), nullable=False)
  1096. message = Column(String(255))
  1097. details = Column(MediumText())
  1098. host = Column(String(255))
  1099. class InstanceAction(BASE, NovaBase, models.SoftDeleteMixin):
  1100. """Track client actions on an instance.
  1101. The intention is that there will only be one of these per user request. A
  1102. lookup by (instance_uuid, request_id) should always return a single result.
  1103. """
  1104. __tablename__ = 'instance_actions'
  1105. __table_args__ = (
  1106. Index('instance_uuid_idx', 'instance_uuid'),
  1107. Index('request_id_idx', 'request_id'),
  1108. Index('instance_actions_instance_uuid_updated_at_idx',
  1109. 'instance_uuid', 'updated_at')
  1110. )
  1111. id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
  1112. action = Column(String(255))
  1113. instance_uuid = Column(String(36),
  1114. ForeignKey('instances.uuid'))
  1115. request_id = Column(String(255))
  1116. user_id = Column(String(255))
  1117. project_id = Column(String(255))
  1118. start_time = Column(DateTime, default=timeutils.utcnow)
  1119. finish_time = Column(DateTime)
  1120. message = Column(String(255))
  1121. class InstanceActionEvent(BASE, NovaBase, models.SoftDeleteMixin):
  1122. """Track events that occur during an InstanceAction."""
  1123. __tablename__ = 'instance_actions_events'
  1124. __table_args__ = ()
  1125. id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
  1126. event = Column(String(255))
  1127. action_id = Column(Integer, ForeignKey('instance_actions.id'))
  1128. start_time = Column(DateTime, default=timeutils.utcnow)
  1129. finish_time = Column(DateTime)
  1130. result = Column(String(255))
  1131. traceback = Column(Text)
  1132. host = Column(String(255))
  1133. details = Column(Text)
  1134. class InstanceIdMapping(BASE, NovaBase, models.SoftDeleteMixin):
  1135. """Compatibility layer for the EC2 instance service."""
  1136. __tablename__ = 'instance_id_mappings'
  1137. __table_args__ = (
  1138. Index('ix_instance_id_mappings_uuid', 'uuid'),
  1139. )
  1140. id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
  1141. uuid = Column(String(36), nullable=False)
  1142. class TaskLog(BASE, NovaBase, models.SoftDeleteMixin):
  1143. """Audit log for background periodic tasks."""
  1144. __tablename__ = 'task_log'
  1145. __table_args__ = (
  1146. schema.UniqueConstraint(
  1147. 'task_name', 'host', 'period_beginning', 'period_ending',
  1148. name="uniq_task_log0task_name0host0period_beginning0period_ending"
  1149. ),
  1150. Index('ix_task_log_period_beginning', 'period_beginning'),
  1151. Index('ix_task_log_host', 'host'),
  1152. Index('ix_task_log_period_ending', 'period_ending'),
  1153. )
  1154. id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
  1155. task_name = Column(String(255), nullable=False)
  1156. state = Column(String(255), nullable=False)
  1157. host = Column(String(255), nullable=False)
  1158. period_beginning = Column(DateTime, default=timeutils.utcnow,
  1159. nullable=False)
  1160. period_ending = Column(DateTime, default=timeutils.utcnow,
  1161. nullable=False)
  1162. message = Column(String(255), nullable=False)
  1163. task_items = Column(Integer(), default=0)
  1164. errors = Column(Integer(), default=0)
  1165. # NOTE(alaski): This table exists in the nova_api database and its usage here
  1166. # is deprecated.
  1167. class InstanceGroupMember(BASE, NovaBase, models.SoftDeleteMixin):
  1168. """Represents the members for an instance group."""
  1169. __tablename__ = 'instance_group_member'
  1170. __table_args__ = (
  1171. Index('instance_group_member_instance_idx', 'instance_id'),
  1172. )
  1173. id = Column(Integer, primary_key=True, nullable=False)
  1174. instance_id = Column(String(255))
  1175. group_id = Column(Integer, ForeignKey('instance_groups.id'),
  1176. nullable=False)
  1177. # NOTE(alaski): This table exists in the nova_api database and its usage here
  1178. # is deprecated.
  1179. class InstanceGroupPolicy(BASE, NovaBase, models.SoftDeleteMixin):
  1180. """Represents the policy type for an instance group."""
  1181. __tablename__ = 'instance_group_policy'
  1182. __table_args__ = (
  1183. Index('instance_group_policy_policy_idx', 'policy'),
  1184. )
  1185. id = Column(Integer, primary_key=True, nullable=False)
  1186. policy = Column(String(255))
  1187. group_id = Column(Integer, ForeignKey('instance_groups.id'),
  1188. nullable=False)
  1189. # NOTE(alaski): This table exists in the nova_api database and its usage here
  1190. # is deprecated.
  1191. class InstanceGroup(BASE, NovaBase, models.SoftDeleteMixin):
  1192. """Represents an instance group.
  1193. A group will maintain a collection of instances and the relationship
  1194. between them.
  1195. """
  1196. __tablename__ = 'instance_groups'
  1197. __table_args__ = (
  1198. schema.UniqueConstraint("uuid", "deleted",
  1199. name="uniq_instance_groups0uuid0deleted"),
  1200. )
  1201. id = Column(Integer, primary_key=True, autoincrement=True)
  1202. user_id = Column(String(255))
  1203. project_id = Column(String(255))
  1204. uuid = Column(String(36), nullable=False)
  1205. name = Column(String(255))
  1206. _policies = orm.relationship(InstanceGroupPolicy, primaryjoin='and_('
  1207. 'InstanceGroup.id == InstanceGroupPolicy.group_id,'
  1208. 'InstanceGroupPolicy.deleted == 0,'
  1209. 'InstanceGroup.deleted == 0)')
  1210. _members = orm.relationship(InstanceGroupMember, primaryjoin='and_('
  1211. 'InstanceGroup.id == InstanceGroupMember.group_id,'
  1212. 'InstanceGroupMember.deleted == 0,'
  1213. 'InstanceGroup.deleted == 0)')
  1214. @property
  1215. def policies(self):
  1216. return [p.policy for p in self._policies]
  1217. @property
  1218. def members(self):
  1219. return [m.instance_id for m in self._members]
  1220. class PciDevice(BASE, NovaBase, models.SoftDeleteMixin):
  1221. """Represents a PCI host device that can be passed through to instances.
  1222. """
  1223. __tablename__ = 'pci_devices'
  1224. __table_args__ = (
  1225. Index('ix_pci_devices_compute_node_id_deleted',
  1226. 'compute_node_id', 'deleted'),
  1227. Index('ix_pci_devices_instance_uuid_deleted',
  1228. 'instance_uuid', 'deleted'),
  1229. Index('ix_pci_devices_compute_node_id_parent_addr_deleted',
  1230. 'compute_node_id', 'parent_addr', 'deleted'),
  1231. schema.UniqueConstraint(
  1232. "compute_node_id", "address", "deleted",
  1233. name="uniq_pci_devices0compute_node_id0address0deleted")
  1234. )
  1235. id = Column(Integer, primary_key=True)
  1236. uuid = Column(String(36))
  1237. compute_node_id = Column(Integer, ForeignKey('compute_nodes.id'),
  1238. nullable=False)
  1239. # physical address of device domain:bus:slot.func (0000:09:01.1)
  1240. address = Column(String(12), nullable=False)
  1241. vendor_id = Column(String(4), nullable=False)
  1242. product_id = Column(String(4), nullable=False)
  1243. dev_type = Column(String(8), nullable=False)
  1244. dev_id = Column(String(255))
  1245. # label is abstract device name, that is used to unify devices with the
  1246. # same functionality with different addresses or host.
  1247. label = Column(String(255), nullable=False)
  1248. status = Column(String(36), nullable=False)
  1249. # the request_id is used to identify a device that is allocated for a
  1250. # particular request
  1251. request_id = Column(String(36), nullable=True)
  1252. extra_info = Column(Text)
  1253. instance_uuid = Column(String(36))
  1254. numa_node = Column(Integer, nullable=True)
  1255. parent_addr = Column(String(12), nullable=True)
  1256. instance = orm.relationship(Instance, backref="pci_devices",
  1257. foreign_keys=instance_uuid,
  1258. primaryjoin='and_('
  1259. 'PciDevice.instance_uuid == Instance.uuid,'
  1260. 'PciDevice.deleted == 0)')
  1261. class Tag(BASE, models.ModelBase):
  1262. """Represents the tag for a resource."""
  1263. __tablename__ = "tags"
  1264. __table_args__ = (
  1265. Index('tags_tag_idx', 'tag'),
  1266. )
  1267. resource_id = Column(String(36), primary_key=True, nullable=False)
  1268. tag = Column(Unicode(80), primary_key=True, nullable=False)
  1269. instance = orm.relationship(
  1270. "Instance",
  1271. backref='tags',
  1272. primaryjoin='and_(Tag.resource_id == Instance.uuid,'
  1273. 'Instance.deleted == 0)',
  1274. foreign_keys=resource_id
  1275. )
  1276. # NOTE(alaski): This table exists in the nova_api database and its usage here
  1277. # is deprecated.
  1278. class ResourceProvider(BASE, models.ModelBase):
  1279. """Represents a mapping to a providers of resources."""
  1280. __tablename__ = "resource_providers"
  1281. __table_args__ = (
  1282. Index('resource_providers_uuid_idx', 'uuid'),
  1283. schema.UniqueConstraint('uuid',
  1284. name='uniq_resource_providers0uuid'),
  1285. Index('resource_providers_name_idx', 'name'),
  1286. schema.UniqueConstraint('name',
  1287. name='uniq_resource_providers0name')
  1288. )
  1289. id = Column(Integer, primary_key=True, nullable=False)
  1290. uuid = Column(String(36), nullable=False)
  1291. name = Column(Unicode(200), nullable=True)
  1292. generation = Column(Integer, default=0)
  1293. can_host = Column(Integer, default=0)
  1294. # NOTE(alaski): This table exists in the nova_api database and its usage here
  1295. # is deprecated.
  1296. class Inventory(BASE, models.ModelBase):
  1297. """Represents a quantity of available resource."""
  1298. __tablename__ = "inventories"
  1299. __table_args__ = (
  1300. Index('inventories_resource_provider_id_idx',
  1301. 'resource_provider_id'),
  1302. Index('inventories_resource_class_id_idx',
  1303. 'resource_class_id'),
  1304. Index('inventories_resource_provider_resource_class_idx',
  1305. 'resource_provider_id', 'resource_class_id'),
  1306. schema.UniqueConstraint('resource_provider_id', 'resource_class_id',
  1307. name='uniq_inventories0resource_provider_resource_class')
  1308. )
  1309. id = Column(Integer, primary_key=True, nullable=False)
  1310. resource_provider_id = Column(Integer, nullable=False)
  1311. resource_class_id = Column(Integer, nullable=False)
  1312. total = Column(Integer, nullable=False)
  1313. reserved = Column(Integer, nullable=False)
  1314. min_unit = Column(Integer, nullable=False)
  1315. max_unit = Column(Integer, nullable=False)
  1316. step_size = Column(Integer, nullable=False)
  1317. allocation_ratio = Column(Float, nullable=False)
  1318. resource_provider = orm.relationship(
  1319. "ResourceProvider",
  1320. primaryjoin=('and_(Inventory.resource_provider_id == '
  1321. 'ResourceProvider.id)'),
  1322. foreign_keys=resource_provider_id)
  1323. # NOTE(alaski): This table exists in the nova_api database and its usage here
  1324. # is deprecated.
  1325. class Allocation(BASE, models.ModelBase):
  1326. """A use of inventory."""
  1327. __tablename__ = "allocations"
  1328. __table_args__ = (
  1329. Index('allocations_resource_provider_class_used_idx',
  1330. 'resource_provider_id', 'resource_class_id',
  1331. 'used'),
  1332. Index('allocations_resource_class_id_idx',
  1333. 'resource_class_id'),
  1334. Index('allocations_consumer_id_idx', 'consumer_id')
  1335. )
  1336. id = Column(Integer, primary_key=True, nullable=False)
  1337. resource_provider_id = Column(Integer, nullable=False)
  1338. consumer_id = Column(String(36), nullable=False)
  1339. resource_class_id = Column(Integer, nullable=False)
  1340. used = Column(Integer, nullable=False)
  1341. # NOTE(alaski): This table exists in the nova_api database and its usage here
  1342. # is deprecated.
  1343. class ResourceProviderAggregate(BASE, models.ModelBase):
  1344. """Associate a resource provider with an aggregate."""
  1345. __tablename__ = 'resource_provider_aggregates'
  1346. __table_args__ = (
  1347. Index('resource_provider_aggregates_aggregate_id_idx',
  1348. 'aggregate_id'),
  1349. )
  1350. resource_provider_id = Column(Integer, primary_key=True, nullable=False)
  1351. aggregate_id = Column(Integer, primary_key=True, nullable=False)
  1352. class ConsoleAuthToken(BASE, NovaBase):
  1353. """Represents a console auth token"""
  1354. __tablename__ = 'console_auth_tokens'
  1355. __table_args__ = (
  1356. Index('console_auth_tokens_instance_uuid_idx', 'instance_uuid'),
  1357. Index('console_auth_tokens_host_expires_idx', 'host', 'expires'),
  1358. Index('console_auth_tokens_token_hash_idx', 'token_hash'),
  1359. Index('console_auth_tokens_token_hash_instance_uuid_idx', 'token_hash',
  1360. 'instance_uuid'),
  1361. schema.UniqueConstraint("token_hash",
  1362. name="uniq_console_auth_tokens0token_hash")
  1363. )
  1364. id = Column(Integer, primary_key=True, nullable=False)
  1365. token_hash = Column(String(255), nullable=False)
  1366. console_type = Column(String(255), nullable=False)
  1367. host = Column(String(255), nullable=False)
  1368. port = Column(Integer, nullable=False)
  1369. internal_access_path = Column(String(255))
  1370. instance_uuid = Column(String(36), nullable=False)
  1371. expires = Column(Integer, nullable=False)
  1372. access_url_base = Column(String(255))
  1373. instance = orm.relationship(
  1374. "Instance",
  1375. backref='console_auth_tokens',
  1376. primaryjoin='and_(ConsoleAuthToken.instance_uuid == Instance.uuid,'
  1377. 'Instance.deleted == 0)',
  1378. foreign_keys=instance_uuid
  1379. )