Exemplo n.º 1
0
    def health_check(self, server_id):
        try:
            server_data = models.ThirdServer.objects.get(id=server_id,
                                                         category=models.THIRD_SERVER_CATEGORY_MQ).server_data
        except models.ThirdServer.DoesNotExist:
            raise Exception("no rabbitmq server is active")

        try:
            http.http_request(
                method="GET",
                url="http://%s:%s/api/overview" % (server_data.get('ip_address'), server_data.get('ip_port')),
                auth=(server_data.get("username"), server_data.get("password"))
            )
        except Exception, e:
            raise Exception("administrator account information error or rabbitmq service exception: %s" % e)
Exemplo n.º 2
0
    def _apply_mq_res(self, server_url, admin_account, user_account, vhost):
        app_code = self.bk_app.app_code
        headers = {'content-type': 'application/json'}
        auth = (admin_account['name'], admin_account['password'])

        try:
            # 创建vhost
            http.http_request(
                method="PUT",
                url='%s/api/vhosts/%s' % (server_url, vhost),
                desired_code=codes.no_content,
                headers=headers,
                auth=auth
            )
        except Exception, e:
            raise Exception("create vhost failed: %s" % e)
Exemplo n.º 3
0
def check_agent_health(bk_server):
    resp = http.http_request(
        method="GET",
        url="http://%s:%s/v1/app/healthz" % (bk_server.ip_address, bk_server.ip_port),
        headers=agent_header(bk_server.s_id, bk_server.token)
    )
    if resp.get("error") != 0:
        raise Exception("%s agent return not zero" % bk_server.ip_address)
    return resp
Exemplo n.º 4
0
class RabbitmqManager(ThirdServiceManager):

    def apply(self, bk_app, mode, triggers):
        self.bk_app, self.mode, self.triggers = bk_app, mode, triggers

        server_data = models.ThirdServer.objects.get(category=models.THIRD_SERVER_CATEGORY_MQ,
                                                     is_active=True).server_data

        app_code = self.bk_app.app_code
        mq_pwd = str(self.bk_app.token)[:8]
        admin_account = {
            "name": server_data.get("username"),
            "password": server_data.get("password")
        }
        user_account = {
            "name": self.bk_app.app_code,
            "password": mq_pwd
        }
        server_url = "http://%s:%s" % (server_data.get("ip_address"), server_data.get("ip_port"))
        vhost = 'test_%s' % app_code if self.mode == 'test' else 'prod_%s' % app_code
        self._apply_mq_res(server_url, admin_account, user_account, vhost)
        return {
            "BK_BROKER_URL": "amqp://%s:%s@%s:5672/%s" % (app_code, mq_pwd, server_data.get('ip_address'), vhost),
            "IS_USE_CELERY": "true",
            "IS_USE_CELERY_BEAT": "true" if self.triggers.get("is_use_celery_beat") else "false"
        }

    def _apply_mq_res(self, server_url, admin_account, user_account, vhost):
        app_code = self.bk_app.app_code
        headers = {'content-type': 'application/json'}
        auth = (admin_account['name'], admin_account['password'])

        try:
            # 创建vhost
            http.http_request(
                method="PUT",
                url='%s/api/vhosts/%s' % (server_url, vhost),
                desired_code=codes.no_content,
                headers=headers,
                auth=auth
            )
        except Exception, e:
            raise Exception("create vhost failed: %s" % e)

        try:
            # 创建账户
            http.http_request(
                method="PUT",
                url="%s/api/users/%s" % (server_url, app_code),
                desired_code=codes.no_content,
                headers=headers,
                auth=auth,
                json={"password": user_account['password'], "tags": "management"}
            )
        except Exception, e:
            raise Exception("create account failed: %s" % e)
Exemplo n.º 5
0
 def _request(self, bk_servers, handle):
     params = {
         "app_code": self.bk_app.app_code,
         "event_id": str(self.bk_app_event.id),
         "deploy_token": self.deploy_config.get("deploy_token", ''),
         "deploy_vars": self.deploy_config.get("deploy_vars", {}),
         "saas_settings": self.deploy_config.get("saas_settings", {}),
         "mode": self.mode,
         "envs": self.bk_app.app_envs[self.mode],
     }
     for bk_server in bk_servers:
         resp = http.http_request(
             method="POST",
             url="http://%s:%s/v1/app/%s" %
             (bk_server.ip_address, bk_server.ip_port, handle),
             headers=utils.agent_header(bk_server.s_id, bk_server.token),
             json=params)
         if resp["error"] != 0:
             raise Exception(resp.get("msg"))
Exemplo n.º 6
0
            http.http_request(
                method="PUT",
                url="%s/api/users/%s" % (server_url, app_code),
                desired_code=codes.no_content,
                headers=headers,
                auth=auth,
                json={"password": user_account['password'], "tags": "management"}
            )
        except Exception, e:
            raise Exception("create account failed: %s" % e)

        try:
            http.http_request(
                method="PUT",
                url="%s/api/permissions/%s/%s" % (server_url, vhost, app_code),
                desired_code=codes.no_content,
                headers=headers,
                auth=auth,
                json={"configure": ".*", "write": ".*", "read": ".*"}
            )
        except Exception, e:
            raise Exception("vhost authorization failed: %s" % e)

    def health_check(self, server_id):
        try:
            server_data = models.ThirdServer.objects.get(id=server_id,
                                                         category=models.THIRD_SERVER_CATEGORY_MQ).server_data
        except models.ThirdServer.DoesNotExist:
            raise Exception("no rabbitmq server is active")

        try:
            http.http_request(