Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from spython.main.instances import list_instances
from spython.utils import run_command as run_cmd
# run_command uses run_cmd, but wraps to catch error
from spython.main.base.command import (init_command, run_command)
from spython.main.base.generate import RobotNamer
from .start import start
from .stop import stop
Instance.RobotNamer = RobotNamer()
Instance._init_command = init_command
Instance.run_command = run_cmd
Instance._run_command = run_command
Instance._list = list_instances # list command is used to get metadata
Instance._println = println
Instance.start = start # intended to be called on init, not by user
Instance.stop = stop
# Give an instance the ability to breed :)
Instance.instance = Instance
return Instance
def load(self, image=None):
'''load an image, either an actual path on the filesystem or a uri.
Parameters
==========
image: the image path or uri to load (e.g., docker://ubuntu
'''
from spython.image import Image
from spython.instance import Instance
self.simage = Image(image)
if image is not None:
if image.startswith('instance://'):
self.simage = Instance(image)
bot.info(self.simage)
if output["return_code"] == 0:
# Only print the table if we are returning json
if not quiet:
print("".join(output["message"]))
# Prepare json result from table
header = ["daemon_name", "pid", "container_image"]
instances = parse_table(output["message"][0], header)
# Does the user want instance objects instead?
listing = []
if not return_json:
for i in instances:
new_instance = Instance(
pid=i["pid"],
name=i["daemon_name"],
image=i["container_image"],
start=False,
)
listing.append(new_instance)
instances = listing
# Couldn't get UID
elif output["return_code"] == 255:
bot.error("Couldn't get UID")
# Return code of 0
else:
from spython.main.base.command import (init_command, run_command)
from spython.main.base.generate import RobotNamer
from .start import start
from .stop import stop
Instance.RobotNamer = RobotNamer()
Instance._init_command = init_command
Instance.run_command = run_cmd
Instance._run_command = run_command
Instance._list = list_instances # list command is used to get metadata
Instance._println = println
Instance.start = start # intended to be called on init, not by user
Instance.stop = stop
# Give an instance the ability to breed :)
Instance.instance = Instance
return Instance