示例#1
0
    def test_get_numa_node_cpus(self):
        host_cpu = {'numa_node0': '0-5,12-17',
                    'numa_node1': '6-11,18-23'}
        node0_cpus = range(0, 6) + range(12, 18)
        node1_cpus = range(6, 12) + range(18, 24)
        real_numa_cpus = utils.get_numa_node_cpus(host_cpu)
        expect_numa_cpus = {'numa_node0': node0_cpus,
                            'numa_node1': node1_cpus, }
        self.assertEqual(real_numa_cpus, expect_numa_cpus)

        host_cpu = {'numa_node0': '0-5,12-17'}
        node0_cpus = range(0, 6) + range(12, 18)
        real_numa_cpus = utils.get_numa_node_cpus(host_cpu)
        expect_numa_cpus = {'numa_node0': node0_cpus}
        self.assertEqual(real_numa_cpus, expect_numa_cpus)

        host_cpu = {'numa_node1': '6-11,18-23'}
        node1_cpus = range(6, 12) + range(18, 24)
        real_numa_cpus = utils.get_numa_node_cpus(host_cpu)
        expect_numa_cpus = {'numa_node1': node1_cpus, }
        self.assertEqual(real_numa_cpus, expect_numa_cpus)

        host_cpu = {}
        real_numa_cpus = utils.get_numa_node_cpus(host_cpu)
        expect_numa_cpus = {}
        self.assertEqual(real_numa_cpus, expect_numa_cpus)
示例#2
0
    def test_get_numa_node_cpus(self):
        host_cpu = {'numa_node0': '0-5,12-17', 'numa_node1': '6-11,18-23'}
        node0_cpus = range(0, 6) + range(12, 18)
        node1_cpus = range(6, 12) + range(18, 24)
        real_numa_cpus = utils.get_numa_node_cpus(host_cpu)
        expect_numa_cpus = {
            'numa_node0': node0_cpus,
            'numa_node1': node1_cpus,
        }
        self.assertEqual(real_numa_cpus, expect_numa_cpus)

        host_cpu = {'numa_node0': '0-5,12-17'}
        node0_cpus = range(0, 6) + range(12, 18)
        real_numa_cpus = utils.get_numa_node_cpus(host_cpu)
        expect_numa_cpus = {'numa_node0': node0_cpus}
        self.assertEqual(real_numa_cpus, expect_numa_cpus)

        host_cpu = {'numa_node1': '6-11,18-23'}
        node1_cpus = range(6, 12) + range(18, 24)
        real_numa_cpus = utils.get_numa_node_cpus(host_cpu)
        expect_numa_cpus = {
            'numa_node1': node1_cpus,
        }
        self.assertEqual(real_numa_cpus, expect_numa_cpus)

        host_cpu = {}
        real_numa_cpus = utils.get_numa_node_cpus(host_cpu)
        expect_numa_cpus = {}
        self.assertEqual(real_numa_cpus, expect_numa_cpus)
示例#3
0
def allocate_dvs_cpus(host_detail):
    dvs_cpu_sets = {}
    host_interfaces = host_detail.get('interfaces')
    if not host_interfaces:
        return dvs_cpu_sets

    dvs_interfaces = utils.get_dvs_interfaces(host_interfaces)
    if not dvs_interfaces:
        return dvs_cpu_sets

    host_id = host_detail.get('id')
    host_hw_info = {'system': '', 'memory': '',
                    'cpu': '', 'disks': '', 'interfaces': '',
                    'pci': '', 'devices': ''}
    host_obj = host_detail
    for f in host_hw_info:
        host_hw_info[f] = host_obj.get(f)
    numa_cpus = utils.get_numa_node_cpus(host_hw_info.get('cpu', {}))

    LOG.info("Get DVS cpusets of host '%s'", host_id)
    dvs_cpu_sets = get_dvs_cpusets(numa_cpus,
                                   host_detail,
                                   host_hw_info)

    return dvs_cpu_sets
示例#4
0
def allocate_clc_cpus(host_detail):
    pci_cpu_sets = {}
    if 'COMPUTER' not in host_detail.get('role', []):
        return pci_cpu_sets

    host_interfaces = host_detail.get('interfaces')
    host_hw_info = {'system': '', 'memory': '',
                    'cpu': '', 'disks': '', 'interfaces': '',
                    'pci': '', 'devices': ''}
    host_obj = host_detail
    for f in host_hw_info:
        host_hw_info[f] = host_obj.get(f)

    host_id = host_detail.get('id')
    clc_pci_list = utils.get_clc_pci_info(host_hw_info['pci'].values())
    if not clc_pci_list:
        return pci_cpu_sets
    else:
        LOG.info("CLC card pci number: '%s'", clc_pci_list)
        numa_cpus = utils.get_numa_node_cpus(host_hw_info.get('cpu', {}))
        LOG.info("Get CLC cpusets of host '%s'", host_id)
        device_numa = {}
        for device in host_hw_info['devices'].values():
            device_numa.update(device)
        (status, pci_cpu_sets) = pci_get_cpu_sets(numa_cpus,
                                                  device_numa,
                                                  clc_pci_list)
        if status['rc'] != 0:
            msg = "Get CLC cpu sets for host '%s' failed,\
                    detail error is '%s'"\
                    % (host_id, status['msg'])
            LOG.error(msg)
    return pci_cpu_sets
示例#5
0
 def check_isomorphic_host(self, compute_list, host_info):
     new_interfaces = host_info.interfaces
     host_numa_cpus = utils.get_numa_node_cpus((host_info.cpu or {}))
     memory_size_b_str = str(host_info.memory['total'])
     memory_size_b_int = int(memory_size_b_str.strip().split()[0])
     for compute_host in compute_list:
         new_interface_count = len([
             interface for interface in new_interfaces
             if interface['type'] == "ether"
         ])
         compute_interface_count = len([
             interface for interface in compute_host.interfaces
             if interface['type'] == "ether"
         ])
         if new_interface_count != compute_interface_count:
             msg = "%s and new host interface number are different" %\
                   (compute_host.name)
             LOG.warning(msg)
             continue
         if host_info.cpu['total'] != compute_host.cpu['total']:
             msg = "%s and new host cpu total numbers are different" %\
                   (compute_host.name)
             LOG.warning(msg)
             continue
         compute_numa_cpus = utils.get_numa_node_cpus((compute_host.cpu
                                                       or {}))
         if compute_numa_cpus != host_numa_cpus:
             msg = "%s and new host numa cpus are different" %\
                   compute_host.name
             LOG.warning(msg)
             continue
         active_compu_memory_str = str(compute_host.memory['total'])
         active_compu_memory_size =\
             int(active_compu_memory_str.strip().split()[0])
         # host memory can't be lower than the installed host memory size-1G
         if memory_size_b_int < active_compu_memory_size - 1024 * 1024:
             msg = "new host memory is lower than %s" % compute_host.name
             LOG.warning(msg)
             continue
         is_isomorphic = self._check_interface_isomorphic(
             new_interfaces, compute_host)
         if is_isomorphic:
             return compute_host
     return False
示例#6
0
 def check_isomorphic_host(self, compute_list, host_info):
     new_interfaces = host_info.interfaces
     host_numa_cpus = utils.get_numa_node_cpus((host_info.cpu or {}))
     memory_size_b_str = str(host_info.memory['total'])
     memory_size_b_int = int(memory_size_b_str.strip().split()[0])
     for compute_host in compute_list:
         new_interface_count = len(
             [interface for interface in
              new_interfaces if interface['type'] == "ether"])
         compute_interface_count = len(
             [interface for interface in
              compute_host.interfaces if interface['type'] == "ether"])
         if new_interface_count != compute_interface_count:
             msg = "%s and new host interface number are different" %\
                   (compute_host.name)
             LOG.warning(msg)
             continue
         if host_info.cpu['total'] != compute_host.cpu['total']:
             msg = "%s and new host cpu total numbers are different" %\
                   (compute_host.name)
             LOG.warning(msg)
             continue
         compute_numa_cpus = utils.get_numa_node_cpus(
             (compute_host.cpu or {}))
         if compute_numa_cpus != host_numa_cpus:
             msg = "%s and new host numa cpus are different" %\
                   compute_host.name
             LOG.warning(msg)
             continue
         active_compu_memory_str = str(compute_host.memory['total'])
         active_compu_memory_size =\
             int(active_compu_memory_str.strip().split()[0])
         # host memory can't be lower than the installed host memory size-1G
         if memory_size_b_int < active_compu_memory_size - 1024 * 1024:
             msg = "new host memory is lower than %s" % compute_host.name
             LOG.warning(msg)
             continue
         is_isomorphic = self._check_interface_isomorphic(
             new_interfaces, compute_host)
         if is_isomorphic:
             return compute_host
     return False
示例#7
0
def allocate_dvs_cpus(host_detail, num):
    dvs_cpu_sets = {}
    host_interfaces = host_detail.get('interfaces')
    if not host_interfaces:
        return dvs_cpu_sets

    # 'vswitch_type' in interface and
    # interface['vswitch_type'] == 'dvs'
    dvs_interfaces = utils.get_dvs_interfaces(host_interfaces)
    if not dvs_interfaces:
        return dvs_cpu_sets

    # extract host_hw_info out from host_detail
    host_hw_info = {
        'id': '',
        'system': '',
        'memory': '',
        'cpu': '',
        'disks': '',
        'interfaces': '',
        'pci': '',
        'devices': ''
    }
    host_obj = host_detail
    for f in host_hw_info:
        host_hw_info[f] = host_obj.get(f)

    # Given host_hw_info.get('cpu', {}) =
    # host_cpu = {"numa_node0": "0-7,16-23",
    #             "numa_node1": "8-15,24-31"}
    # then get_numa_node_cpus will return cpu id list as follows:
    # {'numa_node0': [0,1,2,3,4,5,6,7, 16,17,18,19,20,21,22,23],
    #  'numa_node1': [8,9,10,11,12,13,14,15, 24,25,26,27,28,29,30,31]}
    numa_cpus = utils.get_numa_node_cpus(host_hw_info.get('cpu', {}))

    LOG.info("Get DVS cpusets of host '%s'" % host_hw_info.get('id'))
    dvs_cpu_sets = get_dvs_cpusets(numa_cpus, dvs_interfaces, host_hw_info,
                                   num)

    return dvs_cpu_sets