Esempio n. 1
0
def get_hypervisors():
    nova = login.get_nova_client()
    nova_hypervisors = nova.hypervisors.list()
    hypervisors = []
    for hypervisor in nova_hypervisors:
        print hypervisor._info
        hypervisor_id = hypervisor._info["hypervisor_hostname"]
        hypervisor_running_vms = hypervisor._info["running_vms"]
        hypervisor_util = 0.0
        hypervisor_ram_used = 0.0
        hypervisor_vcpus = hypervisor._info["vcpus"]
        hypervisor_ram = hypervisor._info["memory_mb"]
        # hypervisor_state = hypervisor._info["state"]
        hypervisor_host_ip = hypervisor._info["host_ip"]
        hypervisor_pc = 0.0
        consumption_idle = 150.0
        consumption_max = 300.0
        hypervisors.append({"id": hypervisor_id,
                            "util": hypervisor_util,
                            "cpu": hypervisor_vcpus,
                            "capacity": hypervisor_vcpus * 100,
                            "ram_capacity": hypervisor_ram,
                            "ram_used": hypervisor_ram_used,
                            # "state":hypervisor_state,
                            "host_ip": hypervisor_host_ip,
                            "power_consumption": hypervisor_pc,
                            "no_vms": hypervisor_running_vms,
                            "consumption_idle": consumption_idle,
                            "consumption_max": consumption_max})
    return hypervisors
def get_vms():
    nova = login.get_nova_client()
    ceilometer = login.get_ceilometer_client()
    nova_servers = nova.servers.list(search_opts={"all_tenants": True})
    vms = []
    for nova_server in nova_servers:
        # print nova_server._info
        server_id = nova_server._info["id"]
        server_flavor = nova.flavors.get(nova_server._info["flavor"]["id"])
        server_vcpus = server_flavor._info["vcpus"]
        server_ram = server_flavor._info["ram"]
        server_hypervisor = nova_server._info["OS-EXT-SRV-ATTR:hypervisor_hostname"]
        server_state = nova_server._info["OS-EXT-STS:vm_state"]
        server_cpu_util_rel = get_vm_cpu_util(ceilometer, server_id)
        vms.append(
            {
                "id": server_id,
                "util": server_cpu_util_rel,
                "host": server_hypervisor,
                "vcpus": server_vcpus,
                "ram": server_ram,
                "vm_state": server_state,
                "util_abs": server_cpu_util_rel * server_vcpus,
            }
        )
    return vms
Esempio n. 3
0
def get_hypervisors():
    nova = login.get_nova_client()
    nova_hypervisors = nova.hypervisors.list()
    hypervisors = []
    for hypervisor in nova_hypervisors:
        print hypervisor._info
        hypervisor_id = hypervisor._info["hypervisor_hostname"]
        hypervisor_running_vms = hypervisor._info["running_vms"]
        hypervisor_util = 0.0
        hypervisor_ram_used = 0.0
        hypervisor_vcpus = hypervisor._info["vcpus"]
        hypervisor_ram = hypervisor._info["memory_mb"]
        # hypervisor_state = hypervisor._info["state"]
        hypervisor_host_ip = hypervisor._info["host_ip"]
        hypervisor_pc = 0.0
        consumption_idle = 150.0
        consumption_max = 300.0
        hypervisors.append({
            "id": hypervisor_id,
            "util": hypervisor_util,
            "cpu": hypervisor_vcpus,
            "capacity": hypervisor_vcpus * 100,
            "ram_capacity": hypervisor_ram,
            "ram_used": hypervisor_ram_used,
            # "state":hypervisor_state,
            "host_ip": hypervisor_host_ip,
            "power_consumption": hypervisor_pc,
            "no_vms": hypervisor_running_vms,
            "consumption_idle": consumption_idle,
            "consumption_max": consumption_max
        })
    return hypervisors
def get_vm(vm_id):
    nova = login.get_nova_client()
    print vm_id
    return nova.servers.find(id=vm_id)