2
0

kvs.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # -*- encoding:utf-8 -*-
  2. import time
  3. from kscore.session import get_session
  4. class KvsClient:
  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,Preset=''):
  17. return self.client.del_preset(Preset=Preset)
  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,Preset=''):
  21. return self.client.get_preset_detail(Preset=Preset)
  22. def CreateTask(self,task):
  23. return self.client.create_task(**task)
  24. def FetchMetaInfo(self,task):
  25. return self.client.fetch_meta_info(**task)
  26. def CreateFlowTask(self,task):
  27. return self.client.create_flow_task(**task)
  28. def FetchObjectMediaProcess(self,task):
  29. return self.client.fetch_object_media_process(**task)
  30. def GetTaskByTaskID(self,TaskID=''):
  31. return self.client.get_task_by_task_id(TaskID=TaskID)
  32. def GetTaskList(self,StartDate=0,EndDate=0,Marker=0,Limit=100,StartTime=0,EndTime=0,ErrorCode='',TaskStatus=''):
  33. if StartDate == 0:
  34. StartDate = int(time.strftime('%Y%m',time.localtime(time.time()))+"01")
  35. if EndDate == 0:
  36. return self.client.get_task_list(StartDate=StartDate,Marker=Marker,Limit=Limit,StartTime=StartTime,EndTime=EndTime,ErrorCode=ErrorCode,TaskStatus=TaskStatus)
  37. else:
  38. return self.client.get_task_list(StartDate=StartDate,EndDate=EndDate,Marker=Marker,Limit=Limit,StartTime=StartTime,EndTime=EndTime,ErrorCode=ErrorCode,TaskStatus=TaskStatus)
  39. def DelTaskByTaskID(self,TaskID = ''):
  40. return self.client.del_task_by_task_id(TaskID = TaskID)
  41. def TopTaskByTaskID(self,TaskID = ''):
  42. return self.client.top_task_by_task_id(TaskID = TaskID)
  43. def GetTaskMetaInfo(self,TaskID = '',StartDate=0,EndDate=0,Marker=0,Limit=100):
  44. if TaskID == "":
  45. if StartDate == 0:
  46. StartDate = int(time.strftime('%Y%m',time.localtime(time.time()))+"01")
  47. if EndDate == 0:
  48. return self.client.get_task_list(StartDate=StartDate,Marker=Marker,Limit=Limit)
  49. else:
  50. return self.client.get_task_list(StartDate=StartDate,EndDate=EndDate,Marker=Marker,Limit=Limit)
  51. else:
  52. return self.client.get_task_meta_info(TaskID = TaskID)
  53. def UpdatePipeline(self,param):
  54. return self.client.update_pipeline(**param)
  55. def QueryPipeline(self,PipelineName="usual"):
  56. return self.client.query_pipeline(PipelineName=PipelineName)
  57. def QueryTaskStats(self,Preset="", StartDate=20170101):
  58. return self.client.query_task_stats(Preset=Preset, StartDate=StartDate)
  59. def GetInterfaceNumber(self,StartUnixTime,EndUnixTime,Granularity=5,ResultType=1):
  60. return self.client.get_interface_number(StartUnixTime=StartUnixTime,EndUnixTime=EndUnixTime,Granularity=Granularity,ResultType=ResultType)
  61. def GetMediaTransDuration(self,StartUnixTime=0,EndUnixTime=0,Granularity=5,ResultType=1):
  62. return self.client.get_media_trans_duration(StartUnixTime=StartUnixTime,EndUnixTime=EndUnixTime,Granularity=Granularity,ResultType=ResultType)
  63. def GetScreenshotNumber(self,StartUnixTime,EndUnixTime,Granularity=5,ResultType=1):
  64. return self.client.get_screenshot_number(StartUnixTime=StartUnixTime,EndUnixTime=EndUnixTime,Granularity=Granularity,ResultType=ResultType)
  65. def getKvsClient(service_name,region_name,use_ssl=False,ks_access_key_id=None, ks_secret_access_key=None):
  66. return KvsClient(service_name,region_name,use_ssl,ks_access_key_id, ks_secret_access_key)