def get(self, request, region_id, *args, **kwargs):
        extend_info = request.GET.get("extend_info", False)
        if extend_info == "true":
            extend_info = True
        else:
            extend_info = False
        if extend_info:
            extend_info = "yes"
        if not self.region:
            raise ServiceHandleException(msg="no found region", msg_show=u"数据中心不存在", status_code=404)

        data = region_services.get_enterprise_region(
            self.enterprise.enterprise_id, self.region.region_id, check_status=extend_info)
        serializers = RegionInfoRSerializer(data=data)
        serializers.is_valid(raise_exception=True)
        return Response(serializers.data, status=200)
Esempio n. 2
0
 def dispatch(self, request, enterprise_id, region_id, *args, **kwargs):
     self.args = args
     self.kwargs = kwargs
     request = self.initialize_request(request, *args, **kwargs)
     self.request = request
     self.headers = self.default_response_headers
     try:
         self.initial(request, *args, **kwargs)
         region = region_services.get_enterprise_region(enterprise_id, region_id, check_status=False)
         if not region:
             return Response({}, status=status.HTTP_404_NOTFOUND)
         full_path = request.get_full_path()
         path = full_path[full_path.index("/dashboard/") + 11:len(full_path)]
         response = region_api.proxy(request, '/kubernetes/dashboard/' + path, region['region_name'])
     except Exception as exc:
         response = self.handle_exception(exc)
     self.response = self.finalize_response(request, response, *args, **kwargs)
     return self.response
Esempio n. 3
0
 def post(self, request, enterprise_id, *args, **kwargs):
     token = request.data.get("token")
     region_name = request.data.get("region_name")
     region_alias = request.data.get("region_alias")
     desc = request.data.get("desc")
     region_type = json.dumps(request.data.get("region_type", []))
     region_data = region_services.parse_token(token, region_name, region_alias, region_type)
     region_data["enterprise_id"] = enterprise_id
     region_data["desc"] = desc
     region_data["provider"] = request.data.get("provider", "")
     region_data["provider_cluster_id"] = request.data.get("provider_cluster_id", "")
     region_data["status"] = "1"
     region = region_services.add_region(region_data)
     if region:
         data = region_services.get_enterprise_region(enterprise_id, region.region_id, check_status=False)
         result = general_message(200, "success", "创建成功", bean=data)
         return Response(result, status=status.HTTP_200_OK)
     else:
         result = general_message(500, "failed", "创建失败")
         return Response(result, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Esempio n. 4
0
 def get(self, request, enterprise_id, region_id, *args, **kwargs):
     data = region_services.get_enterprise_region(enterprise_id, region_id, check_status=False)
     result = general_message(200, "success", "获取成功", bean=data)
     return Response(result, status=status.HTTP_200_OK)