Пример #1
0
 def get(self, request, enterprise_id, *args, **kwargs):
     regions = region_repo.get_usable_regions(enterprise_id)
     region_memory_total = 0
     region_memory_used = 0
     region_cpu_total = 0
     region_cpu_used = 0
     if not regions:
         result = general_message(404, "no found", None)
         return Response(result, status=status.HTTP_200_OK)
     region_num = len(regions)
     for region in regions:
         try:
             res, body = region_api.get_region_resources(enterprise_id, region=region.region_name)
             if res.get("status") == 200:
                 region_memory_total += body["bean"]["cap_mem"]
                 region_memory_used += body["bean"]["req_mem"]
                 region_cpu_total += body["bean"]["cap_cpu"]
                 region_cpu_used += body["bean"]["req_cpu"]
         except Exception as e:
             logger.debug(e)
             continue
     data = {
         "total_regions": region_num,
         "memory": {
             "used": region_memory_used,
             "total": region_memory_total
         },
         "cpu": {
             "used": region_cpu_used,
             "total": region_cpu_total
         }
     }
     result = general_message(200, "success", None, bean=data)
     return Response(result, status=status.HTTP_200_OK)
Пример #2
0
    def get_app_share_region(self, app):
        app_template = json.loads(app.app_template)
        apps = app_template["apps"]
        first_app = apps[0]
        if first_app:
            region = first_app.get("service_region", None)
        else:
            group = group_repo.get_group_by_id(app.tenant_service_group_id)
            if group:
                region = group.region_name
            else:
                region = None

        if region:
            region_config = region_repo.get_region_by_region_name(region)
            if region_config:
                return region
            region = None
        else:
            region = None
        if not region and app.source == "market":
            regions = region_repo.get_usable_regions()
            if not regions:
                return None
            else:
                return regions[0].region_name
        else:
            return None
Пример #3
0
 def create_team(self, user, enterprise, region_list=None, team_alias=None):
     team_name = self.random_tenant_name(enterprise=user.enterprise_id, length=8)
     is_public = settings.MODULES.get('SSO_LOGIN')
     if not is_public:
         pay_type = 'payed'
         pay_level = 'company'
     else:
         pay_type = 'free'
         pay_level = 'company'
     expired_day = 7
     if hasattr(settings, "TENANT_VALID_TIME"):
         expired_day = int(settings.TENANT_VALID_TIME)
     expire_time = datetime.datetime.now() + datetime.timedelta(days=expired_day)
     if not region_list:
         region_list = [r.region_name for r in region_repo.get_usable_regions()]
         if not region_list:
             return 404, "无可用数据中心", None
     default_region = region_list[0]
     if not team_alias:
         team_alias = "{0}的团队".format(user.nick_name)
     params = {
         "tenant_name": team_name,
         "pay_type": pay_type,
         "pay_level": pay_level,
         "creater": user.user_id,
         "region": default_region,
         "expired_time": expire_time,
         "tenant_alias": team_alias,
         "enterprise_id": enterprise.enterprise_id,
         "limit_memory": 4096
     }
     team = team_repo.create_tenant(**params)
     return 200, "success", team
Пример #4
0
 def __is_domain_conflict(self, domain_name, team_name):
     regions = region_repo.get_usable_regions()
     conflict_domains = ["{0}.{1}".format(team_name, region.httpdomain) for region in regions]
     for d in conflict_domains:
         if d in domain_name:
             return True, d
     return False, None
Пример #5
0
 def get(self, request, enterprise_id, *args, **kwargs):
     regions = region_repo.get_usable_regions(enterprise_id)
     if not regions:
         result = general_message(404, "no found regions", "查询成功")
         return Response(result, status=200)
     data = enterprise_services.get_enterprise_runing_service(enterprise_id, regions)
     result = general_message(200, "success", "查询成功", bean=data)
     return Response(result, status=status.HTTP_200_OK)
Пример #6
0
 def get_team_usable_regions(self, team_name, enterprise_id):
     usable_regions = region_repo.get_usable_regions(enterprise_id)
     region_names = [r.region_name for r in usable_regions]
     team_opened_regions = region_repo.get_team_opened_region(team_name)
     if team_opened_regions:
         team_opened_regions = team_opened_regions.filter(
             is_init=True, region_name__in=region_names)
     return team_opened_regions
Пример #7
0
 def get_team_unopen_region(self, team_name):
     usable_regions = region_repo.get_usable_regions()
     team_opened_regions = region_repo.get_team_opened_region(team_name).filter(is_init=True)
     opened_regions_name = [
         team_region.region_name for team_region in team_opened_regions
     ]
     unopen_regions = usable_regions.exclude(
         region_name__in=opened_regions_name)
     return [unopen_region.to_dict() for unopen_region in unopen_regions]
Пример #8
0
 def get_team_usable_regions(self, team_name):
     usable_regions = region_repo.get_usable_regions()
     region_names = [r.region_name for r in usable_regions]
     team_opened_regions = region_repo.get_team_opened_region(
         team_name).filter(is_init=True, region_name__in=region_names)
     return team_opened_regions
Пример #9
0
 def get_open_regions(self):
     usable_regions = region_repo.get_usable_regions()
     return usable_regions
 def get_open_regions(self, enterprise_id):
     usable_regions = region_repo.get_usable_regions(enterprise_id)
     return usable_regions