Ejemplo n.º 1
0
 def vms_by_hosts(
     x=list_(str_(of='abc123-', min_length=36, max_length=36),
             min_length=0, max_length=3),
     y=list_(str_(of='abc123-', min_length=36, max_length=36),
             min_length=0, max_length=3),
     host1=str_(of='abc123-', min_length=5, max_length=10),
     host2=str_(of='abc123-', min_length=5, max_length=10)
 ):
     with MockTransaction:
         vms1 = {}
         for vm in x:
             vms1[vm] = host1
         vms2 = {}
         for vm in y:
             vms2[vm] = host2
         vms_all = dict(vms1)
         vms_all.update(vms2)
         vms = []
         for vm_uuid, h in vms_all.items():
             vm = mock(vm_uuid)
             vm.id = vm_uuid
             expect(manager).vm_hostname(vm).and_return(h).once()
             vms.append(vm)
         nova = mock('nova')
         nova.servers = mock('servers')
         expect(nova.servers).list().and_return(vms).once()
         result = manager.vms_by_hosts(nova, [host1, host2])
         result_sets = {}
         for host, data in result.items():
             result_sets[host] = set(data)
         assert result_sets == {host1: set(x), host2: set(y)}
Ejemplo n.º 2
0
 def vms_by_hosts(x=list_(str_(of='abc123-', min_length=36, max_length=36),
                          min_length=0,
                          max_length=3),
                  y=list_(str_(of='abc123-', min_length=36, max_length=36),
                          min_length=0,
                          max_length=3),
                  host1=str_(of='abc123-', min_length=5, max_length=10),
                  host2=str_(of='abc123-', min_length=5, max_length=10)):
     with MockTransaction:
         vms1 = {}
         for vm in x:
             vms1[vm] = host1
         vms2 = {}
         for vm in y:
             vms2[vm] = host2
         vms_all = dict(vms1)
         vms_all.update(vms2)
         vms = []
         for vm_uuid, h in vms_all.items():
             vm = mock(vm_uuid)
             vm.id = vm_uuid
             expect(manager).vm_hostname(vm).and_return(h).once()
             vms.append(vm)
         nova = mock('nova')
         nova.servers = mock('servers')
         expect(nova.servers).list().and_return(vms).once()
         result = manager.vms_by_hosts(nova, [host1, host2])
         result_sets = {}
         for host, data in result.items():
             result_sets[host] = set(data)
         assert result_sets == {host1: set(x), host2: set(y)}
Ejemplo n.º 3
0
config = read_and_validate_config([DEFAILT_CONFIG_PATH, CONFIG_PATH],
                                  REQUIRED_FIELDS)
db = manager.init_db(config['sql_connection'])
nova = client.Client(config['os_admin_user'],
                     config['os_admin_password'],
                     config['os_admin_tenant_name'],
                     config['os_auth_url'],
                     service_type="compute")
hosts = common.parse_compute_hosts(config['compute_hosts'])

hosts_cpu_total, hosts_cpu_cores, hosts_ram_total = \
    db.select_host_characteristics()
hosts_cpu_core = \
    dict((host, int(hosts_cpu_total[host] / hosts_cpu_cores[host]))
         for host in hosts_cpu_total.keys())
hosts_to_vms = manager.vms_by_hosts(nova, hosts)
vms = [item for sublist in hosts_to_vms.values() for item in sublist]

vms_names = []
vms_status = {}
for uuid in vms:
    vm = nova.servers.get(uuid)
    vms_names.append((vm.human_id, uuid))
    vms_status[uuid] = str(vm.status)
vms_names = sorted(vms_names)

vms_cpu_usage = db.select_last_cpu_mhz_for_vms()
for vm in vms:
    if not vm in vms_cpu_usage:
        vms_cpu_usage[vm] = 0
vms_ram_usage = manager.vms_ram_limit(nova, vms)
Ejemplo n.º 4
0
config = read_and_validate_config([DEFAULT_CONFIG_PATH, CONFIG_PATH],
                                  REQUIRED_FIELDS)
db = manager.init_db(config['sql_connection'])
nova = client.Client(config['os_admin_user'],
                     config['os_admin_password'],
                     config['os_admin_tenant_name'],
                     config['os_auth_url'],
                     service_type="compute")
hosts = common.parse_compute_hosts(config['compute_hosts'])

hosts_cpu_total, hosts_cpu_cores, hosts_ram_total = \
    db.select_host_characteristics()
hosts_cpu_core = \
    dict((host, int(hosts_cpu_total[host] / hosts_cpu_cores[host]))
         for host in hosts_cpu_total.keys())
hosts_to_vms = manager.vms_by_hosts(nova, hosts)
vms = [item for sublist in hosts_to_vms.values() for item in sublist]

vms_names = []
vms_status = {}
for uuid in vms:
    vm = nova.servers.get(uuid)
    vms_names.append((vm.human_id, uuid))
    vms_status[uuid] = str(vm.status)
vms_names = sorted(vms_names)

vms_cpu_usage = db.select_last_cpu_mhz_for_vms()
for vm in vms:
    if not vm in vms_cpu_usage:
        vms_cpu_usage[vm] = 0
vms_ram_usage = manager.vms_ram_limit(nova, vms)