Beispiel #1
0
def index():
    client = ResourceManagerClient(endpoint=RM_ENDPOINT)
    machines = client.get_all_resources()

    available_machines = []
    used_machines = []
    pxe_failed = []
    error_state = []

    for machine in machines:
        try:
            addr = socket.getaddrinfo(machine['hostname'], 22, socket.AF_INET, socket.IPPROTO_IP, socket.IPPROTO_TCP)[0]
            machine.update({'ip': str(addr[4][0])})
        except:
            machine.update({'ip': "IP NOT FOUND"})

        if machine['state'] == "in_use":
            used_machines.append(machine)
        elif machine['state'] == "idle":
            available_machines.append(machine)
        elif machine['state'] == "pxe_failed":
            pxe_failed.append(machine)
        else:
            error_state.append(machine)
    total_machines = len(machines)

    return render_template('index.html',
                           machines=machines,
                           total_machines=total_machines,
                           available_machines=len(available_machines),
                           used_machines=len(used_machines),
                           pxe_failed=len(pxe_failed))
Beispiel #2
0
def get_current_jobs():
    client = ResourceManagerClient(endpoint=RM_ENDPOINT,
                                     resource_type='machines')
    jobs = []
    machines = client.get_all_resources()
    for machine in machines:
        if machine['job_id'] and machine['job_id'] not in jobs:
            jobs.append(machine['job_id'])
    return jobs
Beispiel #3
0
def machines():
    client = ResourceManagerClient(endpoint=RM_ENDPOINT)
    machines = client.get_all_resources()
    machine_list = []

    state = request.args.get('state')
    if not state:
        state = "all"

    for machine in machines:
        try:
            addr = socket.getaddrinfo(machine['hostname'], 22, socket.AF_INET, socket.IPPROTO_IP, socket.IPPROTO_TCP)[0]
            machine.update({'ip': str(addr[4][0])})
        except:
            machine.update({'ip': "IP NOT FOUND"})

        if state == "all":
            machine_list.append(machine)
        elif state == machine['state']:
            machine_list.append(machine)
    return render_template("general/machines.html", machines=machine_list)
Beispiel #4
0
def addresses():

    state = request.args.get('state')
    ip_type = request.args.get('type')

    if not ip_type:
        ip_type = "public-addresses"
    if ip_type not in ['public-addresses', 'private-addresses']:
        ip_type = "public-addresses"

    if not state:
        state = "all"

    client = ResourceManagerClient(endpoint=RM_ENDPOINT,
                                   resource_type=ip_type)
    all_ips = client.get_all_resources()
    available_ips = client.find_resources(field="owner", value="")

    jobs = get_current_jobs()
    zombie_ips = []

    for ip in all_ips:
        if ip['owner'] and ip['owner'] not in jobs:
            ip.update({'temp_state': 'zombie'})
            zombie_ips.append(ip)

    if state == "zombie":
        ips = zombie_ips
    else:
        ips = all_ips

    zombie_query_string = "type=" + ip_type + "&state=zombie"

    return render_template("general/ipaddresses.html",
                           total_pub_ips=len(all_ips),
                           available_ips=len(available_ips),
                           zombie_ips=len(zombie_ips),
                           zombie_query_string=zombie_query_string,
                           ips=ips, ip_type=ip_type)
Beispiel #5
0
                'g-xx-xx': {'regex': r'g-\d\d-\d\d.qa1.eucalyptus-systems.com', 'mem': 8589934592,
                            'cpucores': 2, 'cpumhz': 2200,
                            'interfaces': [{'ratembps': 1000}, {'ratembps': 1000}]},
                'h-xx': {'regex': r'h-\d\d.qa1.eucalyptus-systems.com', 'mem': 68719476736,
                         'cpucores': 8, 'cpumhz': 2400},
                'a-xx-x': {'regex': r'a-\d\d-\w.qa1.eucalyptus-systems.com', 'mem': 137438953472,
                           'cpucores': 8, 'cpumhz': 2600,
                           'interfaces': [{'ratembps': 10000}]}
                }

    with open(newhosts, "r") as file:
        collected = json.loads(file.read())

    # client = ResourceManagerClient(endpoint="http://10.111.4.100:5000")  #  PRODUCTION
    client = ResourceManagerClient(endpoint="http://127.0.0.1:5000")  # USE "http://10.111.4.100:5000" for production
    ourlist = client.get_all_resources()
    for item in ourlist:
        machine = client.get_resource(item['hostname'])  # PRODUCTION
        for mtype in memtable:
            match = re.search(memtable[mtype]['regex'], item['hostname'])
            if match:
                if 'tags' not in machine.keys():
                    machine[u'tags'] = {}
                if item['hostname'] in collected['hosts'].keys():
                    print "{}: updating to {} (collected) (vs {} table)".format(
                        item['hostname'],
                        int(collected['hosts'][item['hostname']])*1024,
                        memtable[mtype]['mem'])
                    machine[u'tags'][u'memory'] = int(collected['hosts'][item['hostname']])*1024  # PRODUCTION
                else:
                    print "{}: updating to {} (table)".format(item['hostname'],
def test_get_all_resources():
    client = ResourceManagerClient()
    url = client.endpoint
    response_body = "{\"_items\":[]}"
    httpretty.register_uri(httpretty.GET, url, body=response_body)
    assert isinstance(client.get_all_resources(), list)
            'cpucores': 8,
            'cpumhz': 2600,
            'interfaces': [{
                'ratembps': 10000
            }]
        }
    }

    with open(newhosts, "r") as file:
        collected = json.loads(file.read())

    # client = ResourceManagerClient(endpoint="http://10.111.4.100:5000")  #  PRODUCTION
    client = ResourceManagerClient(
        endpoint="http://127.0.0.1:5000"
    )  # USE "http://10.111.4.100:5000" for production
    ourlist = client.get_all_resources()
    for item in ourlist:
        machine = client.get_resource(item['hostname'])  # PRODUCTION
        for mtype in memtable:
            match = re.search(memtable[mtype]['regex'], item['hostname'])
            if match:
                if 'tags' not in machine.keys():
                    machine[u'tags'] = {}
                if item['hostname'] in collected['hosts'].keys():
                    print "{}: updating to {} (collected) (vs {} table)".format(
                        item['hostname'],
                        int(collected['hosts'][item['hostname']]) * 1024,
                        memtable[mtype]['mem'])
                    machine[u'tags'][u'memory'] = int(collected['hosts'][
                        item['hostname']]) * 1024  # PRODUCTION
                else:
def test_get_all_resources():
    client = ResourceManagerClient()
    url = client.endpoint
    response_body = "{\"_items\":[]}"
    httpretty.register_uri(httpretty.GET, url, body=response_body)
    assert isinstance(client.get_all_resources(), list)