How to use the pyrsistent.field 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 / control / _protocol.py View on Github external
:param IClusterStateSource source: Representation of where these
            changes were received from.
        :param list state_changes: One or more ``IClusterStateChange``
            providers representing the state change which has taken place.
        """
        self.cluster_state.apply_changes_from_source(source, state_changes)
        self._schedule_broadcast_update()


class GenerationPair(PClass):
    """
    A pair of generation hashes, one for the configuration and one for the
    state.
    """
    configuration = field(type=GenerationHash)
    state = field(type=GenerationHash)


class IConvergenceAgent(Interface):
    """
    The agent that will receive notifications from control service.
    """
    logger = Attribute("An eliot ``Logger``.")

    def connected(client):
        """
        The client has connected to the control service.

        :param AgentClient client: The connected client.
        """
github ClusterHQ / flocker / admin / ubuntu.py View on Github external
def new_record_type(name, headings):
    return type(
        name,
        (PClass,),
        {heading: field(type=unicode, mandatory=True) for heading in headings}
    )
github ClusterHQ / flocker / flocker / route / _model.py View on Github external
"""
Objects related to the representation of Flocker-controlled network state.
"""

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 / provision / _ssh / _model.py View on Github external
"""Return argument untouched."""
    return arg


class RunRemotely(PClass):
    """
    Run some commands on a remote host.

    :ivar bytes address: The address of the remote host to connect to.
    :ivar bytes username: The user to connect as.
    :ivar Effect commands: The commands to run.
    :ivar int port: The port of the ssh server to connect to.
    :ivar callable log_command_filter: A filter to apply to any logging
        of the executed command.
    """
    username = field(type=bytes, mandatory=True)
    address = field(type=bytes, mandatory=True)
    commands = field(type=Effect, mandatory=True)
    port = field(type=int, initial=22)
    log_command_filter = field(mandatory=True)


def run_remotely(
        username, address, commands, port=22, log_command_filter=identity):
    """
    Run some commands on a remote host.

    :param bytes address: The address of the remote host to connect to.
    :param bytes username: The user to connect as.
    :param Effect commands: The commands to run.
    :param int port: The port of the ssh server to connect to.
    :param callable log_command_filter: A filter to apply to any logging
github ClusterHQ / flocker / flocker / node / agents / remotefs.py View on Github external
mount_point = field()

    @classmethod
    def from_state_and_config(cls, discovered_dataset, desired_dataset):
        return cls(
            dataset_id=desired_dataset.dataset_id,
            mount_point=desired_dataset.mount_point,
        )

    def _run(self, api):
        api.mount(self.dataset_id, self.mount_point)


class Unmount(_APICommon):
    dataset_id = field()
    mount_point = field()

    @classmethod
    def from_state_and_config(cls, discovered_dataset, desired_dataset):
        return cls(
            dataset_id=desired_dataset.dataset_id,
            mount_point=discovered_dataset.mount_point,
        )

    def _run(self, api):
        api.unmount(self.dataset_id, self.mount_point)


Desired = Discovered = DatasetStates
DATASET_TRANSITIONS = TransitionTable.create({
    Desired.MOUNTED: {
        Discovered.NON_EXISTENT: Create,
github tek / ribosome-py / ribosome / record.py View on Github external
def any_field(**kw: Any) -> pyrsistent.field:
    return pyrsistent.field(mandatory=True, **kw)
github ClusterHQ / flocker / flocker / node / agents / blockdevice.py View on Github external
def _volume_field():
    """
    Create and return a ``PRecord`` ``field`` to hold a ``BlockDeviceVolume``.
    """
    return field(
        type=BlockDeviceVolume, mandatory=True,
        # Disable the automatic PRecord.create factory.  Callers can just
        # supply the right type, we don't need the magic coercion behavior
        # supplied by default.
        factory=lambda x: x
    )
github ClusterHQ / flocker / flocker / common / version.py View on Github external
if is_release(version):
        return ""
    else:
        return "-testing"


class RPMVersion(PClass):
    """
    An RPM compatible version and a release version.
    See: http://fedoraproject.org/wiki/Packaging:NamingGuidelines#Pre-Release_packages  # noqa

    :ivar bytes version: An RPM compatible version.
    :ivar bytes release: An RPM compatible release version.
    """
    version = field(mandatory=True)
    release = field(mandatory=True)


def make_rpm_version(flocker_version):
    """
    Parse the Flocker version generated by versioneer into a
    :class:`RPMVersion`.

    :param flocker_version: The versioneer style Flocker version string.
    :return: An ``RPMVersion``.
    """
    parsed_version = parse_version(flocker_version)
    installable = parsed_version.installable_release

    # Given pre or dev number X create a 0 prefixed, `.` separated
    # string of version labels. E.g.
    # 0.1.2rc2  becomes
github ClusterHQ / flocker / flocker / node / _docker.py View on Github external
:ivar IRestartPolicy restart_policy: The restart policy of the container.

    :ivar command_line: Custom command to run using the image, a ``PVector``
        of ``unicode``. ``None`` means use default.

    :ivar swappiness: Tunable swappiness of the container.
        Default of 0 disables swap.
    """
    name = field(mandatory=True)
    container_name = field(mandatory=True)
    activation_state = field(mandatory=True)
    container_image = field(mandatory=True, initial=None)
    ports = pset_field(PortMap)
    environment = field(mandatory=True, initial=None)
    volumes = pset_field(Volume)
    mem_limit = field(mandatory=True, initial=None)
    cpu_shares = field(mandatory=True, initial=None)
    restart_policy = field(mandatory=True, initial=RestartNever())
    command_line = pvector_field(unicode, optional=True, initial=None)
    swappiness = field(mandatory=False, initial=0, type=int)


class IDockerClient(Interface):
    """
    A client for the Docker HTTP API.

    Note the difference in semantics between the results of ``add()``
    (firing does not indicate application started successfully)
    vs. ``remove()`` (firing indicates application has finished shutting
    down).
    """