Exemple #1
0
def ALICDNRefresh(domain, ak, sk):
    try:
        CLI = AcsClient(ak, sk, 'cn-hangzhou')
        request = RefreshObjectCachesRequest()
        request.set_ObjectType('Directory')
        request.set_accept_format('json')
        request.set_ObjectPath(domain)
        json.loads(CLI.do_action_with_exception(request))
        return {"msg": "刷新完成", "refresh_url": domain, "code": 200}
    except aliexceptions.ServerException as err:
        return {"msg": "刷新失败", "refresh_url": str(err), "code": 5001}
Exemple #2
0
    def flush(self, obj_uri, obj_type):
        request = RefreshObjectCachesRequest()
        request.set_accept_format('json')

        # 其值可以为File或Directory
        # print(11111, obj_uri, obj_type)
        request.set_ObjectType(obj_type)
        request.set_ObjectPath(obj_uri.strip())

        response = self.client.do_action_with_exception(request)
        return str(response, encoding='utf-8')
def refresh_cache(path, fresh_type):
    request = RefreshObjectCachesRequest()
    request.set_accept_format('json')

    request.set_ObjectPath(path)  # 刷新单个url
    request.set_ObjectType(fresh_type)
    # request.set_ObjectPath("http://lly-img.linlinyi.cn/wxapp/1.1.0/ling/bg_redpacket_new1x.png")  # 刷新单个url
    # request.set_ObjectType("URL")

    response = client.do_action_with_exception(request)
    print(str(response, encoding='utf-8'))
    def refresh(self, objectpath, type='File'):
        for path in objectpath:
            request = RefreshObjectCachesRequest()
            request.set_accept_format('json')

            request.set_ObjectType(type)
            request.set_ObjectPath(path)
            response = self.client.do_action_with_exception(request)

            if sys.version_info[0] > 2:
                res_json = json.loads(str(response, encoding='utf-8'))
            else:
                res_json = json.loads(response)
            print(res_json)
Exemple #5
0
 def refresh_cdn(self):
     project_name, server, _ = self.get_param()
     if project_name != 'heplus/heplus-frontend':
         return
     if server != 'heplus':
         return
     client = AcsClient(constants.ALIYUN_OSS_ACCESS_KEY_ID, constants.ALIYUN_OSS_ACCESS_KEY_SECRET, 'cn-hangzhou')
     request = RefreshObjectCachesRequest()
     request.set_accept_format('json')
     request.set_ObjectPath(constants.HEPLUS_URL)
     response = client.do_action_with_exception(request)
     return str(response, encoding='utf-8')
    def purge_cdn(self, operation_type, refresh_type, url):


        # PUSH為主動推送阿里節點進行預熱
        if operation_type == 'push':
            self.request = PushObjectCacheRequest()
            self.request.set_accept_format('json')
            self.request.set_ObjectPath(url)


        # REFRESH為阿里回源服務器拉取資源
        elif operation_type == 'refresh':
            self.request = RefreshObjectCachesRequest()
            self.request.set_accept_format('json')

            if refresh_type == 'url':
                self.request.set_ObjectType("File")
                self.request.set_ObjectPath(url)

            elif refresh_type == 'dir':
                self.request.set_ObjectType("Directory")
                self.request.set_ObjectPath(url)


        try:
            response = self.client.do_action_with_exception(self.request)
            result = json.loads(response)
            return result
        except ServerException as e:
            print(e.message)
            print(e.http_status)
            return {
                "http_status": e.http_status,
                "error_code" : e.error_code,
                "message"    : e.message
            }
Exemple #7
0
 def doRefresh(lists):
     try:
         if Envariable.get_acs_client():
             client = Envariable.get_acs_client()
         else:
             Envariable.set_acs_client()
             client = Envariable.get_acs_client()
         if Envariable.get_task_type() == 'clear':
             taskID = 'RefreshTaskId'
             request = RefreshObjectCachesRequest()
             if Envariable.get_task_otype():
                 request.set_ObjectType(Envariable.get_task_otype())
         elif Envariable.get_task_type() == 'push':
             taskID = 'PushTaskId'
             request = PushObjectCacheRequest()
             if Envariable.get_task_area():
                 request.set_Area(Envariable.get_task_area())
         taskreq = DescribeRefreshTasksRequest()
         request.set_accept_format('json')
         request.set_ObjectPath(lists)
         response = json.loads(client.do_action_with_exception(request))
         print(response)
         timeout = 0
         while True:
             count = 0
             taskreq.set_accept_format('json')
             taskreq.set_TaskId(int(response[taskID].split(',')[0]))
             taskresp = json.loads(client.do_action_with_exception(taskreq))
             print("[" + response[taskID] + "]" + "is doing... ...")
             for t in taskresp['Tasks']['CDNTask']:
                 if t['Status'] != 'Complete':
                     count += 1
             if count == 0:
                 logging.info("[" + response[taskID] + "]" + "is finish")
                 break
             elif timeout > 5:
                 logging.info("[" + response[taskID] + "]" + "timeout")
                 break
             else:
                 timeout += 1
                 time.sleep(5)
                 continue
     except Exception as e:
         logging.info("\n[error]:%s", e) and sys.exit(1)
Exemple #8
0
  def doRefresh(self,lists,types,client):

    try:

      if types == 'clear':

        taskID = 'RefreshTaskId'

        request = RefreshObjectCachesRequest()

        if self.param.has_key('-o'):

          request.set_ObjectType(self.param['-o'])

      elif types == 'push':

        taskID = 'PushTaskId'

        request = PushObjectCacheRequest()

        if self.param.has_key('-a'):

          request.set_Area(self.param['-a'])



      taskreq = DescribeRefreshTasksRequest()

      request.set_accept_format('json')

      request.set_ObjectPath(lists)

      response = json.loads(client.do_action_with_exception(request))

      print(response)

    

      while True:

        count = 0

        taskreq.set_accept_format('json')

        taskreq.set_TaskId(int(response[taskID]))

        taskresp = json.loads(client.do_action_with_exception(taskreq))

        print("[" + response[taskID] + "]" + "is doing... ...")

        for t in taskresp['Tasks']['CDNTask']:

          if t['Status'] != 'Complete':

            count += 1

        if count == 0:

          break

        else:

          continue

        time.sleep(5)

    except Exception as e:

      sys.exit("[Error]" + str(e))