return IMPL.service_get_all_by_topic(context, topic, disabled=disabled)
-def service_get_all_by_host(context, host):
- """Get all services for a given host."""
- return IMPL.service_get_all_by_host(context, host)
-
-
-def service_get_all_volume_sorted(context):
- """Get all volume services sorted by volume count.
-
- :returns: a list of (Service, volume_count) tuples.
-
- """
- return IMPL.service_get_all_volume_sorted(context)
-
-
def service_get_by_args(context, host, binary):
"""Get the state of an service by node name and binary."""
return IMPL.service_get_by_args(context, host, binary)
###############
-def volume_allocate_iscsi_target(context, volume_id, host):
- """Atomically allocate a free iscsi_target from the pool."""
- return IMPL.volume_allocate_iscsi_target(context, volume_id, host)
-
def volume_attached(context, volume_id, instance_id, host_name, mountpoint):
"""Ensure that a volume is set as attached."""
return IMPL.consistencygroup_get_all(context)
-def consistencygroup_get_all_by_host(context, host):
- """Get all consistencygroups belonging to a host."""
- return IMPL.consistencygroup_get_all_by_host(context, host)
-
-
def consistencygroup_create(context, values):
"""Create a consistencygroup from the values dictionary."""
return IMPL.consistencygroup_create(context, values)
return IMPL.cgsnapshot_get_all(context)
-def cgsnapshot_get_all_by_host(context, host):
- """Get all cgsnapshots belonging to a host."""
- return IMPL.cgsnapshot_get_all_by_host(context, host)
-
-
def cgsnapshot_create(context, values):
"""Create a cgsnapshot from the values dictionary."""
return IMPL.cgsnapshot_create(context, values)
return result
-@require_admin_context
-def service_get_all_by_host(context, host):
- return model_query(
- context, models.Service, read_deleted="no").\
- filter_by(host=host).\
- all()
-
-
@require_admin_context
def _service_get_all_topic_subquery(context, session, topic, subq, label):
sort_value = getattr(subq.c, label)
all()
-@require_admin_context
-def service_get_all_volume_sorted(context):
- session = get_session()
- with session.begin():
- topic = CONF.volume_topic
- label = 'volume_gigabytes'
- subq = model_query(context, models.Volume.host,
- func.sum(models.Volume.size).label(label),
- session=session, read_deleted="no").\
- group_by(models.Volume.host).\
- subquery()
- return _service_get_all_topic_subquery(context,
- session,
- topic,
- subq,
- label)
-
-
@require_admin_context
def service_get_by_args(context, host, binary):
result = model_query(context, models.Service).\
###################
-@require_admin_context
-@_retry_on_deadlock
-def volume_allocate_iscsi_target(context, volume_id, host):
- session = get_session()
- with session.begin():
- iscsi_target_ref = model_query(context, models.IscsiTarget,
- session=session, read_deleted="no").\
- filter_by(volume=None).\
- filter_by(host=host).\
- with_lockmode('update').\
- first()
-
- # NOTE(vish): if with_lockmode isn't supported, as in sqlite,
- # then this has concurrency issues
- if not iscsi_target_ref:
- raise exception.NoMoreTargets()
-
- iscsi_target_ref.volume_id = volume_id
- session.add(iscsi_target_ref)
-
- return iscsi_target_ref.target_num
-
-
@require_admin_context
def volume_attached(context, volume_id, instance_uuid, host_name, mountpoint):
if instance_uuid and not uuidutils.is_uuid_like(instance_uuid):
return model_query(context, models.ConsistencyGroup).all()
-@require_admin_context
-def consistencygroup_get_all_by_host(context, host):
- return model_query(context, models.ConsistencyGroup).\
- filter_by(host=host).all()
-
-
@require_context
def consistencygroup_get_all_by_project(context, project_id):
authorize_project_context(context, project_id)
return model_query(context, models.Cgsnapshot).all()
-@require_admin_context
-def cgsnapshot_get_all_by_host(context, host):
- return model_query(context, models.Cgsnapshot).filter_by(host=host).all()
-
-
@require_admin_context
def cgsnapshot_get_all_by_group(context, group_id):
return model_query(context, models.Cgsnapshot).\
real = db.service_get_all_by_topic(self.ctxt, 't1')
self._assertEqualListsOfObjects(expected, real)
- def test_service_get_all_by_host(self):
- values = [
- {'host': 'host1', 'topic': 't1'},
- {'host': 'host1', 'topic': 't1'},
- {'host': 'host2', 'topic': 't1'},
- {'host': 'host3', 'topic': 't2'}
- ]
- services = [self._create_service(vals) for vals in values]
-
- expected = services[:2]
- real = db.service_get_all_by_host(self.ctxt, 'host1')
- self._assertEqualListsOfObjects(expected, real)
-
def test_service_get_by_args(self):
values = [
{'host': 'host1', 'binary': 'a'},
db.service_get_by_args,
self.ctxt, 'non-exists-host', 'a')
- def test_service_get_all_volume_sorted(self):
- values = [
- ({'host': 'h1', 'binary': 'a', 'topic': CONF.volume_topic},
- 100),
- ({'host': 'h2', 'binary': 'b', 'topic': CONF.volume_topic},
- 200),
- ({'host': 'h3', 'binary': 'b', 'topic': CONF.volume_topic},
- 300)]
- services = []
- for vals, size in values:
- services.append(self._create_service(vals))
- db.volume_create(self.ctxt, {'host': vals['host'], 'size': size})
- for service, size in db.service_get_all_volume_sorted(self.ctxt):
- self._assertEqualObjects(services.pop(0), service)
- self.assertEqual(values.pop(0)[1], size)
-
class DBAPIVolumeTestCase(BaseTest):
self.assertTrue(uuidutils.is_uuid_like(volume['id']))
self.assertEqual(volume.host, 'host1')
- def test_volume_allocate_iscsi_target_no_more_targets(self):
- self.assertRaises(exception.NoMoreTargets,
- db.volume_allocate_iscsi_target,
- self.ctxt, 42, 'host1')
-
- def test_volume_allocate_iscsi_target(self):
- host = 'host1'
- volume = db.volume_create(self.ctxt, {'host': host})
- db.iscsi_target_create_safe(self.ctxt, {'host': host,
- 'target_num': 42})
- target_num = db.volume_allocate_iscsi_target(self.ctxt, volume['id'],
- host)
- self.assertEqual(target_num, 42)
-
def test_volume_attached_invalid_uuid(self):
self.assertRaises(exception.InvalidUUID, db.volume_attached, self.ctxt,
42, 'invalid-uuid', None, '/tmp')