def _delete_request(self): private_key = self.conf_params['private_key'] task_id = self.delete_params['TaskId'] self.delete_params['Signature'] = _verfy_ac(private_key, self.delete_params) uai_logger.debug('==' * 10) uai_logger.info( "Start to make delete task {0} request".format(task_id)) r = requests.get(self.delete_url, params=self.delete_params) if r.status_code != requests.codes.ok: uai_logger.debug('================================') uai_logger.warning('Delete Error, PLS check your connection') sys.exit(0) json_data = json.loads(r.text) r_info = {} for k, v in json_data.items(): if isinstance(k, unicode): k = k.encode('utf-8') if isinstance(v, unicode): v = v.encode('utf-8') r_info[k] = v if check_retcode(r_info) != NORMAL_CONDITION: uai_logger.error('Delete Error: {0}'.format(r_info['Message'])) sys.exit(0) else: uai_logger.info('Delete task id {0} successful'.format(task_id))
def _make_request(self): self.request_params['Signature'] = _verfy_ac( self.request_params['PrivateKey'], self.request_params) uai_logger.info('=====================================') uai_logger.info('Send AI Service Deploy Request') uai_logger.debug(self.request_url) uai_logger.debug(self.request_params) r = requests.get(self.request_url, params=self.request_params, timeout=600) uai_logger.info('=====================================') uai_logger.info('Get API Request Response:') uai_logger.info(r.status_code) uai_logger.debug('the deploy request url: {0}'.format(r.url)) uai_logger.debug('the all info {0}'.format(r.text)) if r.status_code != requests.codes.ok: uai_logger.info('Deploy Error! Please Retry') sys.exit(0) json_data = json.loads(r.text) r_info = {} for k, v in json_data.items(): if isinstance(k, unicode): k = k.encode('utf-8') if isinstance(v, unicode): v = v.encode('utf-8') r_info[k] = v self.deploy_response = r_info uai_logger.info('Start Setting Up, Your application ID is {0}'.format( r_info['Id'])) self.id_file.write('Id: {0}\n'.format(r_info['Id']))
def _check_request(self): max_poll_steps = MAX_POLL_STEPS uai_logger.debug('=' * 10 + 'Start poll the state of deploy' + '=' * 10) uai_logger.debug('the url to check the state of deploy: {0}'.format( self.check_url)) self.check_params['Signature'] = _verfy_ac( self.request_params['PrivateKey'], self.check_params) for step in range(max_poll_steps): uai_logger.debug( 'the step {0} to poll the state of the deploy'.format(step)) r = requests.get(self.check_url, params=self.check_params) uai_logger.debug('the result of step {0}'.format(step)) if r.status_code != requests.codes.ok: uai_logger.warning('================================') uai_logger.warning('Check Error, PLS check your connection') break json_data = json.loads(r.text) r_info = {} for k, v in json_data.items(): if isinstance(k, unicode): k = k.encode('utf-8') if isinstance(v, unicode): v = v.encode('utf-8') r_info[k] = v if check_retcode(r_info) != NORMAL_CONDITION: uai_logger.warning('Deploy Error: {0}'.format( r_info['Message'])) break else: if r_info['Status'] == 'SUCCESS': uai_logger.info( 'Building Success, the domain of your deploy application is {0}' .format(r_info['Domain'])) self.id_file.write('URL: {0}\n'.format(r_info['Domain'])) break elif r_info['Status'] == 'BUILDING': uai_logger.info('Building Image Now') time.sleep(5) continue elif r_info['Status'] == 'PUSHIMAGE': uai_logger.info('Pushing Image Now') time.sleep(5) continue elif r_info['Status'] == 'PAASDEPLOY': uai_logger.info('Creating App On PAAS Now') time.sleep(5) continue elif r_info['Status'] == 'FAILED': uai_logger.error('Error Message: {0} '.format( r_info['Message'])) break
def _cmd_common_request(self): if 'Signature' in self.cmd_params: self.cmd_params.pop('Signature') self.cmd_params['Signature'] = _verfy_ac(self.private_key, self.cmd_params) uai_logger.info("Call http request: {0} ".format(get_request(self.cmd_url, params=self.cmd_params))) r = requests.get(self.cmd_url, params=self.cmd_params) print(r.text) self.rsp = json.loads(r.text, encoding="utf-8") if self.rsp["RetCode"] != 0: uai_logger.error("{0} Fail: [{1}]{2}".format(self.cmd_params["Action"], self.rsp["RetCode"], self.rsp["Message"].encode('utf-8'))) return False else: del self.rsp['Action'] uai_logger.info("{0} Success: {1}".format(self.cmd_params["Action"], get_response(self.rsp, 0))) return True
def _cmd_common_request(self): if ('Signature' in self.cmd_params) is True: self.cmd_params.pop('Signature') self.cmd_params['Signature'] = _verfy_ac(self.priv_key, self.cmd_params) uai_logger.info("Signature: {0}".format(self.cmd_params['Signature'])) uai_logger.info(self.cmd_params) uai_logger.info("Call http request: {0} ".format( get_request(self.cmd_url, params=self.cmd_params))) r = requests.get(self.cmd_url, params=self.cmd_params) rsp = json.loads(r.text, encoding='utf-8') if rsp['RetCode'] != 0: uai_logger.error("{0} Fail: [{1}]{2}".format( self.cmd_params[PARAM_ACTION], rsp['RetCode'], rsp['Message'].encode('utf-8'))) return False, rsp else: del rsp[PARAM_ACTION] return True, rsp
def _cmd_writefile_package(self, filepath): if ('Signature' in self.cmd_params) is True: self.cmd_params.pop('Signature') self.cmd_params['Signature'] = _verfy_ac( self.conf_params['private_key'], self.cmd_params) uai_logger.info("Call http request: {0} ".format( get_request(self.cmd_url, params=self.cmd_params))) r = requests.get(self.cmd_url, params=self.cmd_params) rsp = json.loads(r.text, encoding='utf-8') if rsp["RetCode"] != 0: uai_logger.error("{0} Fail: [{1}]{2}".format( self.cmd_params["Action"], rsp["RetCode"], rsp["Message"].encode('utf-8'))) raise RuntimeError("{0} Fail: [{1}]{2}".format( self.cmd_params["Action"], rsp["RetCode"], rsp["Message"].encode('utf-8'))) else: with open(filepath, 'w') as f: json.dump(rsp["PkgSet"], f)