From 5247262739f3901802d6583edd11cfffe7996b4e Mon Sep 17 00:00:00 2001 From: Ajdin Date: Tue, 17 Jul 2018 16:18:31 +0200 Subject: [PATCH] added: Container Interface UP/DOWN --- app/api/controllers/container.py | 20 +++++++++++++++++++- app/api/models/LXCContainer.py | 16 ++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/app/api/controllers/container.py b/app/api/controllers/container.py index c56b7291..123a6fe6 100644 --- a/app/api/controllers/container.py +++ b/app/api/controllers/container.py @@ -222,4 +222,22 @@ def removeProxy(name, proxy): container = LXCContainer({'name': name}) return response.replySuccess(container.removeProxy(proxy)) except ValueError as e: - return response.replyFailed(message=e.__str__()) \ No newline at end of file + return response.replyFailed(message=e.__str__()) + +@container_api.route('//interface//up', methods=['PUT']) +@jwt_required() +def ifaceUp(name, iface): + try: + container = LXCContainer({'name': name}) + return response.replySuccess(container.interfaceUp(iface)) + except ValueError as e: + return response.replyFailed(message=e.__str__()) + +@container_api.route('//interface//down', methods=['PUT']) +@jwt_required() +def ifaceDown(name, iface): + try: + container = LXCContainer({'name': name}) + return response.replySuccess(container.interfaceDown(iface)) + except ValueError as e: + return response.replyFailed(message=e.__str__()) diff --git a/app/api/models/LXCContainer.py b/app/api/models/LXCContainer.py index c97b23c6..6af8f194 100644 --- a/app/api/models/LXCContainer.py +++ b/app/api/models/LXCContainer.py @@ -398,3 +398,19 @@ def removeProxy(self, name): return self.info() except Exception as e: raise ValueError(e) + + def interfaceUp(self, iface): + try: + container = self.client.containers.get(self.data['name']) + result = container.execute(['ifconfig {} up'.format(iface)]) + return result + except Exception as e: + raise ValueError(e) + + def interfaceDown(self, iface): + try: + container = self.client.containers.get(self.data['name']) + result = container.execute(['ifconfig {} down'.format(iface)]) + return result + except Exception as e: + raise ValueError(e) \ No newline at end of file