Beispiel #1
0
  def Run(self, args):
    enable_experimental = (
        properties.VALUES.kuberun.enable_experimental_commands.GetBool())
    if not enable_experimental:
      # This prompt is here because our commands are not yet public and marking
      # them as hidden doesn't proclude a customer from using the command if
      # they know about it.
      console_io.PromptContinue(
          message='This command is currently under construction and not supported.',
          throw_if_unattended=True,
          cancel_on_no=True,
          default=False)

    command_executor = self.CommandExecutor()
    project = properties.VALUES.core.project.Get()
    command = self.Command()
    command.extend(self.BuildKubeRunArgs(args))
    response = command_executor(
        command=command,
        env=kuberuncli.GetEnvArgsForCommand(
            extra_vars={
                'CLOUDSDK_AUTH_TOKEN':
                    auth.GetAuthToken(
                        account=properties.VALUES.core.account.Get()),
                'CLOUDSDK_PROJECT':
                    project
            }),
        show_exec_error=args.show_exec_error)
    log.debug('Response: %s' % response.stdout)
    log.debug('ErrResponse: %s' % response.stderr)
    return self.OperationResponseHandler(response, args)
    def Run(self, args):
        enable_experimental = (
            properties.VALUES.kuberun.enable_experimental_commands.GetBool())
        if not enable_experimental:
            # This prompt is here because our commands are not yet public and marking
            # them as hidden doesn't proclude a customer from using the command if
            # they know about it.
            console_io.PromptContinue(
                message=
                'This command is currently under construction and not supported.',
                throw_if_unattended=True,
                cancel_on_no=True,
                default=False)

        project = properties.VALUES.core.project.Get()
        command = self.Command()
        command.extend(self.BuildKubeRunArgs(args))

        devkit_dir = ''  # '' to force Go binary to use the fdk-dir for gcloud_lite
        if config.Paths().sdk_root:
            devkit_dir = os.path.join(config.Paths().sdk_root, 'lib',
                                      'kuberun', 'kuberun_devkits')
        env_vars = {
            'CLOUDSDK_AUTH_TOKEN':
                auth.GetAuthToken(account=properties.VALUES.core.account.Get()),
            'CLOUDSDK_PROJECT':
                project,
            'CLOUDSDK_USER_AGENT':  # Cloud SDK prefix + user agent string
                '{} {}'.format(config.CLOUDSDK_USER_AGENT,
                               transport.MakeUserAgentString()),
            'KUBERUN_DEVKIT_DIRECTORY':
                devkit_dir,
        }

        region = properties.VALUES.compute.region.Get(required=False,
                                                      validate=False)
        if region:
            env_vars['CLOUDSDK_COMPUTE_REGION'] = region

        zone = properties.VALUES.compute.zone.Get(required=False,
                                                  validate=False)
        if zone:
            env_vars['CLOUDSDK_COMPUTE_ZONE'] = zone

        response = self.command_executor(
            command=command,
            env=kuberuncli.GetEnvArgsForCommand(extra_vars=env_vars),
            show_exec_error=args.show_exec_error)
        log.debug('Response: %s' % response.stdout)
        log.debug('ErrResponse: %s' % response.stderr)

        if response.failed:
            return self.FailureResult(response.stdout)

        return self.SuccessResult(response.stdout, args)