Ejemplo n.º 1
0
def prune_unused_networks(host_id):
    try:
        _network = Network_Module()

        if not _network.set_host(host_id).check_health():
            return {
                "status": "failed",
                "result": {
                    "error": _("Error, Unable to connect to docker host!")
                },
                "notify_type": "failed"
            }

        result = _network.prune()

        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"
        }
Ejemplo n.º 2
0
def disconnect_network_container(host_id):
    try:
        _network = Network_Module()

        if not _network.set_host(host_id).check_health():
            return {
                "status": "failed",
                "result": {
                    "error": _("Error, Unable to connect to docker host!")
                },
                "notify_type": "failed"
            }
    except Exception as e:
        return {
            "status": "error",
            "result": {
                "error": str(e)
            },
            "notify_type": "error"
        }
Ejemplo n.º 3
0
 def prune_networks(self, configs={}):
     _network = Network_Module()
     if _network.set_host(configs["host_id"]).check_health():
         print(_network.prune())
Ejemplo n.º 4
0
 def remove_network(self, configs={}):
     _network = Network_Module()
     if _network.set_host(configs["host_id"]).check_health():
         print(_network.remove(configs["network_id"]))
Ejemplo n.º 5
0
class Get_Networks(View):

    __request = None
    __response = None
    __helpers = None
    __form = None
    __logger = None
    __user_id = None
    __host_id = None
    __network_id = None
    __host_module = None
    __network_module = None

    def __init__(self):
        self.__request = Request()
        self.__response = Response()
        self.__helpers = Helpers()
        self.__form = Form()
        self.__host_module = Host_Module()
        self.__network_module = Network_Module()
        self.__logger = self.__helpers.get_logger(__name__)

    def get(self, request, host_id):

        self.__user_id = request.user.id
        self.__host_id = host_id

        if not self.__host_module.user_owns(self.__host_id, self.__user_id):
            return JsonResponse(self.__response.send_private_failure([{
                "type": "error",
                "message": _("Error! Invalid Request.")
            }]))

        if self.__network_module.set_host(self.__host_id).check_health():
            _host = self.__host_module.get_one_by_id(host_id)
            return JsonResponse(self.__response.send_private_success([], {
                'networks': self.__format_networks(
                    self.__network_module.list(),
                    host_id,
                    _host.slug
                )
            }))
        else:
            return JsonResponse(self.__response.send_private_failure([{
                "type": "error",
                "message": _(
                    "Error! Something goes wrong with your host!"
                )
            }], {
                'networks': []
            }))

    def __format_networks(self, networks_list, host_id, host_slug):
        _networks_list = []

        for network in networks_list:
            date = network["created"].split("T")
            network["created_at"] = date[0]
            network["url"] = "#"
            network["delete_url"] = "#"
            # network["url"] = reverse("app.web.admin.hosts.view.network", kwargs={'host_slug': host_slug, 'network_id': network['long_id']})
            # network["delete_url"] = reverse("app.api.private.v1.admin.action.host.delete_network.endpoint", kwargs={'host_id': host_id})
            _networks_list.append(network)

        return _networks_list