Пример #1
0
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"
        }
Пример #2
0
 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__)
Пример #3
0
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"
        }
Пример #4
0
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"
        }
Пример #5
0
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"
        }
Пример #6
0
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"
        }
Пример #7
0
 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"]))
Пример #8
0
 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"]))
Пример #9
0
 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"))
Пример #10
0
 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"]))
Пример #11
0
 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"]))
Пример #12
0
 def prune_all_unused_images(self, configs={}):
     _image = Image_Module()
     if _image.set_host(configs["host_id"]).check_health():
         print(_image.prune_all_unused())
Пример #13
0
 def list_images(self, configs={}):
     _image = Image_Module()
     if _image.set_host(configs["host_id"]).check_health():
         print(_image.list())
Пример #14
0
 def pull_image(self, configs={}):
     _image = Image_Module()
     if _image.set_host(configs["host_id"]).check_health():
         print(_image.pull(configs["repository"], configs["tag"]))
Пример #15
0
 def check_health(self, configs={}):
     _image = Image_Module()
     if _image.set_host(configs["host_id"]).check_health():
         print("Host Up!")
     else:
         print("Host Down!")