How to use the pystachio.Ref 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 / src / main / python / apache / thermos / common / options.py View on Github external
def add_binding_callback(option, opt, value, parser):
    if not getattr(parser.values, option_name, None):
      setattr(parser.values, option_name, [])
    if len(value.split('=')) != 2:
      raise ParseError('Binding must be of the form NAME=VALUE')
    name, value = value.split('=')
    try:
      ref = Ref.from_address(name)
    except Ref.InvalidRefError as e:
      raise ParseError('Could not parse ref %s: %s' % (name, e))
    getattr(parser.values, option_name).append({ref: value})
  return add_binding_callback
github apache / aurora / src / main / python / apache / aurora / client / cli / options.py View on Github external
def binding_parser(binding):
  """Pystachio takes bindings in the form of a list of dictionaries. Each pystachio binding
  becomes another dictionary in the list. So we need to convert the bindings specified by
  the user from a list of "name=value" formatted strings to a list of the dictionaries
  expected by pystachio.
  """
  binding_parts = binding.split("=", 1)
  if len(binding_parts) < 2:
    raise ArgumentTypeError('Binding parameter must be formatted name=value')
  try:
    ref = Ref.from_address(binding_parts[0])
  except Ref.InvalidRefError as e:
    raise ArgumentTypeError("Could not parse binding parameter %s: %s" % (binding, e))
  return {ref: binding_parts[1]}
github apache / aurora / src / python / twitter / thermos / base / options.py View on Github external
def add_binding_callback(option, opt, value, parser):
    if not getattr(parser.values, option_name, None):
      setattr(parser.values, option_name, [])
    if len(value.split('=')) != 2:
      raise ParseError('Binding must be of the form NAME=VALUE')
    name, value = value.split('=')
    try:
      ref = Ref.from_address(name)
    except Ref.InvalidRefError as e:
      raise ParseError('Could not parse ref %s: %s' % (name, e))
    getattr(parser.values, option_name).append({ref: value})
  return add_binding_callback
github apache / aurora / src / main / python / apache / aurora / client / cli / options.py View on Github external
def binding_parser(binding):
  """Pystachio takes bindings in the form of a list of dictionaries. Each pystachio binding
  becomes another dictionary in the list. So we need to convert the bindings specified by
  the user from a list of "name=value" formatted strings to a list of the dictionaries
  expected by pystachio.
  """
  binding_parts = binding.split("=", 1)
  if len(binding_parts) < 2:
    raise ArgumentTypeError('Binding parameter must be formatted name=value')
  try:
    ref = Ref.from_address(binding_parts[0])
  except Ref.InvalidRefError as e:
    raise ArgumentTypeError("Could not parse binding parameter %s: %s" % (binding, e))
  return {ref: binding_parts[1]}
github apache / aurora / src / main / python / apache / thermos / config / loader.py View on Github external
def extract(cls, obj):
    port_scope = Ref.from_address('thermos.ports')
    _, uninterp = obj.interpolate()
    ports = []
    for ref in uninterp:
      subscope = port_scope.scoped_to(ref)
      if subscope is not None:
        if not subscope.is_index():
          raise cls.InvalidPorts(
            'Bad port specification "%s" (should be of form "thermos.ports[name]"' % ref.address())
        ports.append(subscope.action().value)
    return ports
github apache / aurora / src / python / twitter / mesos / client / client_util.py View on Github external
def _warn_on_unspecified_package_bindings(config):
  if not isinstance(config, PystachioConfig) or not config.package():
    return

  print(PACKAGE_DEPRECATION_WARNING, file=sys.stderr)

  _, refs = config.raw().interpolate()
  p_uri, p = Ref.from_address('mesos.package_uri'), Ref.from_address('mesos.package')
  if p not in refs and p_uri not in refs:
    print(PACKAGE_UNDERSPECIFIED_WARNING % (
        '{{packer[%s][%s][%s].copy_command}}' % tuple(config.package())))
github apache / aurora / src / python / twitter / mesos / client / client_util.py View on Github external
def extract_ref(ref):
    components = ref.components()
    if len(components) < 4:
      return None
    if components[0] != Ref.Dereference('packer'):
      return None
    if not all(isinstance(action, Ref.Index) for action in components[1:4]):
      return None
    role, package_name, version = (action.value for action in components[1:4])
    return (role, package_name, version)
github apache / aurora / src / python / twitter / aurora / config / thrift.py View on Github external
underlying, refs = job.interpolate()

  # need to fake an instance id for the sake of schema checking
  underlying_checked = underlying.bind(mesos = {'instance': 31337})
  try:
    ThermosTaskValidator.assert_valid_task(underlying_checked.task())
  except ThermosTaskValidator.InvalidTaskError as e:
    raise InvalidConfig('Task is invalid: %s' % e)
  if not underlying_checked.check().ok():
    raise InvalidConfig('Job not fully specified: %s' % underlying.check().message())

  unbound = []
  for ref in refs:
    if ref == THERMOS_TASK_ID_REF or ref == MESOS_INSTANCE_REF or (
        Ref.subscope(THERMOS_PORT_SCOPE_REF, ref)):
      continue
    unbound.append(ref)

  if unbound:
    raise InvalidConfig('Config contains unbound variables: %s' % ' '.join(map(str, unbound)))

  cron_schedule = not_empty_or(job.cron_schedule(), '')
  cron_policy = select_cron_policy(job.cron_policy(), job.cron_collision_policy())

  task.executorConfig = ExecutorConfig(
      name='AuroraExecutor',
      data=filter_aliased_fields(underlying).json_dumps())

  return JobConfiguration(
      key=key,
      owner=owner,
github apache / aurora / src / main / python / twitter / thermos / config / loader.py View on Github external
def extract(obj):
    port_scope = Ref.from_address('thermos.ports')
    _, uninterp = obj.interpolate()
    ports = []
    for ref in uninterp:
      subscope = port_scope.scoped_to(ref)
      if subscope is not None:
        if not subscope.is_index():
          raise PortExtractor.InvalidPorts(
            'Bad port specification "%s" (should be of form "thermos.ports[name]"' % ref.address())
        ports.append(subscope.action().value)
    return ports
github apache / aurora / src / main / python / apache / aurora / config / thrift.py View on Github external
def filter_aliased_fields(job):
  return job(**dict((key, Empty) for key in ALIASED_FIELDS))


def assert_valid_field(field, identifier):
  VALID_IDENTIFIER = re.compile(GOOD_IDENTIFIER_PATTERN_PYTHON)
  if not isinstance(identifier, Compatibility.string):
    raise InvalidConfig("%s must be a string" % field)
  if not VALID_IDENTIFIER.match(identifier):
    raise InvalidConfig("Invalid %s '%s'" % (field, identifier))
  return identifier


MESOS_INSTANCE_REF = Ref.from_address('mesos.instance')
MESOS_HOSTNAME_REF = Ref.from_address('mesos.hostname')
THERMOS_PORT_SCOPE_REF = Ref.from_address('thermos.ports')
THERMOS_TASK_ID_REF = Ref.from_address('thermos.task_id')


def create_sla_policy(sla_policy):
  unwrapped = sla_policy.unwrap()
  if isinstance(unwrapped, PystachioPercentageSlaPolicy):
    return SlaPolicy(
      percentageSlaPolicy=PercentageSlaPolicy(
        fully_interpolated(unwrapped.percentage()),
        fully_interpolated(unwrapped.duration_secs()),
      ),
      countSlaPolicy=None,
      coordinatorSlaPolicy=None
    )
  elif isinstance(unwrapped, PystachioCountSlaPolicy):