How to use the pyrsistent.PRecord function in pyrsistent

To help you get started, we’ve selected a few pyrsistent 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
few seconds; the application might take some time to fully start up."
    and so here we wait until the client can be created.
    """
    def create_mongo_client():
        try:
            client = MongoClient(host=host, port=port)
            client.areyoualive.posts.insert({"ping": 1})
            return client
        except PyMongoError:
            return False

    d = loop_until(create_mongo_client)
    return d


class ControlService(PRecord):
    """
    A record of the cluster's control service.

    :ivar bytes public_address: The public address of the control service.
    """
    public_address = field(type=bytes)


class Node(PRecord):
    """
    A record of a cluster node.

    :ivar bytes public_address: The public address of the node.
    :ivar bytes reported_hostname: The address of the node, as reported by the
        API.
    :ivar unicode uuid: The UUID of the node.
github pypa / linehaul / linehaul / user_agents.py View on Github external
pass


class Installer(pyrsistent.PRecord):

    name = pyrsistent.field(type=str)
    version = pyrsistent.field(type=str)


class Implementation(pyrsistent.PRecord):

    name = pyrsistent.field(type=str)
    version = pyrsistent.field(type=str)


class LibC(pyrsistent.PRecord):

    lib = pyrsistent.field(type=str)
    version = pyrsistent.field(type=str)


class Distro(pyrsistent.PRecord):

    name = pyrsistent.field(type=str)
    version = pyrsistent.field(type=str)
    id = pyrsistent.field(type=str)
    libc = pyrsistent.field(type=LibC, factory=LibC.create)


class System(pyrsistent.PRecord):

    name = pyrsistent.field(type=str)
github erp12 / pyshgp / pyshgp / push / program.py View on Github external
"""The :mod:`program` module defines an abstraction to represent Push programs and their the specification.

Program objects encapsulate everything required to execute the program on a Push interpreter with the exception
of instruction definitions. Programs are serializable, and thus can be saved and reused. There is the possibility
(but not a guarantee) that Push programs can be executed across different versions of ``pyshgp`.

"""
from pyrsistent import PRecord, field

from pyshgp.push.config import PushConfig
from pyshgp.push.atoms import CodeBlock
from pyshgp.utils import Saveable


class ProgramSignature(PRecord):
    """A specification of a Push program.

    Attributes
    ----------
    arity : int
        The number of inputs that the program will take.
    output_stacks : List[str]
        The names of the stack(s) which the output values will be pulled from after program execution.
    push_config : PushConfig
        The configuration of the PushInterpreter to use when executing the program.

    """

    arity = field(type=int, mandatory=True)
    output_stacks = field(type=list, mandatory=True)
    push_config = field(type=PushConfig, mandatory=True, initial=PushConfig())
github datawire / forge / backend / model.py View on Github external
from builtins import str
    basestring = str

class Resource(PRecord):
    name = field(type=basestring)
    type = field(type=basestring)

class Descriptor(PRecord):
    artifact = field(type=basestring)
    resources = pvector_field(Resource)

class Task(PRecord):
    type = field(type=basestring)
    resource = field(type=(Resource, basestring))

class Stats(PRecord):
    good = field(type=float)
    bad = field(type=float)
    slow = field(type=float)

class Service(object):

    def __init__(self, name, owner):
        self.name = name
        self.owner = owner
        # the prior descriptors, the head of this is what is currently
        # running
        self.previous = []
        # the target descriptor
        self.update = None
        self.updating = False
        self.descriptor = None
github ClusterHQ / flocker / flocker / control / _model.py View on Github external
def __new__(cls, **kwargs):
        # PRecord does some crazy stuff, thus _precord_buckets; see
        # PRecord.__new__.
        if "_precord_buckets" not in kwargs:
            if "uuid" not in kwargs:
                # See https://clusterhq.atlassian.net/browse/FLOC-1795
                warn("UUID is required, this is for backwards compat with "
                     "existing tests. If you see this in production code "
                     "that's a bug.", DeprecationWarning, stacklevel=2)
                kwargs["uuid"] = ip_to_uuid(kwargs["hostname"])
        return PRecord.__new__(cls, **kwargs)
github ClusterHQ / flocker / flocker / ca / _ca.py View on Github external
serial = os.urandom(16).encode(b"hex")
        serial = int(serial, 16)
        cert = sign_certificate_request(
            authority.credential.keypair.keypair,
            authority.credential.certificate.getSubject(), request,
            serial, EXPIRY_20_YEARS, b'sha256', start=begin
        )
        credential = FlockerCredential(
            path=output_path, keypair=keypair, certificate=cert
        )
        credential.write_credential_files(key_filename, cert_filename)
        instance = cls(credential=credential, username=username)
        return instance


class NodeCredential(PRecord):
    """
    A certificate for a node agent, signed by a supplied certificate
    authority.

    :ivar FlockerCredential credential: The certificate and key pair
        credential object.
    :ivar bytes uuid: A unique identifier for the node this certificate
        identifies, in the form of a version 4 UUID.
    """
    credential = field(mandatory=True)
    uuid = field(mandatory=True, initial=None)

    @classmethod
    def from_path(cls, path, uuid):
        """
        Load a node certificate from a specified path.
github ClusterHQ / flocker / flocker / ca / _ca.py View on Github external
serial = os.urandom(16).encode(b"hex")
        serial = int(serial, 16)
        cert = sign_certificate_request(
            authority.credential.keypair.keypair,
            authority.credential.certificate.getSubject(), request,
            serial, EXPIRY_20_YEARS, 'sha256', start=begin
        )
        credential = FlockerCredential(
            path=path, keypair=keypair, certificate=cert)
        credential.write_credential_files(
            key_filename, cert_filename)
        instance = cls(credential=credential, uuid=uuid)
        return instance


class ControlCredential(PRecord):
    """
    A certificate and key pair for a control service, signed by a supplied
    certificate authority.

    :ivar FlockerCredential credential: The certificate and key pair
        credential object.
    :ivar bytes uuid: A unique identifier for the cluster this certificate
        identifies, in the form of a version 4 UUID.
    """
    credential = field(mandatory=True)
    uuid = field(mandatory=True, type=bytes)

    @classmethod
    def from_path(cls, path, uuid=None):
        keypair, certificate = load_certificate_from_path(
            path, CONTROL_KEY_FILENAME, CONTROL_CERTIFICATE_FILENAME
github Yelp / task_processing / task_processing / plugins / mesos / execution_framework.py View on Github external
from task_processing.interfaces.event import task_event
from task_processing.metrics import create_counter
from task_processing.metrics import create_timer
from task_processing.metrics import get_metric
from task_processing.plugins.mesos import metrics
from task_processing.plugins.mesos.resource_helpers import get_offer_resources


if TYPE_CHECKING:
    from .mesos_executor import MesosExecutorCallbacks  # noqa


log = logging.getLogger(__name__)


class TaskMetadata(PRecord):
    agent_id = field(type=str, initial='')
    task_config = field(type=PRecord, mandatory=True)
    task_state = field(type=str, mandatory=True)
    task_state_history = field(type=PMap, factory=pmap, mandatory=True)


class ExecutionFramework(Scheduler):
    callbacks: 'MesosExecutorCallbacks'

    def __init__(
        self,
        name,
        role,
        callbacks: 'MesosExecutorCallbacks',
        task_staging_timeout_s,
        pool=None,
github ClusterHQ / flocker / flocker / route / _model.py View on Github external
from pyrsistent import PRecord, field


class Proxy(PRecord):
    """
    :ivar ipaddr.IPv4Address ip: The IPv4 address towards which this proxy
        directs traffic.

    :ivar int port: The TCP port number on which this proxy operates.
    """
    ip = field(mandatory=True)
    port = field(type=int, mandatory=True)


class OpenPort(PRecord):
    """
    :ivar int port: The TCP port which is opened.
    """
    port = field(type=int, mandatory=True)
github ClusterHQ / flocker / flocker / node / agents / blockdevice.py View on Github external
def found((volume, compute_instance_id)):
            if volume is None:
                # It was not actually found.
                raise DatasetWithoutVolume(dataset_id=self.dataset_id)
            ATTACH_VOLUME_DETAILS(volume=volume).write(_logger)
            return api.attach_volume(
                volume.blockdevice_id,
                attach_to=compute_instance_id,
            )
        attaching = d.addCallback(found)
        return attaching


@implementer(IStateChange)
class DetachVolume(PRecord):
    """
    Detach a volume from the node it is currently attached to.

    :ivar UUID dataset_id: The unique identifier of the dataset associated with
        the volume to detach.
    """
    dataset_id = field(type=UUID, mandatory=True)

    @property
    def eliot_action(self):
        return DETACH_VOLUME(_logger, dataset_id=self.dataset_id)

    def run(self, deployer):
        """
        Use the deployer's ``IBlockDeviceAPI`` to detach the volume.
        """