Пример #1
0
class Describe(kuberun_command.KubeRunCommand, base.DescribeCommand):
    """Describes a domain mapping."""

    detailed_help = _DETAILED_HELP
    flags = [flags.NamespaceFlag(), flags.ClusterConnectionFlags()]

    @classmethod
    def Args(cls, parser):
        super(Describe, cls).Args(parser)
        parser.add_argument('domain',
                            help='The domain mapping to show details for.')
        parser.display_info.AddFormat('yaml')

    def BuildKubeRunArgs(self, args):
        return [args.domain] + super(Describe, self).BuildKubeRunArgs(args)

    def Command(self):
        return ['core', 'domain-mappings', 'describe']

    def SuccessResult(self, out, args):
        if out:
            return domainmapping.DomainMapping(json.loads(out))
        else:
            raise exceptions.Error('Cannot find domain mapping [{}]'.format(
                args.domain))
Пример #2
0
class Delete(kuberun_command.KubeRunCommand, base.DeleteCommand):
    """Deletes a KubeRun service."""

    detailed_help = _DETAILED_HELP
    flags = [
        flags.NamespaceFlag(),
        flags.ClusterConnectionFlags(),
        flags.AsyncFlag()
    ]

    @classmethod
    def Args(cls, parser):
        super(Delete, cls).Args(parser)
        parser.add_argument('service', help='The KubeRun service to delete.')

    def SuccessResult(self, out, args):
        log.DeletedResource(args.service, 'service')

    def BuildKubeRunArgs(self, args):
        return [args.service] + super(Delete, self).BuildKubeRunArgs(args)

    def Run(self, args):
        """Delete a service."""
        console_io.PromptContinue(
            message='Service [{service}] will be deleted.'.format(
                service=args.service),
            throw_if_unattended=True,
            cancel_on_no=True)
        return super(Delete, self).Run(args)

    def Command(self):
        return ['core', 'services', 'delete']
Пример #3
0
class Describe(kuberun_command.KubeRunCommand, base.DescribeCommand):
    """Describes a KubeRun service."""

    detailed_help = _DETAILED_HELP
    flags = [flags.NamespaceFlag(), flags.ClusterConnectionFlags()]

    @classmethod
    def Args(cls, parser):
        super(Describe, cls).Args(parser)
        parser.add_argument(
            'service', help='The KubeRun service for which to show details.')
        resource_printer.RegisterFormatter(
            service_printer.SERVICE_PRINTER_FORMAT,
            service_printer.ServicePrinter,
            hidden=True)
        parser.display_info.AddFormat(service_printer.SERVICE_PRINTER_FORMAT)

    def BuildKubeRunArgs(self, args):
        return [args.service] + super(Describe, self).BuildKubeRunArgs(args)

    def Command(self):
        return ['core', 'services', 'describe']

    def SuccessResult(self, out, args):
        return json.loads(out)
Пример #4
0
class Delete(kuberun_command.KubeRunCommand, base.DeleteCommand):
  """Deletes a domain mapping."""

  detailed_help = _DETAILED_HELP
  flags = [flags.NamespaceFlag(), flags.ClusterConnectionFlags()]

  @classmethod
  def Args(cls, parser):
    super(Delete, cls).Args(parser)
    parser.add_argument(
        'domain', help='The domain mapping to delete.')

  def BuildKubeRunArgs(self, args):
    return [args.domain] + super(Delete, self).BuildKubeRunArgs(args)

  def Command(self):
    return ['core', 'domain-mappings', 'delete']

  def OperationResponseHandler(self, response, args):
    if response.failed:
      raise exceptions.Error(response.stderr)

    if response.stderr:
      log.status.Print(response.stderr)

    msg = """Mappings to [{domain}] now have been deleted.""".format(
        domain=args.domain)
    pretty_print.Success(msg)
    return None
Пример #5
0
class Describe(kuberun_command.KubeRunCommandWithOutput, base.DescribeCommand):
  """Describes a Knative revision."""

  detailed_help = _DETAILED_HELP
  flags = [flags.ClusterConnectionFlags(), flags.NamespaceFlag()]

  @classmethod
  def Args(cls, parser):
    super(Describe, cls).Args(parser)
    parser.add_argument(
        'revision', help='The Knative revision to show details for.')
    resource_printer.RegisterFormatter(
        revision_printer.REVISION_PRINTER_FORMAT,
        revision_printer.RevisionPrinter,
        hidden=True)
    parser.display_info.AddFormat(revision_printer.REVISION_PRINTER_FORMAT)

  def BuildKubeRunArgs(self, args):
    return [args.revision] + super(Describe, self).BuildKubeRunArgs(args)

  def Command(self):
    return ['core', 'revisions', 'describe']

  def FormatOutput(self, out, args):
    if out:
      return revision.Revision(json.loads(out))
    else:
      raise exceptions.Error('Cannot find revision [{}]'.format(args.revision))
Пример #6
0
class Update(kuberun_command.KubeRunCommand):
  """Updates a backend binding."""

  detailed_help = _DETAILED_HELP
  flags = [
      flags.NamespaceFlag(),
      flags.ClusterConnectionFlags(),
      flags.MaxRateFlag(),
  ]

  @classmethod
  def Args(cls, parser):
    super(Update, cls).Args(parser)
    parser.add_argument(
        'backend_binding',
        help="""Name of the backend binding to update. This name
        is the same as the Compute Engine backend service.""")
    parser.display_info.AddFormat("""table(
        name:label=NAME,
        service:label=SERVICE,
        ready:label=READY)""")

  def BuildKubeRunArgs(self, args):
    return [args.backend_binding] + super(Update, self).BuildKubeRunArgs(args)

  def Command(self):
    return ['core', 'backend-bindings', 'update']

  def SuccessResult(self, out, args):
    if out:
      return backendbinding.BackendBinding(json.loads(out))
    else:
      raise exceptions.Error('Could not update backend binding [{}]'.format(
          args.backend_binding))
Пример #7
0
class Create(kuberun_command.KubeRunCommand):
    """Creates a backend binding."""

    detailed_help = _DETAILED_HELP
    flags = [
        flags.NamespaceFlag(),
        flags.ClusterConnectionFlags(),
        flags.MaxRateFlag(True),
    ]

    @classmethod
    def Args(cls, parser):
        super(Create, cls).Args(parser)
        parser.add_argument(
            '--service',
            help=
            'Name of the KubeRun service to bind to a Compute Engine backend service.',
            required=True)
        parser.add_argument(
            '--backend-service',
            help=
            'Name of the Compute Engine backend service to bind to the KubeRun service.',
            required=True)
        parser.display_info.AddFormat("""table(
        name:label=NAME,
        service:label=SERVICE,
        ready:label=READY)""")

    def BuildKubeRunArgs(self, args):
        return [
            '--service',
            args.service,
            '--backend-service',
            args.backend_service,
        ] + super(Create, self).BuildKubeRunArgs(args)

    def Command(self):
        return ['core', 'backend-bindings', 'create']

    def SuccessResult(self, out, args):
        if out:
            return backendbinding.BackendBinding(json.loads(out))
        else:
            raise exceptions.Error(
                'Could not create backend binding [{}] for service [{}]'.
                format(args.domain, args.service))
Пример #8
0
class Delete(kuberun_command.KubeRunCommand, base.DeleteCommand):
  """Deletes a Knative service."""

  detailed_help = _DETAILED_HELP
  flags = [
      flags.NamespaceFlag(),
      flags.ClusterConnectionFlags(),
      flags.AsyncFlag()
  ]

  @classmethod
  def Args(cls, parser):
    super(Delete, cls).Args(parser)
    parser.add_argument('service',
                        help='The Knative service to delete.')

  def OperationResponseHandler(self, response, args):
    if response.failed:
      log.error(response.stderr)
      return None

    if response.stderr:
      log.status.Print(response.stderr)

    log.status.Print('Service is successfully deleted.')
    return None

  def BuildKubeRunArgs(self, args):
    return [args.service] + super(Delete, self).BuildKubeRunArgs(args)

  def Run(self, args):
    """Delete a service."""
    console_io.PromptContinue(
        message='Service [{service}] will be deleted.'.format(
            service=args.service),
        throw_if_unattended=True,
        cancel_on_no=True)
    return super(Delete, self).Run(args)

  def Command(self):
    return ['core', 'services', 'delete']
Пример #9
0
class Delete(kuberun_command.KubeRunCommand, base.DeleteCommand):
    """Deletes a domain mapping."""

    detailed_help = _DETAILED_HELP
    flags = [flags.NamespaceFlag(), flags.ClusterConnectionFlags()]

    @classmethod
    def Args(cls, parser):
        super(Delete, cls).Args(parser)
        parser.add_argument('domain', help='The domain mapping to delete.')

    def BuildKubeRunArgs(self, args):
        return [args.domain] + super(Delete, self).BuildKubeRunArgs(args)

    def Command(self):
        return ['core', 'domain-mappings', 'delete']

    def SuccessResult(self, out, args):
        msg = """Mappings to [{domain}] now have been deleted.""".format(
            domain=args.domain)
        pretty_print.Success(msg)
Пример #10
0
class UpdateTraffic(kuberun_command.KubeRunCommandWithOutput):
  """Updates the traffic settings of a Knative service."""

  detailed_help = _DETAILED_HELP
  flags = [
      flags.ClusterConnectionFlags(),
      flags.NamespaceFlag(),
      flags.TrafficFlags(),
      flags.AsyncFlag()
  ]

  @classmethod
  def Args(cls, parser):
    super(UpdateTraffic, cls).Args(parser)
    parser.add_argument(
        'service',
        help='Knative service for which to update the traffic settings.')
    resource_printer.RegisterFormatter(
        traffic_printer.TRAFFIC_PRINTER_FORMAT,
        traffic_printer.TrafficPrinter,
        hidden=True)
    parser.display_info.AddFormat(traffic_printer.TRAFFIC_PRINTER_FORMAT)

  def BuildKubeRunArgs(self, args):
    return [args.service] + super(UpdateTraffic, self).BuildKubeRunArgs(args)

  def Command(self):
    return ['core', 'services', 'update-traffic']

  def FormatOutput(self, out, args):
    if out:
      svc = service.Service(json.loads(out))
      return traffic_pair.GetTrafficTargetPairs(svc.spec_traffic,
                                                svc.status_traffic,
                                                svc.latest_ready_revision,
                                                svc.url)
    else:
      raise exceptions.Error('Failed to update traffic for service [{}]'.format(
          args.service))
Пример #11
0
class Delete(kuberun_command.KubeRunCommand, base.DeleteCommand):
    """Deletes a backend binding."""

    detailed_help = _DETAILED_HELP
    flags = [flags.NamespaceFlag(), flags.ClusterConnectionFlags()]

    @classmethod
    def Args(cls, parser):
        super(Delete, cls).Args(parser)
        parser.add_argument(
            'backend_binding',
            help="""Name of the backend binding to delete. This name
        is the same as the Compute Engine backend service.""")

    def BuildKubeRunArgs(self, args):
        return [args.backend_binding] + super(Delete,
                                              self).BuildKubeRunArgs(args)

    def Command(self):
        return ['core', 'backend-bindings', 'delete']

    def SuccessResult(self, out, args):
        log.DeletedResource(args.backend_binding, 'backend binding')
Пример #12
0
        parser.display_info.AddFormat("""table(
        name:label=NAME,
        type:label="RECORD TYPE",
        rrdata:label=CONTENTS)""")

    def BuildKubeRunArgs(self, args):
        return ['--service', args.service, '--domain', args.domain] + super(
            Create, self).BuildKubeRunArgs(args)

    def Command(self):
        return ['core', 'domain-mappings', 'create']

    def SuccessResult(self, out, args):
        if out:
            mapping = json.loads(out)
            status = mapping.get('status', {})
            records = status.get('resourceRecords', [{}])
            spec = mapping.get('spec', {})
            default_name = spec.get('routeName')
            for r in records:
                r['name'] = r.get('name') or default_name
            return records
        else:
            raise exceptions.Error(
                'Could not map domain [{}] to service [{}]'.format(
                    args.domain, args.service))


Create.detailed_help = _DETAILED_HELP
Create.flags = [flags.NamespaceFlag(), flags.ClusterConnectionFlags()]