Beispiel #1
0
 def verify_source(self, tenant, region, new_add_memory, reason=""):
     """判断资源"""
     data = {
         "quantity": new_add_memory,
         "reason": reason,
         "eid": tenant.enterprise_id
     }
     if new_add_memory == 0:
         return True, "success"
     # is_public = settings.MODULES.get('SSO_LOGIN')
     # if not is_public or new_add_memory <= 0:
     #     return allow_create, tips
     try:
         res, body = region_api.service_chargesverify(region, tenant.tenant_name, data)
         logger.debug("verify body {0}".format(body))
         if not body:
             return True, "success"
         msg = body.get("msg", None)
         if not msg or msg == "success":
             return True, "success"
         elif msg == "illegal_quantity":
             raise ResourceNotEnoughException("资源申请非法,请联系管理员")
         elif msg == "missing_tenant":
             raise ResourceNotEnoughException("团队不存在")
         elif msg == "owned_fee":
             raise AccountOverdueException("账户已欠费")
         elif msg == "region_unauthorized":
             raise ResourceNotEnoughException("数据中心未授权")
         elif msg == "lack_of_memory":
             raise ResourceNotEnoughException("团队可用资源不足,请联系企业管理员")
         elif msg == "cluster_lack_of_memory":
             raise ResourceNotEnoughException("集群资源不足,请联系集群管理员")
     except region_api.CallApiError as e:
         logger.exception(e)
         raise e
Beispiel #2
0
 def verify_source(self, tenant, region, new_add_memory, reason=""):
     """判断资源"""
     allow_create = True
     tips = u"success"
     data = {
         "quantity": new_add_memory,
         "reason": reason,
         "eid": tenant.enterprise_id
     }
     is_public = settings.MODULES.get('SSO_LOGIN')
     if not is_public or new_add_memory <= 0:
         return allow_create, tips
     try:
         res, body = region_api.service_chargesverify(region, tenant.tenant_name, data)
         logger.debug("verify body {0}".format(body))
         if not body:
             return True, "success"
         msg = body.get("msg", None)
         if not msg or msg == "success":
             return True, "success"
         else:
             raise ResourceNotEnoughException("资源不足,无法操作")
     except region_api.CallApiError as e:
         logger.exception(e)
         raise e