How to use the eliot.twisted.DeferredContext function in eliot

To help you get started, we’ve selected a few eliot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ClusterHQ / flocker / flocker / acceptance / testtools.py View on Github external
def cleanup_leases():
            context = start_action(action_type="acceptance:cleanup_leases")
            with context.context():
                get_items = DeferredContext(self.client.list_leases())

                def release_all(leases):
                    release_list = []
                    for lease in leases:
                        release_list.append(
                            self.client.release_lease(lease.dataset_id))
                    return gather_deferreds(release_list)

                get_items.addCallback(release_all)
                releasing_leases = get_items.addActionFinish()
                return timeout(
                    reactor, releasing_leases, 20,
                    Exception("Timed out cleaning up leases"),
                )
github LeastAuthority / leastauthority.com / src / lae_automation / subscription_converger.py View on Github external
def get_hosted_zone_by_name(route53, name):
    """
    Get a ``HostedZone`` with a zone name matching ``name``.

    :param route53: A txaws Route53 client.

    :param txaws.route53.model.Name name: The zone name to look for.

    :raise KeyError: If no matching hosted zone is found.

    :return Deferred(HostedZone): The hosted zone with a matching name.
    """
    action = start_action(action_type=u"get-hosted-zone")
    with action.context():
        d = DeferredContext(route53.list_hosted_zones())
        def filter_results(zones):
            Message.log(zone_names=list(zone.name for zone in zones))
            for zone in zones:
                # XXX Bleuch zone.name should be a Name!
                if Name(zone.name) == name:
                    d = route53.list_resource_record_sets(zone_id=zone.identifier)
                    d.addCallback(
                        lambda rrsets, zone=zone: _ZoneState(
                            zone=zone,
                            rrsets=rrsets,
                        ),
                    )
                    return d
            raise KeyError(name)
        d.addCallback(filter_results)
        return d.addActionFinish()
github LeastAuthority / leastauthority.com / src / lae_automation / subscription_converger.py View on Github external
def get_active_subscriptions(subscriptions):
    action = start_action(action_type=u"load-subscriptions")
    with action.context():
        d = DeferredContext(subscriptions.list())
        def got_subscriptions(subscriptions):
            subscriptions = list(subscriptions)
            action.add_success_fields(subscription_count=len(subscriptions))
            return {
                subscription.subscription_id: subscription
                for subscription
                in subscriptions
            }
        d.addCallback(got_subscriptions)
        return d.addActionFinish()
github ClusterHQ / flocker / flocker / provision / _aws.py View on Github external
def finished_booting():
        d = maybeDeferred(_node_is_booting, instance)
        d.addCallback(lambda x: not x)
        return d

    with action.context():
        # Since we are refreshing the instance's state once in a while
        # we may miss some transitions.  So, here we are waiting until
        # the node has transitioned out of the original state and then
        # check if the new state is the one that we expect.
        d = loop_until(
            reactor,
            finished_booting,
            repeat(5, INSTANCE_TIMEOUT)
        )
        d = DeferredContext(d)
        d.addCallback(check_final_state)
        d.addActionFinish()
        return d.result
github LeastAuthority / leastauthority.com / src / lae_automation / subscription_converger.py View on Github external
def get_customer_grid_service(k8s, namespace):
    action = start_action(action_type=u"load-services")
    with action.context():
        d = DeferredContext(k8s.get_services(_s4_selector(namespace)))
        def got_services(services):
            services = list(services)
            action.add_success_fields(service_count=len(services))
            if services:
                return services[0]
            return None
        d.addCallback(got_services)
        return d.addActionFinish()
github LeastAuthority / leastauthority.com / src / lae_automation / subscription_converger.py View on Github external
def g(*args, **kwargs):
            action = start_action(action_type=action_type)
            with action.context():
                try:
                    result = f(*args, **kwargs)
                except Exception as e:
                    action.finish(e)
                else:
                    if isinstance(result, Deferred):
                        d = DeferredContext(result)
                        return d.addActionFinish()
                    else:
                        action.finish()
                        return result
        return g
github twisted / txacme / src / txacme / client.py View on Github external
def register(self, new_reg=None):
        """
        Create a new registration with the ACME server.

        :param ~acme.messages.NewRegistration new_reg: The registration message
            to use, or ``None`` to construct one.

        :return: The registration resource.
        :rtype: Deferred[`~acme.messages.RegistrationResource`]
        """
        if new_reg is None:
            new_reg = messages.NewRegistration()
        action = LOG_ACME_REGISTER(registration=new_reg)
        with action.context():
            return (
                DeferredContext(
                    self.update_registration(
                        new_reg, uri=self.directory[new_reg]))
                .addErrback(self._maybe_registered, new_reg)
                .addCallback(
                    tap(lambda r: action.add_success_fields(registration=r)))
                .addActionFinish())
github LeastAuthority / leastauthority.com / src / lae_automation / subscription_converger.py View on Github external
def get_customer_grid_replicasets(k8s, namespace):
    action = start_action(action_type=u"load-replicasets")
    with action.context():
        d = DeferredContext(k8s.get_replicasets(_s4_selector(namespace)))
        def got_replicasets(replicasets):
            replicasets = list(replicasets)
            action.add_success_fields(replicaset_count=len(replicasets))
            return replicasets
        d.addCallback(got_replicasets)
        return d.addActionFinish()
github LeastAuthority / leastauthority.com / src / lae_automation / subscription_converger.py View on Github external
def get_customer_grid_deployments(k8s, namespace):
    action = start_action(action_type=u"load-deployments")
    with action.context():
        d = DeferredContext(k8s.get_deployments(_s4_selector(namespace)))
        def got_deployments(deployments):
            deployments = list(deployments)
            action.add_success_fields(deployment_count=len(deployments))
            _DEPLOYMENTS.set(len(deployments))
            return deployments
        d.addCallback(got_deployments)
        return d.addActionFinish()
github ClusterHQ / flocker / flocker / provision / _libcloud.py View on Github external
def got_ip_addresses():
                d = self._async_refresh_node(reactor, node)
                d = DeferredContext(d)

                def is_running(updated_node):
                    if updated_node.state is not NodeState.RUNNING:
                        raise Exception("Node failed to run")
                    return updated_node

                def check_addresses(updated_node):
                    """
                    Check if the node has got at least one IPv4 public address
                    and, if requested, an IPv4 private address.  If yes, then
                    return the node object with the addresses, None otherwise.
                    """
                    public_ips = _filter_ipv4(updated_node.public_ips)
                    if len(public_ips) > 0:
                        if self._use_private_addresses:
                            private_ips = _filter_ipv4(