How to use the pystachio.Default function in pystachio

To help you get started, we’ve selected a few pystachio 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 apache / aurora / tests / python / twitter / aurora / common / test_cluster.py View on Github external
def test_simple():
  class AudubonTrait(Cluster.Trait):
    master_role = String
    slave_role  = Default(String, 'slave')
    version     = Required(Integer)

  west = Cluster(name = 'west',
                 master_role = 'west.master',
                 slave_role = 'west.slave',
                 version = 10)
  east = Cluster(name = 'east', version = 11)

  assert east.name == 'east'
  with pytest.raises(AttributeError):
    east.slave_role
  assert east.with_traits(AudubonTrait).slave_role == 'slave'
  assert west.with_traits(AudubonTrait).slave_role == 'west.slave'
  assert east.with_traits(AudubonTrait).master_role is None

  with pytest.raises(TypeError):
github apache / aurora / src / python / twitter / aurora / client / api / scheduler_client.py View on Github external
from gen.twitter.aurora import AuroraAdmin
from gen.twitter.aurora.constants import CURRENT_API_VERSION

from thrift.protocol import TBinaryProtocol
from thrift.transport import TSocket, TTransport

from pystachio import Boolean, Default, Integer, String


class SchedulerClientTrait(Cluster.Trait):
  zk                = String
  zk_port           = Default(Integer, 2181)
  scheduler_zk_path = String
  scheduler_uri     = String
  proxy_url         = String
  auth_mechanism    = Default(String, 'UNAUTHENTICATED')
  use_thrift_ssl    = Default(Boolean, False)


class SchedulerClient(object):
  THRIFT_RETRIES = 5
  RETRY_TIMEOUT = Amount(1, Time.SECONDS)

  class CouldNotConnect(Exception): pass

  # TODO(wickman) Refactor per MESOS-3005 into two separate classes with separate traits:
  #   ZookeeperClientTrait
  #   DirectClientTrait
  @classmethod
  def get(cls, cluster, **kwargs):
    if not isinstance(cluster, Cluster):
      raise TypeError('"cluster" must be an instance of Cluster, got %s' % type(cluster))
github apache / aurora / src / main / python / apache / aurora / client / api / scheduler_client.py View on Github external
from gen.apache.aurora import AuroraAdmin
from gen.apache.aurora.constants import CURRENT_API_VERSION

from thrift.protocol import TBinaryProtocol
from thrift.transport import TSocket, TTransport
from pystachio import Boolean, Default, Integer, String


class SchedulerClientTrait(Cluster.Trait):
  zk                = String
  zk_port           = Default(Integer, 2181)
  scheduler_zk_path = String
  scheduler_uri     = String
  proxy_url         = String
  auth_mechanism    = Default(String, 'UNAUTHENTICATED')
  use_thrift_ssl    = Default(Boolean, False)


class SchedulerClient(object):
  THRIFT_RETRIES = 5
  RETRY_TIMEOUT = Amount(1, Time.SECONDS)

  class CouldNotConnect(Exception): pass

  # TODO(wickman) Refactor per MESOS-3005 into two separate classes with separate traits:
  #   ZookeeperClientTrait
  #   DirectClientTrait
  @classmethod
  def get(cls, cluster, **kwargs):
    if not isinstance(cluster, Cluster):
      raise TypeError('"cluster" must be an instance of Cluster, got %s' % type(cluster))
    cluster = cluster.with_trait(SchedulerClientTrait)
github apache / aurora / src / main / python / apache / aurora / client / api / scheduler_client.py View on Github external
from apache.aurora.common.cluster import Cluster
from apache.aurora.common.transport import TRequestsTransport

from gen.apache.aurora.api import AuroraAdmin
from gen.apache.aurora.api.constants import BYPASS_LEADER_REDIRECT_HEADER_NAME
from gen.apache.aurora.api.ttypes import ResponseCode

try:
  from urlparse import urljoin
except ImportError:
  from urllib.parse import urljoin


class SchedulerClientTrait(Cluster.Trait):
  zk                = String  # noqa
  zk_port           = Default(Integer, 2181)  # noqa
  scheduler_zk_path = String  # noqa
  scheduler_uri     = String  # noqa
  proxy_url         = String  # noqa
  auth_mechanism    = Default(String, 'UNAUTHENTICATED')  # noqa


def _bypass_leader_redirect_session_factory(should_bypass=False):
  session = requests.session()

  if should_bypass:
    session.headers[BYPASS_LEADER_REDIRECT_HEADER_NAME] = 'true'

  return session


class SchedulerClient(object):
github apache / aurora / src / python / twitter / aurora / client / api / scheduler_client.py View on Github external
from gen.twitter.aurora.constants import CURRENT_API_VERSION

from thrift.protocol import TBinaryProtocol
from thrift.transport import TSocket, TTransport

from pystachio import Boolean, Default, Integer, String


class SchedulerClientTrait(Cluster.Trait):
  zk                = String
  zk_port           = Default(Integer, 2181)
  scheduler_zk_path = String
  scheduler_uri     = String
  proxy_url         = String
  auth_mechanism    = Default(String, 'UNAUTHENTICATED')
  use_thrift_ssl    = Default(Boolean, False)


class SchedulerClient(object):
  THRIFT_RETRIES = 5
  RETRY_TIMEOUT = Amount(1, Time.SECONDS)

  class CouldNotConnect(Exception): pass

  # TODO(wickman) Refactor per MESOS-3005 into two separate classes with separate traits:
  #   ZookeeperClientTrait
  #   DirectClientTrait
  @classmethod
  def get(cls, cluster, **kwargs):
    if not isinstance(cluster, Cluster):
      raise TypeError('"cluster" must be an instance of Cluster, got %s' % type(cluster))
    cluster = cluster.with_trait(SchedulerClientTrait)
github apache / aurora / src / main / python / apache / aurora / client / api / scheduler_client.py View on Github external
from gen.apache.aurora.api.constants import BYPASS_LEADER_REDIRECT_HEADER_NAME
from gen.apache.aurora.api.ttypes import ResponseCode

try:
  from urlparse import urljoin
except ImportError:
  from urllib.parse import urljoin


class SchedulerClientTrait(Cluster.Trait):
  zk                = String  # noqa
  zk_port           = Default(Integer, 2181)  # noqa
  scheduler_zk_path = String  # noqa
  scheduler_uri     = String  # noqa
  proxy_url         = String  # noqa
  auth_mechanism    = Default(String, 'UNAUTHENTICATED')  # noqa


def _bypass_leader_redirect_session_factory(should_bypass=False):
  session = requests.session()

  if should_bypass:
    session.headers[BYPASS_LEADER_REDIRECT_HEADER_NAME] = 'true'

  return session


class SchedulerClient(object):
  THRIFT_RETRIES = 5
  RETRY_TIMEOUT = Amount(1, Time.SECONDS)

  class Error(Exception): pass
github apache / aurora / src / python / twitter / thermos / config / schema_base.py View on Github external
# before process is failed.
  daemon        = Default(Boolean, False)
  ephemeral     = Default(Boolean, False)
  min_duration  = Default(Integer, 5)      # integer seconds
  final         = Default(Boolean, False)  # if this process should be a finalizing process
                                           # that should always be run after regular processes


class Task(Struct):
  name = Default(String, '{{processes[0].name}}')
  processes = List(Process)

  # optionals
  constraints = Default(List(Constraint), [])
  resources = Resources
  max_failures = Default(Integer, 1)        # maximum number of failed processes before task is failed.
  max_concurrency = Default(Integer, 0)     # 0 is infinite concurrency.
                                            # > 0 is max concurrent processes.
  finalization_wait = Default(Integer, 30)  # the amount of time in seconds we allocate to run the
                                            # finalization schedule.

  # TODO(jon): remove/replace with proper solution to MESOS-3546
  user = String
github apache / aurora / src / main / python / apache / thermos / config / schema_base.py View on Github external
destination = Default(LoggerDestination, LoggerDestination('file'))
  mode = Default(LoggerMode, LoggerMode('standard'))
  rotate = RotatePolicy


class Process(Struct):
  cmdline = Required(String)
  name    = Required(String)

  # This is currently unused but reserved for future use by Thermos.
  resources     = Resources

  # optionals
  max_failures  = Default(Integer, 1)      # maximum number of failed process runs
                                           # before process is failed.
  daemon        = Default(Boolean, False)
  ephemeral     = Default(Boolean, False)
  min_duration  = Default(Integer, 5)      # integer seconds
  final         = Default(Boolean, False)  # if this process should be a finalizing process
                                           # that should always be run after regular processes
  logger        = Default(Logger, Empty)


class Task(Struct):
  name = Default(String, '{{processes[0].name}}')
  processes = List(Process)

  # optionals
  constraints = Default(List(Constraint), [])
  resources = Resources
  max_failures = Default(Integer, 1)        # maximum number of failed processes before task is failed.
  max_concurrency = Default(Integer, 0)     # 0 is infinite concurrency.
github apache / aurora / src / main / python / apache / thermos / config / schema_base.py View on Github external
order = List(String)


class RotatePolicy(Struct):
  log_size = Default(Integer, 100*MB)
  backups = Default(Integer, 5)


LoggerDestination = Enum('file', 'console', 'both', 'none')


LoggerMode = Enum('standard', 'rotate')


class Logger(Struct):
  destination = Default(LoggerDestination, LoggerDestination('file'))
  mode = Default(LoggerMode, LoggerMode('standard'))
  rotate = RotatePolicy


class Process(Struct):
  cmdline = Required(String)
  name    = Required(String)

  # This is currently unused but reserved for future use by Thermos.
  resources     = Resources

  # optionals
  max_failures  = Default(Integer, 1)      # maximum number of failed process runs
                                           # before process is failed.
  daemon        = Default(Boolean, False)
  ephemeral     = Default(Boolean, False)