def main(): username = process_config('production', 'user') key = process_config('production', 'passwd') tenant_name = process_config('production', 'name') url = process_config('production', 'url') zone = process_config('config', 'zone') client = createNovaConnection(username, key, tenant_name, url) az = process_config('config', 'az') opt_ = get_args() if opt_.t is None: data = RunCollect(client, zone, opt=True) data2 = CombineResource(data) if opt_.o is 'n': printOptions(data, data_2=data2, options='all') elif opt_.o == 'html': templateLoader(data, data2) elif opt_.o == 'csv': multiCSVNode(data) createCSVFileCloud(data2) elif opt_.o == 'both': templateLoader(data, data2) multiCSVNode(data) createCSVFileCloud(data2) elif opt_.o == 'email': file_l = templateLoader(data, data2, opt='email') email_user(file_l) elif opt_.t in az: data = RunCollect(client, zone, opt=opt_.t) if opt_.o is 'n': printOptions(data) elif opt_.o == 'html': templateLoader(data, cell=opt_.t) elif opt_.o == 'csv': createCSVFileNode(data) elif opt_.o == 'both': templateLoader(data, cell=opt_.t) createCSVFileNode(data) elif opt_.o == 'email': file_l = templateLoader(data, cell=opt_.t, opt='email') email_user(file_l) else: print "Error!, cell %s not found. Current cell %s " % (opt_.t, az) return sys.exit(1)
def main(): parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS) parser.add_argument('-a', nargs='?', dest='target_cell', action='store', required=True, default=True, help='{specify 1 cell name to overide,e,g -a np}') parser.add_argument('-o', nargs='?', dest='output', default='n', choices=['html', 'csv', 'both', 'email'], required=False, help='output, {default: console}, {email: email html }') opts = parser.parse_args() username = processConfig('production', 'user') key = processConfig('production', 'passwd') tenant_name = processConfig('production', 'name') url = processConfig('production', 'url') zone = processConfig('config', 'zone') client = createNovaConnection(username, key, tenant_name, url) az = processConfig('config', 'az') if opts.target_cell is not None: if opts.target_cell not in az: parser.error("Error!, cell %s not found. Current cell %s " % (opts.target_cell, az)) else: opts.target_cell = True data = collect_all(client, zone, opt=opts.target_cell) if opts.target_cell is True: data2 = combineResource(data) else: data2 = None if opts.output is 'n': printOptions(data, data_2=data2, options='all') elif opts.output == 'html': templateLoader(data, data2) elif opts.output == 'csv': if opts.target_cell is True: multiCSVNode(data) createCSVFileCloud(data2) else: createCSVFileNode(data) elif opts.output == 'both': templateLoader(data, data2, cell=opts.target_cell) if opts.target_cell is True: multiCSVNode(data) createCSVFileCloud(data2) else: createCSVFileNode(data) elif opts.output == 'email': file_l = templateLoader(data, data2, cell=opts.target_cell, opt='email') emailUser(file_l)
def main(sender): username = processConfig('production', 'user') key = processConfig('production', 'passwd') tenant_name = processConfig('production', 'name') url = processConfig('production', 'url') zone = processConfig('config', 'zone') client = createNovaConnection(username, key, tenant_name, url) kclient = createKeystoneConnection(username, key, tenant_name, url) users = {} for user in kclient.users.list(): if not user.email: users[user.id] = None continue email = user.email.split('@')[-1] if email.endswith('.edu.au'): email = '_'.join(email.split('.')[-3:]) else: email = email.replace('.', '_') users[user.id] = email servers = all_servers(client) flavors = all_flavors(client, servers) servers_by_cell = defaultdict(list) servers_by_cell_by_domain = defaultdict(lambda: defaultdict(list)) for server in servers: cell = getattr(server, 'OS-EXT-AZ:availability_zone') servers_by_cell[cell].append(server) # Skip any hosts that are being run by users without an email # address. if server.user_id in users and users[server.user_id] is None: logger.info("skipping unknown user %s" % server.user_id) continue if server.user_id not in users: logger.error( "user %s doesn't exist but is currently owner of server %s" % (server.user_id, server.id)) continue servers_by_cell_by_domain[cell][users[server.user_id]].append(server) now = int(time.time()) for metric, value in server_metrics(servers, flavors).items(): sender.send_graphite_nectar(metric, value, now) for zone, servers in servers_by_cell.items(): for metric, value in server_metrics(servers, flavors).items(): sender.send_graphite_cell(zone, metric, value, now) for zone, items in servers_by_cell_by_domain.items(): for domain, servers in items.items(): for metric, value in server_metrics(servers, flavors).items(): if metric not in ['used_vcpus']: continue sender.send_graphite_domain(zone, domain, metric, value, now)
def main(): parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS) parser.add_argument('-a', nargs='?', dest='target_cell', action='store', required=True, default=True, help='{specify 1 cell name to overide,e,g -a np}') parser.add_argument( '-o', nargs='?', dest='output', default='n', choices=['html', 'csv', 'both', 'email'], required=False, help='output, {default: console}, {email: email html }') opts = parser.parse_args() username = processConfig('production', 'user') key = processConfig('production', 'passwd') tenant_name = processConfig('production', 'name') url = processConfig('production', 'url') zone = processConfig('config', 'zone') client = createNovaConnection(username, key, tenant_name, url) az = processConfig('config', 'az') if opts.target_cell is not None: if opts.target_cell not in az: parser.error("Error!, cell %s not found. Current cell %s " % (opts.target_cell, az)) else: opts.target_cell = True data = collect_all(client, zone, opt=opts.target_cell) if opts.target_cell is True: data2 = combineResource(data) else: data2 = None if opts.output is 'n': printOptions(data, data_2=data2, options='all') elif opts.output == 'html': templateLoader(data, data2) elif opts.output == 'csv': if opts.target_cell is True: multiCSVNode(data) createCSVFileCloud(data2) else: createCSVFileNode(data) elif opts.output == 'both': templateLoader(data, data2, cell=opts.target_cell) if opts.target_cell is True: multiCSVNode(data) createCSVFileCloud(data2) else: createCSVFileNode(data) elif opts.output == 'email': file_l = templateLoader(data, data2, cell=opts.target_cell, opt='email') emailUser(file_l)