Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added: Container Interface UP/DOWN #217

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion app/api/controllers/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__())
return response.replyFailed(message=e.__str__())

@container_api.route('/<name>/interface/<iface>/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('/<name>/interface/<iface>/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__())
16 changes: 16 additions & 0 deletions app/api/models/LXCContainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)