def action_whales(): start = himutils.get_date(options.start, date.today() - timedelta(days=1)) stop = himutils.get_date(options.end, date.today() + timedelta(days=1)) if start > stop: himutils.sys_error('start %s must be fore stop %s' % (start, stop)) logger.debug('=> start date = %s', start) logger.debug('=> stop date = %s', stop) for region in regions: nc = Nova(options.config, debug=options.debug, log=logger, region=region) cc = Cinder(options.config, debug=options.debug, log=logger, region=region) project_usage = nc.get_usage(start=start, end=stop) logger.debug('=> threshold for whales filter %s', options.threshold) print_header = True for usage in project_usage: project = kc.get_by_id(obj_type='project', obj_id=usage.tenant_id) if not project: logger.debug('=> project with id %s not found',usage.tenant_id) continue if len(usage.server_usages) < options.threshold: continue cinderusage = cc.get_usage(usage.tenant_id) admin = project.admin if hasattr(project, 'admin') else 'unknown!' output = OrderedDict() output['instances'] = len(usage.server_usages) output['volume_gb'] = cinderusage.gigabytes['in_use'] output['name'] = project.name output['admin'] = admin if print_header: output['header'] = 'project usage %s (instances, volume (GB), name, id)' % region print_header = False printer.output_dict(objects=output, sort=False, one_line=True)
def action_flavors(): project = kc.get_project_by_name(options.project) start = himutils.get_date(options.start, date.today() - timedelta(days=1)) stop = himutils.get_date(options.end, date.today() + timedelta(days=1)) if start > stop: himutils.sys_error('start %s must be fore stop %s' % (start, stop)) logger.debug('=> start date = %s', start) logger.debug('=> stop date = %s', stop) flavors = dict() for region in regions: nc = Nova(options.config, debug=options.debug, log=logger, region=region) usage = nc.get_usage(project_id=project.id, start=start, end=stop) if not hasattr(usage, 'server_usages'): continue for server in usage.server_usages: flavors[server['flavor']] = flavors.get(server['flavor'], 0) + 1 flavors['header'] = 'flavor usage for %s in all regions' % project.name printer.output_dict(flavors)
def action_whales(): start = himutils.get_date(options.start, date.today() - timedelta(days=1)) stop = himutils.get_date(options.end, date.today() + timedelta(days=1)) if start > stop: himutils.sys_error('start %s must be fore stop %s' % (start, stop)) logger.debug('=> start date = %s', start) logger.debug('=> stop date = %s', stop) for region in regions: nc = Nova(options.config, debug=options.debug, log=logger, region=region) cc = Cinder(options.config, debug=options.debug, log=logger, region=region) project_usage = nc.get_usage(start=start, end=stop) logger.debug('=> threshold for whales filter %s', options.threshold) print_header = True for usage in project_usage: project = kc.get_by_id(obj_type='project', obj_id=usage.tenant_id) if not project: logger.debug('=> project with id %s not found', usage.tenant_id) continue if len(usage.server_usages) < options.threshold: continue cinderusage = cc.get_quota(usage.tenant_id, True) admin = project.admin if hasattr(project, 'admin') else 'unknown!' output = OrderedDict() output['instances'] = len(usage.server_usages) output['volume_gb'] = cinderusage['gigabytes']['in_use'] output['name'] = project.name output['admin'] = admin if print_header: output[ 'header'] = 'project usage %s (instances, volume (GB), name, id)' % region print_header = False printer.output_dict(objects=output, sort=False, one_line=True)