def remove_image_by_id(host_id, long_id, force=False, noprune=False): try: _image = Image_Module() if not _image.set_host(host_id).check_health(): return { "status": "failed", "result": { "error": _("Error, Unable to connect to docker host!") }, "notify_type": "failed" } _image.remove_by_id( long_id=long_id, force=force, noprune=noprune ) return { "status": "passed", "result": "{}", "notify_type": "passed" } except Exception as e: return { "status": "error", "result": { "error": str(e) }, "notify_type": "error" }
def __init__(self): self.__request = Request() self.__response = Response() self.__helpers = Helpers() self.__form = Form() self.__host_module = Host_Module() self.__image_module = Image_Module() self.__logger = self.__helpers.get_logger(__name__)
def build_image(host_id, fileobj, tag, rm=False, nocache=False): try: _image = Image_Module() if not _image.set_host(host_id).check_health(): return { "status": "failed", "result": { "error": _("Error, Unable to connect to docker host!") }, "notify_type": "failed" } result = _image.build( fileobj=fileobj, tag=tag, rm=rm, nocache=nocache ) if result: return { "status": "passed", "result": "{}", "notify_type": "passed" } else: return { "status": "failed", "result": "{}", "notify_type": "failed" } except Exception as e: return { "status": "error", "result": { "error": str(e) }, "notify_type": "error" }
def tag_image_by_id(host_id, long_id, repository, tag=None, force=False): try: _image = Image_Module() if not _image.set_host(host_id).check_health(): return { "status": "failed", "result": { "error": _("Error, Unable to connect to docker host!") }, "notify_type": "failed" } result = _image.tag_by_id( long_id=long_id, repository=repository, tag=tag, force=force ) if result: return { "status": "passed", "result": "{}", "notify_type": "passed" } else: return { "status": "failed", "result": "{}", "notify_type": "failed" } except Exception as e: return { "status": "error", "result": { "error": str(e) }, "notify_type": "error" }
def pull_image(host_id, image_name): try: _image = Image_Module() if not _image.set_host(host_id).check_health(): return { "status": "failed", "result": { "error": _("Error, Unable to connect to docker host!") }, "notify_type": "failed" } image_name = image_name.split(":") result = _image.pull( image_name[0], image_name[1] ) if result: return { "status": "passed", "result": "{}", "notify_type": "passed" } else: return { "status": "failed", "result": "{}", "notify_type": "failed" } except Exception as e: return { "status": "error", "result": { "error": str(e) }, "notify_type": "error" }
def prune_all_unused_images(host_id): try: _image = Image_Module() if not _image.set_host(host_id).check_health(): return { "status": "failed", "result": { "error": _("Error, Unable to connect to docker host!") }, "notify_type": "failed" } result = _image.prune_all_unused() if result: return { "status": "passed", "result": "{}", "notify_type": "passed" } else: return { "status": "failed", "result": "{}", "notify_type": "failed" } except Exception as e: return { "status": "error", "result": { "error": str(e) }, "notify_type": "error" }
def tag_image_by_id(self, configs={}): _image = Image_Module() if _image.set_host(configs["host_id"]).check_health(): print( _image.tag_by_id(configs["image_id"], configs["repository"], configs["tag"]))
def build_image(self, configs={}): _image = Image_Module() if _image.set_host(configs["host_id"]).check_health(): print( _image.build(File().read(configs["dockerfile"]), configs["tag"]))
def remove_image_by_id(self, configs={}): _image = Image_Module() if _image.set_host(configs["host_id"]).check_health(): print( _image.remove_by_id(configs["image_id"], configs["force"] == "True"))
def get_image_by_id(self, configs={}): _image = Image_Module() if _image.set_host(configs["host_id"]).check_health(): print(_image.get_by_id(configs["image_id"]))
def remove_image_by_name(self, configs={}): _image = Image_Module() if _image.set_host(configs["host_id"]).check_health(): print(_image.remove_by_name(configs["repository"], configs["tag"]))
def prune_all_unused_images(self, configs={}): _image = Image_Module() if _image.set_host(configs["host_id"]).check_health(): print(_image.prune_all_unused())
def list_images(self, configs={}): _image = Image_Module() if _image.set_host(configs["host_id"]).check_health(): print(_image.list())
def pull_image(self, configs={}): _image = Image_Module() if _image.set_host(configs["host_id"]).check_health(): print(_image.pull(configs["repository"], configs["tag"]))
def check_health(self, configs={}): _image = Image_Module() if _image.set_host(configs["host_id"]).check_health(): print("Host Up!") else: print("Host Down!")