def on_result(result): if result.code == 200: return txhttp.collect(result, on_log) elif result.code == 404: return self.collect_to_exception(NotFound, result) else: return self.collect_to_exception(CommandFailed, result)
def build_image(self, dockerfile, ticket_id=None): headers = {'Content-Type': 'application/tar'} result = {} def on_content(chunk): self.task_log(ticket_id, chunk) if not 'image_id' in result: match = re.search(r'Successfully built ([0-9a-f]+)', chunk) if match: result['image_id'] = match.group(1) response = yield self._post('build', data=dockerfile, headers=headers, response_handler=None) yield txhttp.collect(response, on_content) defer.returnValue(result['image_id'])