Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
def collect_all(client, zone, opt=None):
    flav = getAvailFlav(client)
    cells = filterAz(client, zone)
    timeout = processConfig('config', 'timeout')
    if opt is True:
        jobs = []
        for i, cell in enumerate(cells):
            cell["queue"] = Queue()

            p = Process(name=i, target=gather_all_stats,
                        args=(cell["cell"], cell["host_name"], flav,
                              zone, cell["fq_cell"], client, cell["queue"]))
            jobs.append(p)
            p.start()

        for p in jobs:
            p.join(int(timeout))
            if p.is_alive():
                p.terminate()
                return False

        html_array = []
        for cell in cells:
            html_array.append(cell["queue"].get())

        return html_array
    else:
        if cell in cells:
            index_id = cell['cell'].index(opt)
        a_name = cell['fq_cell'][index_id]
        c_name = cell['host_name'][index_id]

        return gather_all_stats(opt, c_name, flav, zone, a_name, client)
Ejemplo n.º 4
0
def collect_compute(client, zone, target_cell=None):
    cells = filterAz(client, zone)
    timeout = processConfig('config', 'timeout')
    if target_cell is None:
        jobs = []
        for i, cell in enumerate(cells):
            cell["queue"] = Queue()

            p = Process(name=i, target=gather_compute_stats,
                        args=(cell["cell"], zone,
                              cell["fq_cell"], client,
                              cell["queue"]))
            jobs.append(p)
            p.start()

        for p in jobs:
            p.join(int(timeout))
            if p.is_alive():
                p.terminate()
                return False

        html_array = []
        for cell in cells:
            html_array.append(cell["queue"].get())

        return html_array
    else:
        for cell in cells:
            if cell["cell"] == target_cell:
                a_name = cell['fq_cell']
                break
        else:
            raise Exception("Can't find cell.")

        return [gather_compute_stats(target_cell, zone, a_name, client)]
Ejemplo n.º 5
0
def retries(func):
    attempt = processConfig('config', 'retries')

    @wraps(func)
    def _decorator(*args, **kwargs):
        for x in xrange(int(attempt)):
            try:
                return func(*args, **kwargs)
            except ClientException:
                time.sleep(5)
        return func(*args, **kwargs)
    return _decorator
Ejemplo n.º 6
0
def retries(func):
    attempt = processConfig('config', 'retries')

    @wraps(func)
    def _decorator(*args, **kwargs):
        for x in xrange(int(attempt)):
            try:
                return func(*args, **kwargs)
            except ClientException:
                time.sleep(5)
        return func(*args, **kwargs)

    return _decorator
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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)