def match_nodes(conn, min_nodes): results = [] while True: nodes = [ node for node in fuel_rest_api.get_all_nodes(conn) if node.cluster is None ] if len(nodes) < min_nodes: templ = "Only {0} nodes available. {1} requires. Wait 60 sec" logger.info(templ.format(len(nodes), min_nodes)) time.sleep(60) continue if len(nodes) < 1: raise ValueError("Nodes amount should be not less, than 2") cpu_disk = [] for node in nodes: info = node.get_info() cpu_count = int(info['meta']['cpu']['real']) disk_size = 0 for disk in info['meta']['disks']: disk_size += int(disk['size']) cpu_disk.append((disk_size, cpu_count, node)) cpu_disk.sort() nodes = [tpl[2] for tpl in cpu_disk] results.append(({'roles': ["controller"]}, nodes[0])) nodes = nodes[1:] num_computes = max(1, int((len(nodes) + 1) / 2)) for node in nodes[:num_computes]: results.append(({'roles': ["compute"]}, node)) for node in nodes[num_computes:]: results.append(({'roles': ["cinder"]}, node)) break return results
def match_nodes(conn, min_nodes): results = [] while True: nodes = [node for node in fuel_rest_api.get_all_nodes(conn) if node.cluster is None] if len(nodes) < min_nodes: templ = "Only {0} nodes available. {1} requires. Wait 60 sec" logger.info(templ.format(len(nodes), min_nodes)) time.sleep(60) continue if len(nodes) < 1: raise ValueError("Nodes amount should be not less, than 2") cpu_disk = [] for node in nodes: info = node.get_info() cpu_count = int(info['meta']['cpu']['real']) disk_size = 0 for disk in info['meta']['disks']: disk_size += int(disk['size']) cpu_disk.append((disk_size, cpu_count, node)) cpu_disk.sort() nodes = [tpl[2] for tpl in cpu_disk] results.append(({'roles': ["controller"]}, nodes[0])) nodes = nodes[1:] num_computes = max(1, int((len(nodes) + 1) / 2)) for node in nodes[:num_computes]: results.append(({'roles': ["compute"]}, node)) for node in nodes[num_computes:]: results.append(({'roles': ["cinder"]}, node)) break return results
def match_nodes(conn, cluster, max_nodes=None): node_groups = [] for node_group in cluster: rroles, rcount = node_group.split(",") rroles = rroles.strip() rcount = rcount.strip() roles = [role.strip() for role in rroles.split('+')] if rcount.endswith("+"): node_groups.append(NodeGroup(roles, int(rcount[:-1]), '+')) else: node_groups.append(NodeGroup(roles, int(rcount), None)) min_nodes = sum(node_group.num for node_group in node_groups) if max_nodes is not None and max_nodes < min_nodes: templ = "max_nodes ({0!r}) < min_nodes ({1!r})" raise ValueError(templ.format(max_nodes, min_nodes)) for node_group in node_groups: logger.info("Node : {0}".format(node_group)) controller_only = sum(node_group.num for node_group in node_groups if ['controller'] == node_group.roles) while True: raw_nodes = [ raw_node for raw_node in fuel_rest_api.get_all_nodes(conn) if raw_node.cluster is None ] if len(raw_nodes) < min_nodes: templ = "Waiting till {0} nodes will be available" logger.info(templ.format(min_nodes)) time.sleep(10) continue break if len(raw_nodes) < 1: raise ValueError("Nodes amount should be not less, than 1") cpu_disk = [] for raw_node in raw_nodes: info = raw_node.get_info() cpu_count = int(info['meta']['cpu']['real']) disk_size = 0 for disk in info['meta']['disks']: disk_size += int(disk['size']) cpu_disk.append(RawNodeInfo(cpu_count, disk_size, raw_node)) cpu_disk.sort() # least performant node - controllers for idx, node_info in enumerate(cpu_disk[:controller_only]): descr = {'roles': ["controller"], 'name': "controller_{0}".format(idx)} yield (descr, node_info.node) cpu_disk = cpu_disk[controller_only:] non_c_node_groups = [ node_group for node_group in node_groups if ['controller'] != node_group.roles ] def make_name(group, idx): return "_".join(group.roles + [str(idx)]) compute_nodes = [ node_group for node_group in non_c_node_groups if 'compute' in node_group.roles ] idx = 0 for node_group in compute_nodes: for idx, _ in enumerate(range(node_group.num), idx): name = make_name(node_group, idx) descr = {'roles': node_group.roles, 'name': name} yield (descr, cpu_disk.pop().node) data_nodes = [ node_group for node_group in non_c_node_groups if 'compute' not in node_group.roles ] idx = 0 for node_group in data_nodes: for idx, _ in enumerate(range(node_group.num), idx): name = make_name(node_group, idx) descr = {'roles': node_group.roles, 'name': name} yield (descr, cpu_disk.pop().node) strechable_node_groups = [ node_group for node_group in node_groups if node_group.num_modif == '+' ] if len(strechable_node_groups) != 0: cycle_over = enumerate(itertools.cycle(strechable_node_groups), min_nodes) nums = dict((id(node_group), node_group.num) for node_group in strechable_node_groups) for selected_nodes, node_group in cycle_over: if cpu_disk == [] or selected_nodes == max_nodes: break name = make_name(node_group, nums[id(node_group)]) nums[id(node_group)] += 1 descr = {'roles': node_group.roles, 'name': name} yield (descr, cpu_disk.pop().node)
def match_nodes(conn, cluster, max_nodes=None): node_groups = [] for node_group in cluster: rroles, rcount = node_group.split(",") rroles = rroles.strip() rcount = rcount.strip() roles = [role.strip() for role in rroles.split('+')] if rcount.endswith("+"): node_groups.append(NodeGroup(roles, int(rcount[:-1]), '+')) else: node_groups.append(NodeGroup(roles, int(rcount), None)) min_nodes = sum(node_group.num for node_group in node_groups) if max_nodes is not None and max_nodes < min_nodes: templ = "max_nodes ({0!r}) < min_nodes ({1!r})" raise ValueError(templ.format(max_nodes, min_nodes)) for node_group in node_groups: logger.info("Node : {0}".format(node_group)) controller_only = sum(node_group.num for node_group in node_groups if ['controller'] == node_group.roles) while True: raw_nodes = [raw_node for raw_node in fuel_rest_api.get_all_nodes(conn) if raw_node.cluster is None] if len(raw_nodes) < min_nodes: templ = "Waiting till {0} nodes will be available" logger.info(templ.format(min_nodes)) time.sleep(10) continue break if len(raw_nodes) <= 1: raise ValueError("Nodes amount should be not less, than 2") cpu_disk = [] for raw_node in raw_nodes: info = raw_node.get_info() cpu_count = int(info['meta']['cpu']['real']) disk_size = 0 for disk in info['meta']['disks']: disk_size += int(disk['size']) cpu_disk.append(RawNodeInfo(cpu_count, disk_size, raw_node)) cpu_disk.sort() # least performant node - controllers for idx, node_info in enumerate(cpu_disk[:controller_only]): descr = {'roles': ["controller"], 'name': "controller_{0}".format(idx)} yield (descr, node_info.node) cpu_disk = cpu_disk[controller_only:] non_c_node_groups = [node_group for node_group in node_groups if ['controller'] != node_group.roles] def make_name(group, idx): return "_".join(group.roles + [str(idx)]) compute_nodes = [node_group for node_group in non_c_node_groups if 'compute' in node_group.roles] idx = 0 for node_group in compute_nodes: for idx, _ in enumerate(range(node_group.num), idx): name = make_name(node_group, idx) descr = {'roles': node_group.roles, 'name': name} yield (descr, cpu_disk.pop().node) data_nodes = [node_group for node_group in non_c_node_groups if 'compute' not in node_group.roles] idx = 0 for node_group in data_nodes: for idx, _ in enumerate(range(node_group.num), idx): name = make_name(node_group, idx) descr = {'roles': node_group.roles, 'name': name} yield (descr, cpu_disk.pop().node) strechable_node_groups = [node_group for node_group in node_groups if node_group.num_modif == '+'] if len(strechable_node_groups) != 0: cycle_over = enumerate(itertools.cycle(strechable_node_groups), min_nodes) nums = dict((id(node_group), node_group.num) for node_group in strechable_node_groups) for selected_nodes, node_group in cycle_over: if cpu_disk == [] or selected_nodes == max_nodes: break name = make_name(node_group, nums[id(node_group)]) nums[id(node_group)] += 1 descr = {'roles': node_group.roles, 'name': name} yield (descr, cpu_disk.pop().node)
def match_nodes(conn, cluster): controller_count = int(cluster['controller']) compute_nodes = int(cluster['compute']) cinder = int(cluster.get('cinder', 0)) ceph_osd = int(cluster.get('ceph_osd', 0)) min_nodes = ceph_osd + cinder + compute_nodes + controller_count while True: nodes = [ node for node in fuel_rest_api.get_all_nodes(conn) if node.cluster is None ] if len(nodes) < min_nodes: templ = "Waiting till {} nodes will be available" logger.info(templ.format(min_nodes)) time.sleep(10) continue if len(nodes) <= 1: raise ValueError("Nodes amount should be not less, than 2") cpu_disk = [] for node in nodes: info = node.get_info() cpu_count = int(info['meta']['cpu']['real']) disk_size = 0 for disk in info['meta']['disks']: disk_size += int(disk['size']) cpu_disk.append((disk_size, cpu_count, node)) cpu_disk.sort() nodes = [tpl[2] for tpl in cpu_disk] for i, node in enumerate(nodes[:controller_count]): descr = { 'roles': ["controller"], 'name': "controller_{}".format(i) } yield (descr, node) nodes = nodes[controller_count:] for i, node in enumerate(nodes[:cinder]): descr = {'roles': ["cinder"], 'name': "cinder_{}".format(i)} yield (descr, node) nodes = nodes[cinder:] for i, node in enumerate(nodes[:ceph_osd]): descr = {'roles': ["ceph-osd"], 'name': "ceph_{}".format(i)} yield (descr, node) nodes = nodes[ceph_osd:] for i, node in enumerate(nodes): descr = {'roles': ["compute"], 'name': "compute_{}".format(i)} yield (descr, node) break