def commit(self): """ commit victim and related assets, associations """ r_id = self.id ro = RequestObject() ro.set_body(self.gen_body) ro.set_resource_type(self.resource_type) prop = self._resource_properties['add'] ro.set_description('adding batchjob') ro.set_http_method(prop['http_method']) ro.set_owner_allowed(prop['owner_allowed']) ro.set_request_uri(prop['uri'].format(self._id)) ro.empty_payload() if self._phase == 1: # validate all required fields are present if self.validate: api_response = self._tc.api_request(ro) if api_response.headers['content-type'] == 'application/json': api_response_dict = api_response.json() if api_response_dict['status'] == 'Success': r_id = api_response_dict['data']['batchId'] else: self._tc.tcl.debug('Resource Object'.format(self)) raise RuntimeError('Cannot commit incomplete resource object') for ro in self._resource_container.commit_queue(self.id): # if self.owner_name is not None: # ro.set_owner(self.owner_name) # replace the id if self.id != r_id: request_uri = str( ro.request_uri.replace(str(self.id), str(r_id))) ro.set_request_uri(request_uri) self._tc.tcl.debug('Replacing {0} with {1}'.format( self.id, str(r_id))) self._tc.tcl.debug('RO {0}'.format(ro)) api_response2 = self._tc.api_request(ro) if api_response2.headers['content-type'] == 'application/json': api_response_dict2 = api_response2.json() if api_response_dict2['status'] != 'Success': self._tc.tcl.error('API Request Failure: [{0}]'.format( ro.description)) self.set_id(r_id) self.set_phase(0) # return object return self
def upload(self, body): """ upload batch job """ prop = self._resource_properties['batch_job_upload'] ro = RequestObject() ro.set_body(body) ro.set_content_type('application/octet-stream') ro.set_description('upload batch job for "{0}"'.format(self._id)) ro.set_http_method(prop['http_method']) ro.set_owner_allowed(prop['owner_allowed']) ro.set_request_uri(prop['uri'].format(self._id)) ro.set_resource_pagination(prop['pagination']) ro.set_resource_type(self._resource_type) ro.empty_payload() self._resource_container.add_commit_queue(self.id, ro)
def commit(self): """ commit victim and related assets, associations """ r_id = self.id ro = RequestObject() ro.set_body(self.gen_body) ro.set_resource_type(self.resource_type) prop = self._resource_properties['add'] ro.set_description('adding batchjob') ro.set_http_method(prop['http_method']) ro.set_owner_allowed(prop['owner_allowed']) ro.set_request_uri(prop['uri'].format(self._id)) ro.empty_payload() if self._phase == 1: # validate all required fields are present if self.validate: api_response = self._tc.api_request(ro) if api_response.headers['content-type'] == 'application/json': api_response_dict = api_response.json() if api_response_dict['status'] == 'Success': r_id = api_response_dict['data']['batchId'] else: self._tc.tcl.debug('Resource Object'.format(self)) raise RuntimeError('Cannot commit incomplete resource object') for ro in self._resource_container.commit_queue(self.id): # if self.owner_name is not None: # ro.set_owner(self.owner_name) # replace the id if self.id != r_id: request_uri = str(ro.request_uri.replace(str(self.id), str(r_id))) ro.set_request_uri(request_uri) self._tc.tcl.debug('Replacing {0} with {1}'.format(self.id, str(r_id))) self._tc.tcl.debug('RO {0}'.format(ro)) api_response2 = self._tc.api_request(ro) if api_response2.headers['content-type'] == 'application/json': api_response_dict2 = api_response2.json() if api_response_dict2['status'] != 'Success': self._tc.tcl.error('API Request Failure: [{0}]'.format(ro.description)) self.set_id(r_id) self.set_phase(0) # return object return self