How to use the pystachio.Ref.from_address 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 / mesos / parsers / test_mesos_to_pystachio.py View on Github external
def test_config_with_package():
  hwc = copy.deepcopy(HELLO_WORLD)
  hwc['package'] = ('jane', 'package', 'live')
  job = convert(hwc)
  assert len(job.task().processes().get()) == 2
  pi, refs = job.task().processes()[0].interpolate()
  assert Ref.from_address('packer[jane][package][live].copy_command') in refs
github apache / aurora / src / main / python / apache / aurora / config / __init__.py View on Github external
def standard_bindings(cls, job):
    # Rewrite now-deprecated bindings into their proper form.
    return job.bind({
      Ref.from_address('mesos.role'): '{{role}}',
      Ref.from_address('mesos.cluster'): '{{cluster}}',
      Ref.from_address('thermos.user'): '{{role}}',
    })
github apache / aurora / src / python / twitter / mesos / client / binding_helpers / packer_helper.py View on Github external
def bind_ref(self, config, match, env, force_local, binding_dict):
    local = config.cluster() == 'local' or force_local
    package = match
    ref_str = 'packer[%s][%s][%s]' % package[1:4]
    ref = Ref.from_address(ref_str)
    if ref_str in binding_dict:
      (package_data, packer_struct) = binding_dict[ref_str]
    else:
      package_data = get_package_data(config.cluster(), package[1:4])
      packer_struct = generate_packer_struct(validate_package(package_data), local)
    binding_dict[ref_str] = (package_data, packer_struct)
    config.bind({ref: packer_struct})
    config.add_package((package[1], package[2], package_data['id']))
github apache / aurora / src / python / twitter / aurora / config / __init__.py View on Github external
def standard_bindings(cls, job):
    # Rewrite now-deprecated bindings into their proper form.
    return job.bind({
      Ref.from_address('mesos.role'): '{{role}}',
      Ref.from_address('mesos.cluster'): '{{cluster}}',
      Ref.from_address('thermos.user'): '{{role}}',
    })
github apache / aurora / src / python / twitter / aurora / config / __init__.py View on Github external
def standard_bindings(cls, job):
    # Rewrite now-deprecated bindings into their proper form.
    return job.bind({
      Ref.from_address('mesos.role'): '{{role}}',
      Ref.from_address('mesos.cluster'): '{{cluster}}',
      Ref.from_address('thermos.user'): '{{role}}',
    })
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
    )
github apache / aurora / src / python / twitter / aurora / config / __init__.py View on Github external
def task_links(self):
    # {{mesos.instance}} --> %shard_id%
    # {{thermos.ports[foo]}} --> %port:foo%
    task_links = self._job.task_links()
    if task_links is Empty:
      return task_links
    _, uninterp = task_links.interpolate()
    substitutions = {
      Ref.from_address('mesos.instance'): '%shard_id%'
    }
    port_scope = Ref.from_address('thermos.ports')
    for ref in uninterp:
      subscope = port_scope.scoped_to(ref)
      if subscope:
        substitutions[ref] = '%%port:%s%%' % subscope.action().value
    return task_links.bind(substitutions)
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 convert(job, metadata=frozenset(), ports=frozenset()):
  """Convert a Pystachio MesosJob to an Aurora Thrift JobConfiguration."""

  owner = Identity(role=fully_interpolated(job.role()), user=getpass.getuser())
  key = JobKey(
    role=assert_valid_field('role', fully_interpolated(job.role())),
    environment=assert_valid_field('environment', fully_interpolated(job.environment())),
    name=assert_valid_field('name', fully_interpolated(job.name())))

  task_raw = job.task()