Пример #1
0
def distribute_proxy():
    proxy_manager_lock.acquire()
    try:
        host_list = cps_server.cps_host_list()
        hosts = host_list["hosts"]
        free_proxy_list = []
        allocated_proxy_nums = []

        for host in hosts:
            proxy_info = {"id": host["id"],
                          "status": host["status"],
                          "manageip": host["manageip"]
                          }

            # proxy_free = True
            # for role in host["roles"]:
            #     if "compute-proxy" in role:
            #         num = role.split("-")[1]
            #         allocated_proxy_nums.append(num)
            #         proxy_free = False
            #         break
            #
            # if proxy_free:
            #     free_proxy_list.append(proxy_info)

            if len(host["roles"]) <= 2 and "normal" == host["status"]:
                free_proxy_list.append(proxy_info)
            else:
                for role in host["roles"]:
                    if "compute-proxy" in role:
                        num = role.split("-")[1]
                        allocated_proxy_nums.append(num)

        if 0 == len(free_proxy_list):
            aws_installer.install_aws_proxy()
            return None

        #TODO£¨lrx£©:deprecated without aws,modify later
        # if 1 == len(free_proxy_list):
        #     aws_installer.install_aws_proxy()

        right_proxy = free_proxy_list[0]
        num = 1

        while True:
            right_proxy_num = "proxy" + str(num).zfill(3)
            if right_proxy_num not in allocated_proxy_nums:
                right_proxy["proxy_num"] = right_proxy_num
                break
            else:
                num += 1

        # add role for this proxy
        # _add_role_to_proxy(right_proxy["id"], right_proxy["proxy_num"])

        return right_proxy
    except Exception as e:
        LOG.error("distribute proxy error, error: %s" % e.message)
    finally:
        proxy_manager_lock.release()
Пример #2
0
def distribute_proxy():
    proxy_manager_lock.acquire()
    try:
        host_list = cps_server.cps_host_list()
        hosts = host_list["hosts"]
        free_proxy_list = []
        allocated_proxy_nums = []

        for host in hosts:
            proxy_info = {
                "id": host["id"],
                "status": host["status"],
                "manageip": host["manageip"]
            }

            proxy_free = True
            for role in host["roles"]:
                if "compute-proxy" in role:
                    num = role.split("-")[1]
                    allocated_proxy_nums.append(num)
                    proxy_free = False
                    break

            if proxy_free:
                free_proxy_list.append(proxy_info)

            # if len(host["roles"]) <= 2 and "normal" == host["status"]:
            #     free_proxy_list.append(proxy_info)
            # else:
            #     for role in host["roles"]:
            #         if "compute-proxy" in role:
            #             num = role.split("-")[1]
            #             allocated_proxy_nums.append(num)

        if 0 == len(free_proxy_list):
            aws_installer.install_aws_proxy()
            return None

        #TODO£¨lrx£©:deprecated without aws,modify later
        # if 1 == len(free_proxy_list):
        #     aws_installer.install_aws_proxy()

        right_proxy = free_proxy_list[0]
        num = 1

        while True:
            right_proxy_num = "proxy" + str(num).zfill(3)
            if right_proxy_num not in allocated_proxy_nums:
                right_proxy["proxy_num"] = right_proxy_num
                break
            else:
                num += 1

        # add role for this proxy
        # _add_role_to_proxy(right_proxy["id"], right_proxy["proxy_num"])

        return right_proxy
    except Exception as e:
        LOG.error("distribute proxy error, error: %s" % e.message)
    finally:
        proxy_manager_lock.release()
Пример #3
0
    def host_list():
        """

        :return:
        """
        return cps_server.cps_host_list()
Пример #4
0
    def host_list():
        """

        :return:
        """
        return cps_server.cps_host_list()
Пример #5
0
 def host_list():
     return cps_server.cps_host_list()