def show(self, req, id): """Shows the storage 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', 'storage_count': 1, 'total_storage_gb': 2048} """ host = id context = req.environ['vsm.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, FLAGS.storage_topic) except exception.ServiceNotFound: raise webob.exc.HTTPNotFound(explanation=_("Host not found")) # Getting total available/used resource # TODO(jdg): Add summary info for Snapshots storage_refs = db.storage_get_all_by_host(context, host_ref['host']) (count, sum) = db.storage_data_get_for_host(context, host_ref['host']) snap_count_total = 0 snap_sum_total = 0 resources = [{'resource': {'host': host, 'project': '(total)', 'storage_count': str(count), 'total_storage_gb': str(sum), 'snapshot_count': str(snap_count_total), 'total_snapshot_gb': str(snap_sum_total)}}] project_ids = [v['project_id'] for v in storage_refs] project_ids = list(set(project_ids)) for project_id in project_ids: (count, sum) = db.storage_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, 'storage_count': str(count), 'total_storage_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 _sync_gigabytes(context, project_id, session): (_junk, vol_gigs) = db.storage_data_get_for_project(context, project_id, session=session) if FLAGS.no_snapshot_gb_quota: return {'gigabytes': vol_gigs} (_junk, snap_gigs) = db.snapshot_data_get_for_project(context, project_id, session=session) return {'gigabytes': vol_gigs + snap_gigs}
def _sync_storages(context, project_id, session): (storages, gigs) = db.storage_data_get_for_project(context, project_id, session=session) return {'storages': storages}