Esempio n. 1
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        messages = holder.client.messages
        service = holder.client.apitools_client.routers

        router_ref = self.ROUTER_ARG.ResolveAsResource(args, holder.resources)

        request_type = messages.ComputeRoutersGetRequest
        replacement = service.Get(request_type(**router_ref.AsDict()))

        # Retrieve specified NAT and update base fields.
        existing_nat = nats_utils.FindNatOrRaise(replacement, args.name)
        nat = nats_utils.UpdateNatMessage(
            existing_nat,
            args,
            holder,
            with_rules=self.with_rules,
            with_tcp_time_wait_timeout=self.with_tcp_time_wait_timeout)

        request_type = messages.ComputeRoutersPatchRequest
        result = service.Patch(
            request_type(project=router_ref.project,
                         region=router_ref.region,
                         router=router_ref.Name(),
                         routerResource=replacement))

        operation_ref = resources.REGISTRY.Parse(
            result.name,
            collection='compute.regionOperations',
            params={
                'project': router_ref.project,
                'region': router_ref.region,
            })

        if args.async_:
            log.UpdatedResource(
                operation_ref,
                kind='nat [{0}] in router [{1}]'.format(
                    nat.name, router_ref.Name()),
                is_async=True,
                details='Run the [gcloud compute operations describe] command '
                'to check the status of this operation.')
            return result

        target_router_ref = holder.resources.Parse(
            router_ref.Name(),
            collection='compute.routers',
            params={
                'project': router_ref.project,
                'region': router_ref.region,
            })

        operation_poller = poller.Poller(service, target_router_ref)
        return waiter.WaitFor(
            operation_poller, operation_ref,
            'Updating nat [{0}] in router [{1}]'.format(
                nat.name, router_ref.Name()))
Esempio n. 2
0
    def Run(self, args):
        holder = base_classes.ComputeApiHolder(self.ReleaseTrack())
        messages = holder.client.messages
        service = holder.client.apitools_client.routers

        router_ref = self.ROUTER_ARG.ResolveAsResource(args, holder.resources)

        request_type = messages.ComputeRoutersGetRequest
        replacement = service.Get(request_type(**router_ref.AsDict()))

        # Retrieve specified NAT and update base fields.
        existing_nat = nats_utils.FindNatOrRaise(replacement, args.name)
        nat = nats_utils.UpdateNatMessage(existing_nat,
                                          args,
                                          holder,
                                          with_logging=self.with_logging)

        cleared_fields = []
        if args.clear_min_ports_per_vm:
            cleared_fields.append('minPortsPerVm')
        if args.clear_udp_idle_timeout:
            cleared_fields.append('udpIdleTimeoutSec')
        if args.clear_icmp_idle_timeout:
            cleared_fields.append('icmpIdleTimeoutSec')
        if args.clear_tcp_transitory_idle_timeout:
            cleared_fields.append('tcpTransitoryIdleTimeoutSec')
        if args.clear_tcp_established_idle_timeout:
            cleared_fields.append('tcpEstablishedIdleTimeoutSec')

        with holder.client.apitools_client.IncludeFields(cleared_fields):
            request_type = messages.ComputeRoutersPatchRequest
            result = service.Patch(
                request_type(project=router_ref.project,
                             region=router_ref.region,
                             router=router_ref.Name(),
                             routerResource=replacement))

        operation_ref = resources.REGISTRY.Parse(
            result.name,
            collection='compute.regionOperations',
            params={
                'project': router_ref.project,
                'region': router_ref.region,
            })

        if args. async:
            log.UpdatedResource(
                operation_ref,
                kind='nat [{0}] in router [{1}]'.format(
                    nat.name, router_ref.Name()),
                is_async=True,
                details='Run the [gcloud compute operations describe] command '
                'to check the status of this operation.')
            return result

        target_router_ref = holder.resources.Parse(
            router_ref.Name(),
            collection='compute.routers',
            params={
                'project': router_ref.project,
                'region': router_ref.region,
            })

        operation_poller = poller.Poller(service, target_router_ref)
        return waiter.WaitFor(
            operation_poller, operation_ref,
            'Updating nat [{0}] in router [{1}]'.format(
                nat.name, router_ref.Name()))