diff options
| author | Vishvananda Ishaya <vishvananda@yahoo.com> | 2010-09-11 20:00:56 -0700 |
|---|---|---|
| committer | Vishvananda Ishaya <vishvananda@yahoo.com> | 2010-09-11 20:00:56 -0700 |
| commit | 3aae714e4feb4a29ac7d2aed78aef37b3385300c (patch) | |
| tree | 1747e2ae3a42865c2d012d3805000ab0318f4bbb /nova/db | |
| parent | ef1913292dd8a88041f603d79c09c738a7ecbb04 (diff) | |
| parent | 15ca1fe1670cfd95880f2e1c2a5270be787c6035 (diff) | |
| download | nova-3aae714e4feb4a29ac7d2aed78aef37b3385300c.tar.gz nova-3aae714e4feb4a29ac7d2aed78aef37b3385300c.tar.xz nova-3aae714e4feb4a29ac7d2aed78aef37b3385300c.zip | |
merged scheduler
Diffstat (limited to 'nova/db')
| -rw-r--r-- | nova/db/api.py | 38 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 82 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/models.py | 35 |
3 files changed, 145 insertions, 10 deletions
diff --git a/nova/db/api.py b/nova/db/api.py index 1b477da72..9f6ff99c3 100644 --- a/nova/db/api.py +++ b/nova/db/api.py @@ -125,6 +125,11 @@ def floating_ip_create(context, values): return IMPL.floating_ip_create(context, values) +def floating_ip_count_by_project(context, project_id): + """Count floating ips used by project.""" + return IMPL.floating_ip_count_by_project(context, project_id) + + def floating_ip_deallocate(context, address): """Deallocate an floating ip by address""" return IMPL.floating_ip_deallocate(context, address) @@ -227,6 +232,11 @@ def instance_create(context, values): return IMPL.instance_create(context, values) +def instance_data_get_for_project(context, project_id): + """Get (instance_count, core_count) for project.""" + return IMPL.instance_data_get_for_project(context, project_id) + + def instance_destroy(context, instance_id): """Destroy the instance or raise if it does not exist.""" return IMPL.instance_destroy(context, instance_id) @@ -411,6 +421,29 @@ def export_device_create(context, values): ################### +def quota_create(context, values): + """Create a quota from the values dictionary.""" + return IMPL.quota_create(context, values) + + +def quota_get(context, project_id): + """Retrieve a quota or raise if it does not exist.""" + return IMPL.quota_get(context, project_id) + + +def quota_update(context, project_id, values): + """Update a quota from the values dictionary.""" + return IMPL.quota_update(context, project_id, values) + + +def quota_destroy(context, project_id): + """Destroy the quota or raise if it does not exist.""" + return IMPL.quota_destroy(context, project_id) + + +################### + + def volume_allocate_shelf_and_blade(context, volume_id): """Atomically allocate a free shelf and blade from the pool.""" return IMPL.volume_allocate_shelf_and_blade(context, volume_id) @@ -426,6 +459,11 @@ def volume_create(context, values): return IMPL.volume_create(context, values) +def volume_data_get_for_project(context, project_id): + """Get (volume_count, gigabytes) for project.""" + return IMPL.volume_data_get_for_project(context, project_id) + + def volume_destroy(context, volume_id): """Destroy the volume or raise if it does not exist.""" return IMPL.volume_destroy(context, volume_id) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index 735e88145..d612fe669 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -67,7 +67,7 @@ def service_get_all_by_topic(context, topic): def _service_get_all_topic_subquery(_context, session, topic, subq, label): sort_value = getattr(subq.c, label) - return session.query(models.Service, sort_value + return session.query(models.Service, func.coalesce(sort_value, 0) ).filter_by(topic=topic ).filter_by(deleted=False ).outerjoin((subq, models.Service.host == subq.c.host) @@ -79,15 +79,16 @@ def service_get_all_compute_sorted(context): session = get_session() with session.begin(): # NOTE(vish): The intended query is below - # SELECT services.*, inst_count.instance_count + # SELECT services.*, COALESCE(inst_cores.instance_cores, + # 0) # FROM services LEFT OUTER JOIN - # (SELECT host, count(*) AS instance_count - # FROM instances GROUP BY host) AS inst_count - # ON services.host = inst_count.host + # (SELECT host, SUM(instances.vcpus) AS instance_cores + # FROM instances GROUP BY host) AS inst_cores + # ON services.host = inst_cores.host topic = 'compute' - label = 'instance_count' + label = 'instance_cores' subq = session.query(models.Instance.host, - func.count('*').label(label) + func.sum(models.Instance.vcpus).label(label) ).filter_by(deleted=False ).group_by(models.Instance.host ).subquery() @@ -104,7 +105,7 @@ def service_get_all_network_sorted(context): topic = 'network' label = 'network_count' subq = session.query(models.Network.host, - func.count('*').label(label) + func.count(models.Network.id).label(label) ).filter_by(deleted=False ).group_by(models.Network.host ).subquery() @@ -119,9 +120,9 @@ def service_get_all_volume_sorted(context): session = get_session() with session.begin(): topic = 'volume' - label = 'volume_count' + label = 'volume_gigabytes' subq = session.query(models.Volume.host, - func.count('*').label(label) + func.sum(models.Volume.size).label(label) ).filter_by(deleted=False ).group_by(models.Volume.host ).subquery() @@ -182,6 +183,14 @@ def floating_ip_create(_context, values): return floating_ip_ref['address'] +def floating_ip_count_by_project(_context, project_id): + session = get_session() + return session.query(models.FloatingIp + ).filter_by(project_id=project_id + ).filter_by(deleted=False + ).count() + + def floating_ip_fixed_ip_associate(_context, floating_address, fixed_address): session = get_session() with session.begin(): @@ -351,6 +360,17 @@ def instance_create(_context, values): return instance_ref +def instance_data_get_for_project(_context, project_id): + session = get_session() + result = session.query(func.count(models.Instance.id), + func.sum(models.Instance.vcpus) + ).filter_by(project_id=project_id + ).filter_by(deleted=False + ).first() + # NOTE(vish): convert None to 0 + return (result[0] or 0, result[1] or 0) + + def instance_destroy(_context, instance_id): session = get_session() with session.begin(): @@ -621,6 +641,37 @@ def export_device_create(_context, values): ################### +def quota_create(_context, values): + quota_ref = models.Quota() + for (key, value) in values.iteritems(): + quota_ref[key] = value + quota_ref.save() + return quota_ref + + +def quota_get(_context, project_id): + return models.Quota.find_by_str(project_id) + + +def quota_update(_context, project_id, values): + session = get_session() + with session.begin(): + quota_ref = models.Quota.find_by_str(project_id, session=session) + for (key, value) in values.iteritems(): + quota_ref[key] = value + quota_ref.save(session=session) + + +def quota_destroy(_context, project_id): + session = get_session() + with session.begin(): + quota_ref = models.Quota.find_by_str(project_id, session=session) + quota_ref.delete(session=session) + + +################### + + def volume_allocate_shelf_and_blade(_context, volume_id): session = get_session() with session.begin(): @@ -658,6 +709,17 @@ def volume_create(_context, values): return volume_ref +def volume_data_get_for_project(_context, project_id): + session = get_session() + result = session.query(func.count(models.Volume.id), + func.sum(models.Volume.size) + ).filter_by(project_id=project_id + ).filter_by(deleted=False + ).first() + # NOTE(vish): convert None to 0 + return (result[0] or 0, result[1] or 0) + + def volume_destroy(_context, volume_id): session = get_session() with session.begin(): diff --git a/nova/db/sqlalchemy/models.py b/nova/db/sqlalchemy/models.py index c16f684fe..41013f41b 100644 --- a/nova/db/sqlalchemy/models.py +++ b/nova/db/sqlalchemy/models.py @@ -229,6 +229,11 @@ class Instance(BASE, NovaBase): state = Column(Integer) state_description = Column(String(255)) + memory_mb = Column(Integer) + vcpus = Column(Integer) + local_gb = Column(Integer) + + hostname = Column(String(255)) host = Column(String(255)) # , ForeignKey('hosts.id')) @@ -277,6 +282,36 @@ class Volume(BASE, NovaBase): launched_at = Column(DateTime) terminated_at = Column(DateTime) +class Quota(BASE, NovaBase): + """Represents quota overrides for a project""" + __tablename__ = 'quotas' + id = Column(Integer, primary_key=True) + + project_id = Column(String(255)) + + instances = Column(Integer) + cores = Column(Integer) + volumes = Column(Integer) + gigabytes = Column(Integer) + floating_ips = Column(Integer) + + @property + def str_id(self): + return self.project_id + + @classmethod + def find_by_str(cls, str_id, session=None, deleted=False): + if not session: + session = get_session() + try: + return session.query(cls + ).filter_by(project_id=str_id + ).filter_by(deleted=deleted + ).one() + except exc.NoResultFound: + new_exc = exception.NotFound("No model for project_id %s" % str_id) + raise new_exc.__class__, new_exc, sys.exc_info()[2] + class ExportDevice(BASE, NovaBase): """Represates a shelf and blade that a volume can be exported on""" __tablename__ = 'export_devices' |
