offline.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- encoding:utf-8 -*-
  2. from kscore.session import get_session
  3. import time
  4. class OfflineClient:
  5. def __init__(self,service_name,region_name,use_ssl,ks_access_key_id,ks_secret_access_key):
  6. s = get_session()
  7. if ks_access_key_id != None and ks_secret_access_key != None:
  8. self.client = s.create_client(service_name, region_name, use_ssl = use_ssl,
  9. ks_access_key_id=ks_access_key_id, ks_secret_access_key=ks_secret_access_key)
  10. else:
  11. self.client = s.create_client(service_name, region_name, use_ssl = use_ssl)
  12. def Preset(self,param):
  13. return self.client.preset(**param)
  14. def UpdatePreset(self,param):
  15. return self.client.update_preset(**param)
  16. def DelPreset(self,presetName):
  17. return self.client.del_preset(preset = presetName)
  18. def GetPresetList(self,withDetail=0,presettype='',presets=''):
  19. return self.client.get_preset_list(withDetail = withDetail,presettype=presettype,presets=presets)
  20. def GetPresetDetail(self,presetName):
  21. return self.client.get_preset_detail(preset = presetName)
  22. def CreateTask(self,task):
  23. return self.client.create_task(**task)
  24. def GetTaskByTaskID(self,taskid):
  25. return self.client.get_task_by_task_id(taskid = taskid)
  26. def GetTaskList(self,startdate=0,enddate=0,marker=0,limit=100):
  27. if startdate == 0:
  28. startdate = int(time.strftime('%Y%m',time.localtime(time.time()))+"01")
  29. if enddate == 0:
  30. return self.client.get_task_list(startdate=startdate,marker=marker,limit=limit)
  31. else:
  32. return self.client.get_task_list(startdate=startdate,enddate=enddate,marker=marker,limit=limit)
  33. def DelTaskByTaskID(self,taskid):
  34. return self.client.del_task_by_task_id(taskid = taskid)
  35. def TopTaskByTaskID(self,taskid):
  36. return self.client.top_task_by_task_id(taskid = taskid)
  37. def GetTaskMetaInfo(self,taskid = "",startdate=0,enddate=0,marker=0,limit=0):
  38. if taskid == "":
  39. if startdate == 0:
  40. startdate = int(time.strftime('%Y%m',time.localtime(time.time()))+"01")
  41. if enddate == 0:
  42. return self.client.get_task_list(startdate=startdate,marker=marker,limit=limit)
  43. else:
  44. return self.client.get_task_list(startdate=startdate,enddate=enddate,marker=marker,limit=limit)
  45. else:
  46. return self.client.get_task_meta_info(taskid = taskid)
  47. def getOfflineClient(service_name,region_name,use_ssl=False,ks_access_key_id=None, ks_secret_access_key=None):
  48. return OfflineClient(service_name,region_name,use_ssl,ks_access_key_id, ks_secret_access_key)