Пример #1
0
class NestedCallClient:
    """A client that calls nested commands as System Clients"""
    def __init__(self):
        self.nestedCallsClient = SystemClient(system_name="nested-calls")

    @command(description="Start Commands at Level One")
    def level_1(self):
        """Starts Commands at Level One"""

        return self.nestedCallsClient.level_2().output

    @command(description="Start Commands at Level Two")
    def level_2(self):
        """Starts Commands at Level One"""

        return self.nestedCallsClient.level_3().output

    @command(description="Start Commands at Level Three")
    def level_3(self):
        """Starts Commands at Level Three"""

        return self.nestedCallsClient.level_4().output

    @command(description="Start Commands at Level Four")
    def level_4(self):
        """Starts Commands at Level Four"""

        return self.nestedCallsClient.level_5().output

    @command(description="Start Commands at Level Five")
    def level_5(self):
        """Starts Commands at Level Five"""

        return "Success"
Пример #2
0
def main():
    raw_req = YAML(typ="safe").load(Path("templates/echo.yaml"))

    req = {"_" + k: v for k, v in raw_req.items() if k != "parameters"}
    req.update(raw_req.get("parameters", {}))

    futures = []
    sys_client = SystemClient(**load_config(), blocking=False)

    start = datetime.now()

    for _ in range(250_000):
        futures.append(sys_client.send_bg_request(**req))
Пример #3
0
def setup_system_client(**kwargs):
    client_args = kwargs.copy()
    client_args.update(get_config())
    client = SystemClient(**client_args)

    wait_for_connection(client._easy_client)
    wait_for_plugins(client._easy_client)

    return client
Пример #4
0
def setup_system_client(**kwargs):
    client_args = kwargs.copy()
    client_args.update(get_config())
    client = SystemClient(**client_args)

    namespace = kwargs.get('namespace', 'docker')

    wait_for_connection(client._easy_client)
    wait_for_plugins(client._easy_client, namespace=namespace)

    return client
Пример #5
0
class ParentClient:
    """A Client communicates with a child in a seperate namespace"""
    def __init__(self):
        self.child_client = SystemClient(system_name="child",
                                         system_namespace="child")

    @command()
    def who_am_i(self):
        return "Parent"

    @command()
    def child_who_am_i(self):
        return self.child_client.who_am_i().output
Пример #6
0
 def __init__(self):
     self.nestedCallsClient = SystemClient(system_name="nested-calls")
Пример #7
0
 def __init__(self):
     self.child_client = SystemClient(system_name="child",
                                      system_namespace="child")
Пример #8
0
 def bytes_no_resolve_invoker(self):
     return SystemClient().bytes_no_resolve(the_bytes=b'im a byte').output
Пример #9
0
 def bytes_no_resolve(self, the_bytes):
     return SystemClient().bytes_command(the_bytes=the_bytes).output
Пример #10
0
 def bytes_model_invoker_literal(self):
     return SystemClient().bytes_model_command(
         bytes_model={"foo": "hi", "bar": b'im a byte'}
     ).output
Пример #11
0
 def bytes_multi_invoker_literal(self):
     return SystemClient().bytes_multi_command(the_bytes=[b'abc', b'123']).output
Пример #12
0
 def bytes_invoker_file(self):
     with pkg_resources.open_binary(resources, "favicon.ico") as f:
         return SystemClient().bytes_command(the_bytes=f).output
Пример #13
0
 def bytes_invoker_literal(self):
     return SystemClient().bytes_command(the_bytes=b'im a byte').output
Пример #14
0
 def __init__(self):
     self.echo_client = SystemClient(system_name="echo")
     self.sleeper_client = SystemClient(system_name="sleeper")
     self.error_client = SystemClient(system_name="error")
     self.concurrent_sleeper_client = SystemClient(
         system_name="concurrent-sleeper", blocking=False)
Пример #15
0
class EchoSleeperClient:
    """A client that delegates to the Echo and Sleeper plugins"""
    def __init__(self):
        self.echo_client = SystemClient(system_name="echo")
        self.sleeper_client = SystemClient(system_name="sleeper")
        self.error_client = SystemClient(system_name="error")
        self.concurrent_sleeper_client = SystemClient(
            system_name="concurrent-sleeper", blocking=False)

    @parameter(
        key="message",
        description="The message",
        optional=True,
        type="String",
        default=DEFAULT_MESSAGE,
    )
    @parameter(
        key="loud",
        description="Add exclamation marks",
        optional=True,
        type="Boolean",
        default=False,
    )
    @parameter(
        key="amount",
        description="How long to sleep",
        optional=True,
        type="Float",
        default=10,
    )
    def say_sleep(self, message=DEFAULT_MESSAGE, loud=False, amount=10):
        """Echos using Echo and sleeps using Sleeper"""

        echo_request = self.echo_client.say(message=message, loud=loud)
        self.sleeper_client.sleep(amount=amount)

        return echo_request.output

    @parameter(
        key="message",
        description="The message",
        optional=True,
        type="String",
        default=DEFAULT_MESSAGE,
    )
    @parameter(
        key="loud",
        description="Add exclamation marks",
        optional=True,
        type="Boolean",
        default=False,
    )
    def say_error_and_catch(self, message=DEFAULT_MESSAGE, loud=False):
        """Echos using Echo and then errors using Error"""
        echo_request = self.echo_client.say(message=message, loud=loud)
        error_request = self.error_client.string_error_message()

        if error_request.status == "ERROR":
            print("Message errored, but thats ok.")

        return {
            "echo_output": echo_request.output,
            "error_output": error_request.output,
        }

    @parameter(
        key="message",
        description="The message",
        optional=True,
        type="String",
        default=DEFAULT_MESSAGE,
    )
    @parameter(
        key="loud",
        description="Add exclamation marks",
        optional=True,
        type="Boolean",
        default=False,
    )
    def say_error_and_raise(self, message=DEFAULT_MESSAGE, loud=False):
        """Echos using Echo and then errors using Error"""
        self.echo_client.say(message=message, loud=loud)
        error_request = self.error_client.string_error_message()

        if error_request.status == "ERROR":
            # Note: Don't raise an error this way. You should figure out a way not to use eval.
            raise eval(error_request.error_class)(error_request.output)

    @parameter(
        key="message",
        description="The message",
        optional=True,
        type="String",
        default=DEFAULT_MESSAGE,
    )
    @parameter(
        key="loud",
        description="Add exclamation marks",
        optional=True,
        type="Boolean",
        default=False,
    )
    @parameter(
        key="amount",
        description="How long to sleep",
        optional=True,
        type="Float",
        default=10,
    )
    def sleep_say(self, message=DEFAULT_MESSAGE, loud=False, amount=10):
        """Echos using Echo and sleeps using Sleeper"""

        self.sleeper_client.sleep(amount=amount)

        return self.echo_client.say(message=message, loud=loud).output

    @parameter(
        key="message",
        description="The message",
        optional=True,
        type="String",
        default=DEFAULT_MESSAGE,
    )
    @parameter(
        key="loud",
        description="Add exclamation marks",
        optional=True,
        type="Boolean",
        default=False,
    )
    @parameter(
        key="amount",
        description="How long to sleep",
        optional=True,
        type="Float",
        default=10,
    )
    @parameter(
        key="number",
        description="Number of times to sleep",
        optional=True,
        type="Integer",
        default=1,
    )
    def super_sleeper(self,
                      message=DEFAULT_MESSAGE,
                      loud=False,
                      amount=10,
                      number=1):
        """Echos using Echo and sleeps using Sleeper"""

        [self.sleeper_client.sleep(amount=amount) for _ in range(number)]

        return self.echo_client.say(message=message, loud=loud).output

    @parameter(
        key="message",
        description="The message",
        optional=True,
        type="String",
        default=DEFAULT_MESSAGE,
    )
    @parameter(
        key="loud",
        description="Add exclamation marks",
        optional=True,
        type="Boolean",
        default=False,
    )
    @parameter(
        key="amount",
        description="How long to sleep",
        optional=True,
        type="Float",
        default=10,
    )
    @parameter(
        key="number",
        description="Number of times to sleep",
        optional=True,
        type="Integer",
        default=1,
    )
    def super_sleeper_concurrent(self,
                                 message=DEFAULT_MESSAGE,
                                 loud=False,
                                 amount=10,
                                 number=1):
        """Echos using Echo and sleeps using non-blocking Sleeper sleep"""

        # System client with blocking=False will return Futures
        sleeps = []
        for n in range(number):
            sleeps.append(
                self.concurrent_sleeper_client.sleep(amount=amount,
                                                     _comment=n))

        # Wait for all the futures to complete
        wait(sleeps)

        return self.echo_client.say(message=message, loud=loud).output