Esempio n. 1
0
    def Run(self, args):
        """Runs 'endpoints create'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      If --async=true, returns Operation to poll.
      Else, returns nothing.

    Raises:
      HttpException: An http error response was received while executing api
          request.
      ToolException: Endpoint creation encountered an error.
    """
        client = self.context[constants.CLIENT]
        messages = self.context[constants.MESSAGES]
        resources = self.context[constants.RESOURCES]
        project = properties.VALUES.core.project.Get(required=True)
        writer = write_support.ServiceRegistryClient(client, resources)

        request = messages.ServiceregistryEndpointsInsertRequest(
            project=project,
            endpoint=messages.Endpoint(
                name=args.endpoint_name,
                description=args.description,
                addresses=args.target,
                dnsIntegration=messages.EndpointDnsIntegration(
                    networks=args.networks)))

        return writer.call_service_registry(
            client.endpoints.Insert, request, args. async,
            'Created [{0}] successfully.'.format(args.endpoint_name))
Esempio n. 2
0
    def Run(self, args):
        """Runs 'endpoints delete'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      If --async=true, returns Operation to poll.
      Else, returns nothing.

    Raises:
      HttpException: An http error response was received while executing api
          request.
      ToolException: The endpoint deletion operation encountered an error.
    """
        client = self.context[constants.CLIENT]
        messages = self.context[constants.MESSAGES]
        resources = self.context[constants.RESOURCES]
        project = properties.VALUES.core.project.Get(required=True)
        writer = write_support.ServiceRegistryClient(client, resources)

        request = messages.ServiceregistryEndpointsDeleteRequest(
            project=project, endpoint=args.endpoint_name)

        return writer.call_service_registry(client.endpoints.Delete, request,
                                            args. async, log.DeletedResource)
Esempio n. 3
0
    def Run(self, args):
        """Runs 'operations wait'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.
    Raises:
      ServiceRegistryError: One or more operations finished with error(s) or
        the wait timed out.
    """
        client = self.context['serviceregistry_client']
        messages = self.context['serviceregistry_messages']
        project = properties.VALUES.core.project.Get(required=True)
        writer = write_support.ServiceRegistryClient(client, messages, project)

        failed_operations = []
        for operation in args.operations:
            try:
                # TODO(b/27272474): need to use resources.Parse with write_support
                writer.wait_for_operation(operation)
            except write_support.ServiceRegistryError as error:
                log.Print(error)
                failed_operations.append(operation)

        if failed_operations:
            raise write_support.ServiceRegistryError(
                'There were operations with errors: {0}'.format(
                    failed_operations))

        log.Print('All operations completed successfully.')
Esempio n. 4
0
    def Run(self, args):
        """Runs 'operations wait'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.
    Raises:
      ServiceRegistryError: One or more operations finished with error(s) or
        the wait timed out.
    """
        client = self.context[constants.CLIENT]
        resources = self.context[constants.RESOURCES]
        writer = write_support.ServiceRegistryClient(client, resources)

        failed_operations = []
        for operation in args.operations:
            operation_ref = resources.Parse(
                operation, collection=constants.OPERATIONS_COLLECTION)
            try:
                writer.wait_for_operation(operation_ref)
            except write_support.ServiceRegistryError as error:
                log.Print(error)
                failed_operations.append(operation)

        if failed_operations:
            raise write_support.ServiceRegistryError(
                'There were operations with errors: {0}'.format(
                    failed_operations))

        log.Print('All operations completed successfully.')
Esempio n. 5
0
    def Run(self, args):
        """Runs 'endpoints update'.

    Args:
      args: argparse.Namespace, The arguments that this command was invoked
          with.

    Returns:
      If --async=true, returns Operation to poll.
      Else returns nothing.

    Raises:
      HttpException: An http error response was received while executing api
          request.
      ToolException: Endpoint update encountered an error.
    """
        client = self.context[constants.CLIENT]
        messages = self.context[constants.MESSAGES]
        resources = self.context[constants.RESOURCES]
        project = properties.VALUES.core.project.Get(required=True)
        writer = write_support.ServiceRegistryClient(client, resources)

        fingerprint = None
        endpoint = client.endpoints.Get(
            messages.ServiceregistryEndpointsGetRequest(
                project=project, endpoint=args.endpoint_name))
        fingerprint = endpoint.fingerprint

        message_str = 'Preparing to update [{0}].'.format(args.endpoint_name)
        if not console_io.PromptContinue(message=message_str):
            log.Print('Cancelling update operation.')
            return

        request = messages.ServiceregistryEndpointsUpdateRequest(
            project=project,
            endpoint=args.endpoint_name,
            endpointResource=messages.Endpoint(
                name=args.endpoint_name,
                description=args.description,
                addresses=args.target,
                dnsIntegration=messages.EndpointDnsIntegration(
                    networks=arg_support.ExpandNetworks(
                        args.networks, project),
                    enableExternal=args.enable_external,
                ),
                fingerprint=fingerprint))

        return writer.call_service_registry(
            client.endpoints.Update, request, args. async,
            'Updated [{0}] successfully.'.format(args.endpoint_name))