def test_volume_data_get_for_host(self): for i in xrange(3): for j in xrange(3): db.volume_create(self.ctxt, {'host': 'h%d' % i, 'size': 100}) for i in xrange(3): self.assertEqual((3, 300), db.volume_data_get_for_host(self.ctxt, 'h%d' % i))
def show(self, req, id): """Shows the volume usage info given by hosts. :param context: security context :param host: hostname :returns: expected to use HostShowTemplate. ex.:: {'host': {'resource':D},..} D: {'host': 'hostname','project': 'admin', 'volume_count': 1, 'total_volume_gb': 2048} """ host = id context = req.environ['cinder.context'] if not context.is_admin: msg = _("Describe-resource is admin only functionality") raise webob.exc.HTTPForbidden(explanation=msg) try: host_ref = db.service_get_by_host_and_topic(context, host, CONF.volume_topic) except exception.ServiceNotFound: raise webob.exc.HTTPNotFound(explanation=_("Host not found")) # Getting total available/used resource # TODO(jdg): Add summary info for Snapshots volume_refs = db.volume_get_all_by_host(context, host_ref['host']) (count, sum) = db.volume_data_get_for_host(context, host_ref['host']) snap_count_total = 0 snap_sum_total = 0 resources = [{'resource': {'host': host, 'project': '(total)', 'volume_count': str(count), 'total_volume_gb': str(sum), 'snapshot_count': str(snap_count_total), 'total_snapshot_gb': str(snap_sum_total)}}] project_ids = [v['project_id'] for v in volume_refs] project_ids = list(set(project_ids)) for project_id in project_ids: (count, sum) = db.volume_data_get_for_project(context, project_id) (snap_count, snap_sum) = db.snapshot_data_get_for_project( context, project_id) resources.append( {'resource': {'host': host, 'project': project_id, 'volume_count': str(count), 'total_volume_gb': str(sum), 'snapshot_count': str(snap_count), 'total_snapshot_gb': str(snap_sum)}}) snap_count_total += int(snap_count) snap_sum_total += int(snap_sum) resources[0]['resource']['snapshot_count'] = str(snap_count_total) resources[0]['resource']['total_snapshot_gb'] = str(snap_sum_total) return {"host": resources}
def test_volume_data_get_for_host(self): for i in xrange(3): for j in xrange(3): db.volume_create(self.ctxt, {'host': 'h%d' % i, 'size': 100}) for i in xrange(3): self.assertEqual((3, 300), db.volume_data_get_for_host( self.ctxt, 'h%d' % i))
def _weigh_object(self, host_state, weight_properties): """Less volume number weights win. We want spreading to be the default. """ context = weight_properties['context'] volume_number = db.volume_data_get_for_host(context=context, host=host_state.host, count_only=True) return volume_number
def show(self, req, id): """Shows the volume usage info given by hosts. :param req: security context :param id: hostname :returns: dict -- the host resources dictionary. ex.:: {'host': [{'resource': D},..]} D: {'host': 'hostname','project': 'admin', 'volume_count': 1, 'total_volume_gb': 2048} """ host = id context = req.environ['cinder.context'] context.authorize(policy.MANAGE_POLICY) # Not found exception will be handled at the wsgi level host_ref = objects.Service.get_by_host_and_topic( context, host, constants.VOLUME_TOPIC) # Getting total available/used resource on a host. volume_refs = db.volume_get_all_by_host(context, host_ref.host) (count, vol_sum) = db.volume_data_get_for_host(context, host_ref.host) snap_count_total = 0 snap_sum_total = 0 resources = [{'resource': {'host': host, 'project': '(total)', 'volume_count': str(count), 'total_volume_gb': str(vol_sum), 'snapshot_count': str(snap_count_total), 'total_snapshot_gb': str(snap_sum_total)}}] project_ids = [v['project_id'] for v in volume_refs] project_ids = list(set(project_ids)) for project_id in project_ids: (count, vol_sum) = db.volume_data_get_for_project( context, project_id, host=host_ref.host) (snap_count, snap_sum) = ( objects.Snapshot.snapshot_data_get_for_project( context, project_id, host=host_ref.host)) resources.append( {'resource': {'host': host, 'project': project_id, 'volume_count': str(count), 'total_volume_gb': str(vol_sum), 'snapshot_count': str(snap_count), 'total_snapshot_gb': str(snap_sum)}}) snap_count_total += int(snap_count) snap_sum_total += int(snap_sum) resources[0]['resource']['snapshot_count'] = str(snap_count_total) resources[0]['resource']['total_snapshot_gb'] = str(snap_sum_total) return {"host": resources}
def test_volume_data_get_for_host(self): for i in xrange(3): for j in xrange(3): db.volume_create(self.ctxt, {"host": "h%d" % i, "size": 100}) for i in xrange(3): self.assertEqual((3, 300), db.volume_data_get_for_host(self.ctxt, "h%d" % i))