Esempio n. 1
0
 def __init__(self, circle_name):
     self.circle_name = circle_name
     self.is_provision = 0
     self.provision_release_id = load_global_params_config()['circle_var'][circle_name]['provision_release_id']
     self.user_name = load_global_params_config()['circle_var'][circle_name]['user_name']
     self.az_pat = os.getenv('AZ_PAT')
     self.minimun_available_count = load_global_params_config()['circle_var'][circle_name]['minimun_available_count']
     self.dg_id_list = load_global_params_config()['circle_var'][circle_name]['dg_id_list']
Esempio n. 2
0
 def __init__(self, circle_name):
     self.user_name = load_global_params_config(
     )['circle_var'][circle_name]['user_name']
     self.az_pat = os.getenv('AZ_PAT')
     self.stage_list = load_global_params_config(
     )['circle_var'][circle_name]['stage_list']
     self.task_agent = TaskAgent(self.user_name, self.az_pat)
     self.ap_circle = []
     self.ap_id = {}
     self.dg_circle = []
     self.dg_id = {}
Esempio n. 3
0
    def trigger_provision_job(self, stage: str, rg_dtl_name: str):
        """
        trigger provision vm in specific dev test lab
        """
        provision_pipeline_id = load_global_params_config()['circle_var'][
            self.circle_name]['provision_pipeline_id']
        pipeline = Pipeline(self.user_name, self.az_pat)

        run_params = {
            'variables': {
                'app_name': {
                    'isSecret': False,
                    'value': self.circle_name
                },
                'vm_count': {
                    'isSecret': False,
                    'value':
                    self.minimun_available_count // len(self.os_type_list)
                },
                'env': {
                    'isSecret': False,
                    'value': stage.lower()
                },
                'rg_dtl_name': {
                    'isSecret': False,
                    'value': rg_dtl_name.lower()
                }
            }
        }

        pipeline.trigger_pipeline(run_params, provision_pipeline_id)
Esempio n. 4
0
 def __init__(self, circle_name):
     self.circle_name = circle_name
     self.subscription_id = load_global_params_config(
     )['common_var']['subscription_id']
     self.user_name = load_global_params_config(
     )['circle_var'][circle_name]['user_name']
     self.az_pat = os.getenv('AZ_PAT')
     self.sp_client_id = os.getenv('SP_CLIENT_ID')
     self.sp_pwd = os.getenv('SP_PWD')
     self.tenant_id = os.getenv('TENANT_ID')
     self.rg_dtl_name = load_global_params_config(
     )['circle_var'][circle_name]['rg_dtl_name']
     self.os_type_list = load_global_params_config(
     )['circle_var'][circle_name]['os_type']
     self.minimun_available_count = load_global_params_config(
     )['circle_var'][circle_name]['minimun_available_count'] * len(
         self.os_type_list)
     self.stage_list = load_global_params_config(
     )['circle_var'][circle_name]['stage_list']
     self.circe_status = []
     self.circe_env_status = {
         "circle": "",
         "env": "",
         "agent pool": "",
         "agent": "",
         "available count": "",
         "minimun count": "",
         "provision": ""
     }
Esempio n. 5
0
def main(req: func.HttpRequest) -> func.HttpResponse:
    load_dotenv()
    circle_list = list(load_global_params_config()['circle_var'].keys())

    try:
        for circle in circle_list:
            infra = InfraUtil(circle)
            infra.generate_circle_agent_pool_name(circle)
            infra.create_agent_pool(circle)

        return func.HttpResponse(
            f"This HTTP triggered function executed successfully.")

    except Exception as e:
        return func.HttpResponse(f"Meet Error {e}.", status_code=500)

    else:
        pass
Esempio n. 6
0
    def monitor_az_agent_in_ag(self):
        """
        """
        self.task_agent = TaskAgent(self.user_name, self.az_pat)
        self.ap_id_list = load_global_params_config()['circle_var'][
            self.circle_name]['ap_id_list']

        for env, ap_id in self.ap_id_list.items():
            result = self.task_agent.get_agent_pool_agents(ap_id)
            logging.info(
                f"Get {env} agents in agent pool: {ap_id} return: {result}")
            available_agent_count = 0
            for each in result:
                logging.debug(
                    f"Circle: {self.circle_name}, env: {env}, agent pool: {ap_id}, agent: {each}"
                )
                if "online" in each.status:
                    available_agent_count += 1

            if available_agent_count <= self.minimun_available_count:
                logging.info(
                    f"available agent count: {available_agent_count} less than minimun_count:{self.minimun_available_count}, do provision"
                )
                provision = True
                self.trigger_provision_job(env, self.rg_dtl_name)
            else:
                logging.info(
                    f"available agent count: {available_agent_count}, no need provision"
                )
                provision = False

            self.circe_env_status = {
                "circle": self.circle_name,
                "env": env,
                "agent pool": ap_id,
                "available count": available_agent_count,
                "minimun count": self.minimun_available_count,
                "provision": provision
            }
            self.circe_status.append(self.circe_env_status)
Esempio n. 7
0
    def monitor_az_agent_in_dg(self):
        """
        """
        self.task_agent = TaskAgent(self.user_name, self.az_pat)
        self.dg_id_list = load_global_params_config()['circle_var'][
            self.circle_name]['dg_id_list']

        for dg_id in self.dg_id_list:
            result = self.task_agent.get_deployment_group_agents(dg_id)

            available_agent_count = 0
            for each in result:
                if "available" in each.tags and "online" in each.agent.status:
                    available_agent_count += 1

            if available_agent_count <= self.minimun_available_count:
                logging.info(
                    f"Circle: {self.circle_name}, deployment group: {dg_id}, available agent count: {available_agent_count} is less than minimun_count:{self.minimun_available_count}, do provision"
                )
            else:
                logging.info(
                    f"Circle: {self.circle_name}, deployment group: {dg_id}, available agent count: {available_agent_count}, no need provision"
                )
Esempio n. 8
0
def main(req: func.HttpRequest) -> func.HttpResponse:
    load_dotenv()
    circle_list = list(load_global_params_config()['circle_var'].keys())
    api_response = []
    logging.info(
        f'Python HTTP trigger function processed a request. circle: {circle_list}'
    )

    try:
        for circle in circle_list:
            logging.info(f"Prepare to monitor resource in {circle}")
            monitor_circle = MonitorUtil(circle)
            monitor_circle.monitor_az_agent_in_ag()

            logging.info(
                f"Circle: {circle}, Function complete: {monitor_circle.circe_status}"
            )
            api_response.append(monitor_circle.circe_status)
        return func.HttpResponse(
            f"This HTTP triggered function executed successfully.\r\n {api_response}"
        )

    except Exception as e:
        return func.HttpResponse(f"Meet Error {e}.", status_code=500)