~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/db/sqlalchemy/models.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
300
300
                            primaryjoin=instance_id == Instance.uuid)
301
301
 
302
302
 
303
 
class InstanceActions(BASE, NovaBase):
304
 
    """Represents a guest VM's actions and results"""
305
 
    __tablename__ = "instance_actions"
306
 
    id = Column(Integer, primary_key=True)
307
 
    instance_uuid = Column(String(36), ForeignKey('instances.uuid'))
308
 
    action = Column(String(255))
309
 
    error = Column(Text)
310
 
 
311
 
 
312
303
class InstanceTypes(BASE, NovaBase):
313
304
    """Represent possible instance_types or flavor of VM offered"""
314
305
    __tablename__ = "instance_types"
335
326
class Volume(BASE, NovaBase):
336
327
    """Represents a block storage device that can be attached to a vm."""
337
328
    __tablename__ = 'volumes'
338
 
    id = Column(Integer, primary_key=True, autoincrement=True)
 
329
    id = Column(String(36), primary_key=True)
339
330
 
340
331
    @property
341
332
    def name(self):
342
333
        return FLAGS.volume_name_template % self.id
343
334
 
 
335
    ec2_id = Column(Integer)
344
336
    user_id = Column(String(255))
345
337
    project_id = Column(String(255))
346
338
 
347
 
    snapshot_id = Column(String(255))
 
339
    snapshot_id = Column(String(36))
348
340
 
349
341
    host = Column(String(255))  # , ForeignKey('hosts.id'))
350
342
    size = Column(Integer)
351
343
    availability_zone = Column(String(255))  # TODO(vish): foreign key?
352
 
    instance_id = Column(Integer, ForeignKey('instances.id'), nullable=True)
353
 
    instance = relationship(Instance,
354
 
                            backref=backref('volumes'),
355
 
                            foreign_keys=instance_id,
356
 
                            primaryjoin='and_(Volume.instance_id==Instance.id,'
357
 
                                             'Volume.deleted==False)')
 
344
    instance_uuid = Column(String(36))
358
345
    mountpoint = Column(String(255))
359
346
    attach_time = Column(String(255))  # TODO(vish): datetime
360
347
    status = Column(String(255))  # TODO(vish): enum?
379
366
    id = Column(Integer, primary_key=True)
380
367
    key = Column(String(255))
381
368
    value = Column(String(255))
382
 
    volume_id = Column(Integer, ForeignKey('volumes.id'), nullable=False)
 
369
    volume_id = Column(String(36), ForeignKey('volumes.id'), nullable=False)
383
370
    volume = relationship(Volume, backref="volume_metadata",
384
371
                            foreign_keys=volume_id,
385
372
                            primaryjoin='and_('
419
406
class Quota(BASE, NovaBase):
420
407
    """Represents a single quota override for a project.
421
408
 
422
 
    If there is no row for a given project id and resource, then
423
 
    the default for the deployment is used. If the row is present
424
 
    but the hard limit is Null, then the resource is unlimited.
 
409
    If there is no row for a given project id and resource, then the
 
410
    default for the quota class is used.  If there is no row for a
 
411
    given quota class and resource, then the default for the
 
412
    deployment is used. If the row is present but the hard limit is
 
413
    Null, then the resource is unlimited.
425
414
    """
426
415
 
427
416
    __tablename__ = 'quotas'
433
422
    hard_limit = Column(Integer, nullable=True)
434
423
 
435
424
 
 
425
class QuotaClass(BASE, NovaBase):
 
426
    """Represents a single quota override for a quota class.
 
427
 
 
428
    If there is no row for a given quota class and resource, then the
 
429
    default for the deployment is used.  If the row is present but the
 
430
    hard limit is Null, then the resource is unlimited.
 
431
    """
 
432
 
 
433
    __tablename__ = 'quota_classes'
 
434
    id = Column(Integer, primary_key=True)
 
435
 
 
436
    class_name = Column(String(255), index=True)
 
437
 
 
438
    resource = Column(String(255))
 
439
    hard_limit = Column(Integer, nullable=True)
 
440
 
 
441
 
 
442
class QuotaUsage(BASE, NovaBase):
 
443
    """Represents the current usage for a given resource."""
 
444
 
 
445
    __tablename__ = 'quota_usages'
 
446
    id = Column(Integer, primary_key=True)
 
447
 
 
448
    project_id = Column(String(255), index=True)
 
449
    resource = Column(String(255))
 
450
 
 
451
    in_use = Column(Integer)
 
452
    reserved = Column(Integer)
 
453
 
 
454
    @property
 
455
    def total(self):
 
456
        return self.in_use + self.reserved
 
457
 
 
458
    until_refresh = Column(Integer, nullable=True)
 
459
 
 
460
 
 
461
class Reservation(BASE, NovaBase):
 
462
    """Represents a resource reservation for quotas."""
 
463
 
 
464
    __tablename__ = 'reservations'
 
465
    id = Column(Integer, primary_key=True)
 
466
    uuid = Column(String(36), nullable=False)
 
467
 
 
468
    usage_id = Column(Integer, ForeignKey('quota_usages.id'), nullable=False)
 
469
    usage = relationship(QuotaUsage,
 
470
                         backref=backref('reservations'),
 
471
                         foreign_keys=usage_id,
 
472
                         primaryjoin='and_('
 
473
                              'Reservation.usage_id == QuotaUsage.id,'
 
474
                              'Reservation.deleted == False)')
 
475
 
 
476
    project_id = Column(String(255), index=True)
 
477
    resource = Column(String(255))
 
478
 
 
479
    delta = Column(Integer)
 
480
    expire = Column(DateTime, nullable=False)
 
481
 
 
482
 
436
483
class Snapshot(BASE, NovaBase):
437
484
    """Represents a block storage device that can be attached to a vm."""
438
485
    __tablename__ = 'snapshots'
439
 
    id = Column(Integer, primary_key=True, autoincrement=True)
 
486
    id = Column(String(36), primary_key=True)
440
487
 
441
488
    @property
442
489
    def name(self):
449
496
    user_id = Column(String(255))
450
497
    project_id = Column(String(255))
451
498
 
452
 
    volume_id = Column(Integer)
 
499
    volume_id = Column(String(36))
453
500
    status = Column(String(255))
454
501
    progress = Column(String(255))
455
502
    volume_size = Column(Integer)
463
510
    __tablename__ = "block_device_mapping"
464
511
    id = Column(Integer, primary_key=True, autoincrement=True)
465
512
 
466
 
    instance_id = Column(Integer, ForeignKey('instances.id'), nullable=False)
 
513
    instance_uuid = Column(Integer, ForeignKey('instances.uuid'),
 
514
                           nullable=False)
467
515
    instance = relationship(Instance,
468
516
                            backref=backref('balock_device_mapping'),
469
 
                            foreign_keys=instance_id,
470
 
                            primaryjoin='and_(BlockDeviceMapping.instance_id=='
471
 
                                              'Instance.id,'
 
517
                            foreign_keys=instance_uuid,
 
518
                            primaryjoin='and_(BlockDeviceMapping.'
 
519
                                              'instance_uuid=='
 
520
                                              'Instance.uuid,'
472
521
                                              'BlockDeviceMapping.deleted=='
473
522
                                              'False)')
474
523
    device_name = Column(String(255), nullable=False)
482
531
    # for ephemeral device
483
532
    virtual_name = Column(String(255), nullable=True)
484
533
 
485
 
    # for snapshot or volume
486
 
    snapshot_id = Column(Integer, ForeignKey('snapshots.id'), nullable=True)
487
 
    # outer join
488
 
    snapshot = relationship(Snapshot,
489
 
                            foreign_keys=snapshot_id)
 
534
    snapshot_id = Column(String(36))
490
535
 
491
 
    volume_id = Column(Integer, ForeignKey('volumes.id'), nullable=True)
492
 
    volume = relationship(Volume,
493
 
                          foreign_keys=volume_id)
 
536
    volume_id = Column(String(36), nullable=True)
494
537
    volume_size = Column(Integer, nullable=True)
495
538
 
496
539
    # for no device to suppress devices.
507
550
    id = Column(Integer, primary_key=True)
508
551
    target_num = Column(Integer)
509
552
    host = Column(String(255))
510
 
    volume_id = Column(Integer, ForeignKey('volumes.id'), nullable=True)
 
553
    volume_id = Column(String(36), ForeignKey('volumes.id'), nullable=True)
511
554
    volume = relationship(Volume,
512
555
                          backref=backref('iscsi_target', uselist=False),
513
556
                          foreign_keys=volume_id,
809
852
 
810
853
 
811
854
class InstanceMetadata(BASE, NovaBase):
812
 
    """Represents a metadata key/value pair for an instance"""
 
855
    """Represents a user-provided metadata key/value pair for an instance"""
813
856
    __tablename__ = 'instance_metadata'
814
857
    id = Column(Integer, primary_key=True)
815
858
    key = Column(String(255))
822
865
                                'InstanceMetadata.deleted == False)')
823
866
 
824
867
 
 
868
class InstanceSystemMetadata(BASE, NovaBase):
 
869
    """Represents a system-owned metadata key/value pair for an instance"""
 
870
    __tablename__ = 'instance_system_metadata'
 
871
    id = Column(Integer, primary_key=True)
 
872
    key = Column(String(255))
 
873
    value = Column(String(255))
 
874
    instance_uuid = Column(String(36),
 
875
                           ForeignKey('instances.uuid'),
 
876
                           nullable=False)
 
877
 
 
878
    primary_join = ('and_(InstanceSystemMetadata.instance_uuid == '
 
879
                    'Instance.uuid, InstanceSystemMetadata.deleted == False)')
 
880
    instance = relationship(Instance, backref="system_metadata",
 
881
                            foreign_keys=instance_uuid,
 
882
                            primaryjoin=primary_join)
 
883
 
 
884
 
825
885
class InstanceTypeExtraSpecs(BASE, NovaBase):
826
886
    """Represents additional specs as key/value pairs for an instance_type"""
827
887
    __tablename__ = 'instance_type_extra_specs'
926
986
    """Cache for instance bandwidth usage data pulled from the hypervisor"""
927
987
    __tablename__ = 'bw_usage_cache'
928
988
    id = Column(Integer, primary_key=True, nullable=False)
 
989
    uuid = Column(String(36), nullable=False)
929
990
    mac = Column(String(255), nullable=False)
930
991
    start_period = Column(DateTime, nullable=False)
931
992
    last_refreshed = Column(DateTime)
940
1001
    uuid = Column(String(36), nullable=False)
941
1002
 
942
1003
 
 
1004
class VolumeIdMapping(BASE, NovaBase):
 
1005
    """Compatability layer for the EC2 volume service"""
 
1006
    __tablename__ = 'volume_id_mappings'
 
1007
    id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
 
1008
    uuid = Column(String(36), nullable=False)
 
1009
 
 
1010
 
 
1011
class SnapshotIdMapping(BASE, NovaBase):
 
1012
    """Compatability layer for the EC2 snapshot service"""
 
1013
    __tablename__ = 'snapshot_id_mappings'
 
1014
    id = Column(Integer, primary_key=True, nullable=False, autoincrement=True)
 
1015
    uuid = Column(String(36), nullable=False)
 
1016
 
 
1017
 
943
1018
class SMFlavors(BASE, NovaBase):
944
1019
    """Represents a flavor for SM volumes."""
945
1020
    __tablename__ = 'sm_flavors'
960
1035
 
961
1036
class SMVolume(BASE, NovaBase):
962
1037
    __tablename__ = 'sm_volume'
963
 
    id = Column(Integer(), ForeignKey(Volume.id), primary_key=True)
 
1038
    id = Column(String(36), ForeignKey(Volume.id), primary_key=True)
964
1039
    backend_id = Column(Integer, ForeignKey('sm_backend_config.id'),
965
1040
                        nullable=False)
966
1041
    vdi_uuid = Column(String(255))
997
1072
              FixedIp,
998
1073
              FloatingIp,
999
1074
              Instance,
1000
 
              InstanceActions,
1001
1075
              InstanceFault,
1002
1076
              InstanceMetadata,
1003
1077
              InstanceTypeExtraSpecs,
1018
1092
              VolumeMetadata,
1019
1093
              VolumeTypeExtraSpecs,
1020
1094
              VolumeTypes,
 
1095
              VolumeIdMapping,
 
1096
              SnapshotIdMapping,
1021
1097
              )
1022
1098
    engine = create_engine(FLAGS.sql_connection, echo=False)
1023
1099
    for model in models: