コード例 #1
0
ファイル: task.py プロジェクト: wickman/incubator-aurora
  def execute(self, context):
    (cluster, role, env, name) = context.options.task_instance.jobkey
    instance = context.options.task_instance.instance

    api = context.get_api(cluster)
    resp = api.query(api.build_query(role, name, set([int(instance)]), env=env))
    if resp.responseCode != ResponseCode.OK:
      raise context.CommandError('Unable to get information about instance: %s' % resp.message)
    first_task = resp.result.scheduleStatusResult.tasks[0]
    remote_cmd = context.options.command or 'bash'
    command = DistributedCommandRunner.substitute(remote_cmd, first_task,
        api.cluster, executor_sandbox=context.options.executor_sandbox)

    ssh_command = ['ssh', '-t']
    role = first_task.assignedTask.task.owner.role
    slave_host = first_task.assignedTask.slaveHost

    for tunnel in context.options.tunnels:
      try:
        port, name = tunnel.split(':')
        port = int(port)
      except ValueError:
        die('Could not parse tunnel: %s.  Must be of form PORT:NAME' % tunnel)
      if name not in first_task.assignedTask.assignedPorts:
        die('Task %s has no port named %s' % (first_task.assignedTask.taskId, name))
      ssh_command += [
          '-L', '%d:%s:%d' % (port, slave_host, first_task.assignedTask.assignedPorts[name])]

    ssh_command += ['%s@%s' % (context.options.ssh_user or role, slave_host), command]
    return subprocess.call(ssh_command)
コード例 #2
0
ファイル: task.py プロジェクト: kevinburg/incubator-aurora
    def execute(self, context):
        (cluster, role, env, name) = context.options.task_instance.jobkey
        instance = context.options.task_instance.instance

        api = context.get_api(cluster)
        resp = api.query(api.build_query(role, name, set([int(instance)]), env=env))
        context.check_and_log_response(
            resp, err_msg=("Unable to get information about instance: %s" % resp.messageDEPRECATED)
        )
        first_task = resp.result.scheduleStatusResult.tasks[0]
        remote_cmd = context.options.command or "bash"
        command = DistributedCommandRunner.substitute(
            remote_cmd, first_task, api.cluster, executor_sandbox=context.options.executor_sandbox
        )

        ssh_command = ["ssh", "-t"]
        role = first_task.assignedTask.task.owner.role
        slave_host = first_task.assignedTask.slaveHost

        for tunnel in context.options.tunnels:
            try:
                port, name = tunnel.split(":")
                port = int(port)
            except ValueError:
                raise context.CommandError(
                    EXIT_INVALID_PARAMETER, "Could not parse tunnel: %s.  Must be of form PORT:NAME" % tunnel
                )
            if name not in first_task.assignedTask.assignedPorts:
                raise context.CommandError(
                    EXIT_INVALID_PARAMETER, "Task %s has no port named %s" % (first_task.assignedTask.taskId, name)
                )
            ssh_command += ["-L", "%d:%s:%d" % (port, slave_host, first_task.assignedTask.assignedPorts[name])]

        ssh_command += ["%s@%s" % (context.options.ssh_user or role, slave_host), command]
        return subprocess.call(ssh_command)
コード例 #3
0
def ssh(args, options):
  """usage: ssh cluster/role/env/job shard [args...]

  Initiate an SSH session on the machine that a shard is running on.
  """
  if not args:
    die('Job path is required')
  job_path = args.pop(0)
  try:
    cluster_name, role, env, name = AuroraJobKey.from_path(job_path)
  except AuroraJobKey.Error as e:
    die('Invalid job path "%s": %s' % (job_path, e))
  if not args:
    die('Shard is required')
  try:
    shard = int(args.pop(0))
  except ValueError:
    die('Shard must be an integer')

  newcmd = ["task", "ssh", "%s/%s" % (job_path, shard)]
  if len(options.tunnels) > 0:
    newcmd.append("--tunnels=%s" % options.tunnels)
  if options.ssh_user is not None:
    newcmd.append("--ssh-user=%s" % options.ssh_user)
  if options.executor_sandbox:
    newcmd.append("--executor-sandbox")
  if len(args) > 0:
    newcmd.append("--command=\"%s\"" % " ".join(args))
  v1_deprecation_warning("ssh", newcmd)

  api = make_client(cluster_name)
  resp = api.query(api.build_query(role, name, set([int(shard)]), env=env))
  check_and_log_response(resp)

  first_task = resp.result.scheduleStatusResult.tasks[0]
  remote_cmd = 'bash' if not args else ' '.join(args)
  command = DistributedCommandRunner.substitute(remote_cmd, first_task,
      api.cluster, executor_sandbox=options.executor_sandbox)

  ssh_command = ['ssh', '-t']


  role = first_task.assignedTask.task.owner.role
  slave_host = first_task.assignedTask.slaveHost

  for tunnel in options.tunnels:
    try:
      port, name = tunnel.split(':')
      port = int(port)
    except ValueError:
      die('Could not parse tunnel: %s.  Must be of form PORT:NAME' % tunnel)
    if name not in first_task.assignedTask.assignedPorts:
      die('Task %s has no port named %s' % (first_task.assignedTask.taskId, name))
    ssh_command += [
        '-L', '%d:%s:%d' % (port, slave_host, first_task.assignedTask.assignedPorts[name])]

  ssh_command += ['%s@%s' % (options.ssh_user or role, slave_host), command]
  return subprocess.call(ssh_command)
コード例 #4
0
    def execute(self, context):
        (cluster, role, env, name) = context.options.instance_spec.jobkey
        instance = (None
                    if context.options.instance_spec.instance == ALL_INSTANCES
                    else set(context.options.instance_spec.instance))
        if instance is None and context.options.command:
            raise context.CommandError(
                EXIT_INVALID_PARAMETER,
                'INSTANCE must be specified when --command option is given')
        api = context.get_api(cluster)
        resp = api.query(
            api.build_query(role, name, env=env, instances=instance))
        context.log_response_and_raise(
            resp,
            err_msg=('Unable to get information about instance: %s' %
                     combine_messages(resp)))
        if (resp.result.scheduleStatusResult.tasks is None
                or len(resp.result.scheduleStatusResult.tasks) == 0):
            raise context.CommandError(
                EXIT_INVALID_PARAMETER,
                "Job %s not found" % context.options.instance_spec.jobkey)
        first_task = resp.result.scheduleStatusResult.tasks[0]
        remote_cmd = context.options.command or 'bash'
        command = DistributedCommandRunner.substitute(
            remote_cmd,
            first_task,
            api.cluster,
            executor_sandbox=context.options.executor_sandbox)

        ssh_command = ['ssh', '-t']
        ssh_command += context.options.ssh_options if context.options.ssh_options else []
        assigned = first_task.assignedTask
        role = assigned.task.job.role
        slave_host = assigned.slaveHost

        for tunnel in context.options.tunnels:
            try:
                port, name = tunnel.split(':')
                port = int(port)
            except ValueError:
                raise context.CommandError(
                    EXIT_INVALID_PARAMETER,
                    'Could not parse tunnel: %s.  Must be of form PORT:NAME' %
                    tunnel)
            if name not in assigned.assignedPorts:
                raise context.CommandError(
                    EXIT_INVALID_PARAMETER,
                    'Task %s has no port named %s' % (assigned.taskId, name))
            ssh_command += [
                '-L',
                '%d:%s:%d' % (port, slave_host, assigned.assignedPorts[name])
            ]

        ssh_command += [
            '%s@%s' % (context.options.ssh_user or role, slave_host), command
        ]
        return subprocess.call(ssh_command)
コード例 #5
0
    def execute(self, context):
        (cluster, role, env, name) = context.options.task_instance.jobkey
        instance = context.options.task_instance.instance

        api = context.get_api(cluster)
        resp = api.query(
            api.build_query(role, name, set([int(instance)]), env=env))
        context.check_and_log_response(
            resp,
            err_msg=('Unable to get information about instance: %s' %
                     resp.messageDEPRECATED))
        if (resp.result.scheduleStatusResult.tasks is None
                or len(resp.result.scheduleStatusResult.tasks) == 0):
            raise context.CommandError(
                EXIT_INVALID_PARAMETER,
                "Job %s not found" % context.options.task_instance.jobkey)
        first_task = resp.result.scheduleStatusResult.tasks[0]
        remote_cmd = context.options.command or 'bash'
        command = DistributedCommandRunner.substitute(
            remote_cmd,
            first_task,
            api.cluster,
            executor_sandbox=context.options.executor_sandbox)

        ssh_command = ['ssh', '-t']
        role = first_task.assignedTask.task.owner.role
        slave_host = first_task.assignedTask.slaveHost

        for tunnel in context.options.tunnels:
            try:
                port, name = tunnel.split(':')
                port = int(port)
            except ValueError:
                raise context.CommandError(
                    EXIT_INVALID_PARAMETER,
                    'Could not parse tunnel: %s.  Must be of form PORT:NAME' %
                    tunnel)
            if name not in first_task.assignedTask.assignedPorts:
                raise context.CommandError(
                    EXIT_INVALID_PARAMETER, 'Task %s has no port named %s' %
                    (first_task.assignedTask.taskId, name))
            ssh_command += [
                '-L',
                '%d:%s:%d' %
                (port, slave_host, first_task.assignedTask.assignedPorts[name])
            ]

        ssh_command += [
            '%s@%s' % (context.options.ssh_user or role, slave_host), command
        ]
        return subprocess.call(ssh_command)
コード例 #6
0
ファイル: task.py プロジェクト: apache/aurora
  def execute(self, context):
    (cluster, role, env, name) = context.options.instance_spec.jobkey
    instance = (None if context.options.instance_spec.instance == ALL_INSTANCES else
        set(context.options.instance_spec.instance))
    if instance is None and context.options.command:
      raise context.CommandError(EXIT_INVALID_PARAMETER,
          'INSTANCE must be specified when --command option is given')
    api = context.get_api(cluster)
    resp = api.query(api.build_query(role, name, env=env, instances=instance))
    context.log_response_and_raise(resp,
        err_msg=('Unable to get information about instance: %s' % combine_messages(resp)))
    if (resp.result.scheduleStatusResult.tasks is None or
        len(resp.result.scheduleStatusResult.tasks) == 0):
      raise context.CommandError(EXIT_INVALID_PARAMETER,
          "Job %s not found" % context.options.instance_spec.jobkey)
    first_task = resp.result.scheduleStatusResult.tasks[0]
    remote_cmd = context.options.command or 'bash'
    command = DistributedCommandRunner.substitute(
        remote_cmd,
        first_task,
        api.cluster,
        executor_sandbox=context.options.executor_sandbox)

    ssh_command = ['ssh', '-t']
    ssh_command += context.options.ssh_options if context.options.ssh_options else []
    assigned = first_task.assignedTask
    role = assigned.task.job.role
    slave_host = assigned.slaveHost

    for tunnel in context.options.tunnels:
      try:
        port, name = tunnel.split(':')
        port = int(port)
      except ValueError:
        raise context.CommandError(EXIT_INVALID_PARAMETER,
            'Could not parse tunnel: %s.  Must be of form PORT:NAME' % tunnel)
      if name not in assigned.assignedPorts:
        raise context.CommandError(EXIT_INVALID_PARAMETER,
            'Task %s has no port named %s' % (assigned.taskId, name))
      ssh_command += [
          '-L', '%d:%s:%d' % (port, slave_host, assigned.assignedPorts[name])]

    ssh_command += ['%s@%s' % (context.options.ssh_user or role, slave_host), command]
    process = subprocess.Popen(ssh_command)

    if context.options.pid_file:
      with open(context.options.pid_file, "w") as f:
        f.write(str(process.pid))

    return process.wait()
コード例 #7
0
ファイル: task.py プロジェクト: KancerEzeroglu/aurora
  def execute(self, context):
    (cluster, role, env, name) = context.options.task_instance.jobkey
    instance = context.options.task_instance.instance

    api = context.get_api(cluster)
    resp = api.query(api.build_query(role, name, env=env, instances=set([int(instance)])))
    context.log_response_and_raise(resp,
        err_msg=('Unable to get information about instance: %s' % combine_messages(resp)))
    if (resp.result.scheduleStatusResult.tasks is None or
        len(resp.result.scheduleStatusResult.tasks) == 0):
      raise context.CommandError(EXIT_INVALID_PARAMETER,
          "Job %s not found" % context.options.task_instance.jobkey)
    first_task = resp.result.scheduleStatusResult.tasks[0]
    remote_cmd = context.options.command or 'bash'
    command = DistributedCommandRunner.substitute(remote_cmd, first_task,
        api.cluster, executor_sandbox=context.options.executor_sandbox)

    ssh_command = ['ssh', '-t']
    assigned = first_task.assignedTask
    role = assigned.task.job.role if assigned.task.job else assigned.task.owner.role
    slave_host = assigned.slaveHost

    for tunnel in context.options.tunnels:
      try:
        port, name = tunnel.split(':')
        port = int(port)
      except ValueError:
        raise context.CommandError(EXIT_INVALID_PARAMETER,
            'Could not parse tunnel: %s.  Must be of form PORT:NAME' % tunnel)
      if name not in assigned.assignedPorts:
        raise context.CommandError(EXIT_INVALID_PARAMETER,
            'Task %s has no port named %s' % (assigned.taskId, name))
      ssh_command += [
          '-L', '%d:%s:%d' % (port, slave_host, assigned.assignedPorts[name])]

    ssh_command += ['%s@%s' % (context.options.ssh_user or role, slave_host), command]
    return subprocess.call(ssh_command)
コード例 #8
0
def ssh(args, options):
  """usage: ssh cluster/role/env/job shard [args...]

  Initiate an SSH session on the machine that a shard is running on.
  """
  if not args:
    die('Job path is required')
  job_path = args.pop(0)
  try:
    cluster_name, role, env, name = AuroraJobKey.from_path(job_path)
  except AuroraJobKey.Error as e:
    die('Invalid job path "%s": %s' % (job_path, e))
  if not args:
    die('Shard is required')
  try:
    shard = int(args.pop(0))
  except ValueError:
    die('Shard must be an integer')

  newcmd = ["task", "ssh", "%s/%s" % (job_path, shard)]
  if len(options.tunnels) > 0:
    newcmd.append("--tunnels=%s" % options.tunnels)
  if options.ssh_user is not None:
    newcmd.append("--ssh-user=%s" % options.ssh_user)
  if options.executor_sandbox:
    newcmd.append("--executor-sandbox")
  if len(args) > 0:
    newcmd.append("--command=\"%s\"" % " ".join(args))
  v1_deprecation_warning("ssh", newcmd)

  api = make_client(cluster_name)
  resp = api.query(api.build_query(role, name, set([int(shard)]), env=env))
  check_and_log_response(resp)

  if (resp.result.scheduleStatusResult.tasks is None or
      len(resp.result.scheduleStatusResult.tasks) == 0):
    die("Job %s not found" % job_path)
  first_task = resp.result.scheduleStatusResult.tasks[0]
  remote_cmd = 'bash' if not args else ' '.join(args)
  command = DistributedCommandRunner.substitute(remote_cmd, first_task,
      api.cluster, executor_sandbox=options.executor_sandbox)

  ssh_command = ['ssh', '-t']


  role = first_task.assignedTask.task.owner.role
  slave_host = first_task.assignedTask.slaveHost

  for tunnel in options.tunnels:
    try:
      port, name = tunnel.split(':')
      port = int(port)
    except ValueError:
      die('Could not parse tunnel: %s.  Must be of form PORT:NAME' % tunnel)
    if name not in first_task.assignedTask.assignedPorts:
      die('Task %s has no port named %s' % (first_task.assignedTask.taskId, name))
    ssh_command += [
        '-L', '%d:%s:%d' % (port, slave_host, first_task.assignedTask.assignedPorts[name])]

  ssh_command += ['%s@%s' % (options.ssh_user or role, slave_host), command]
  return subprocess.call(ssh_command)