mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-30 12:33:02 +02:00
- New helper class for container testing - New helper class to urllib, Furl Due to extremely weak Python-fu in the undersigned, this patch changes the __init__.py file to add new helper classes for container tests. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
"""Manage Infix containers"""
|
|
|
|
class Container:
|
|
"""Helper methods"""
|
|
|
|
def __init__(self, target):
|
|
self.system = target
|
|
|
|
def _find(self, name):
|
|
oper = self.system.get_data("/infix-containers:containers/container")
|
|
if not oper:
|
|
return None
|
|
|
|
for container in oper["containers"]["container"]:
|
|
if container["name"] == name:
|
|
return container
|
|
return None
|
|
|
|
def exists(self, name):
|
|
"""Check if container {name} runs on target."""
|
|
container = self._find(name)
|
|
if not container:
|
|
return False
|
|
return True
|
|
|
|
def running(self, name):
|
|
"""Check if container {name} exists and is running."""
|
|
container = self._find(name)
|
|
if container and container["running"]:
|
|
return True
|
|
return False
|
|
|
|
def action(self, name, act):
|
|
"""Call NETCONF action 'type' on container 'name'"""
|
|
return self.system.call_action_dict("infix-containers", {
|
|
"containers": {
|
|
"container": [
|
|
{
|
|
"name": f"{name}",
|
|
f"{act}": {}
|
|
}
|
|
]
|
|
}
|
|
})
|