def Run(self, args): holder = base_classes.ComputeApiHolder(self.ReleaseTrack()) client = holder.client self.ValidateArgs(args) health_check_ref = self.HEALTH_CHECK_ARG.ResolveAsResource( args, holder.resources) if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): get_request = self._GetRegionalGetRequest(client, health_check_ref) else: get_request = self._GetGetRequest(client, health_check_ref) objects = client.MakeRequests([get_request]) new_object = self.Modify(client, args, objects[0]) # If existing object is equal to the proposed object or if # Modify() returns None, then there is no work to be done, so we # print the resource and return. if objects[0] == new_object: log.status.Print( 'No change requested; skipping update for [{0}].'.format( objects[0].name)) return objects if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): set_request = self._GetRegionalSetRequest(client, health_check_ref, new_object) else: set_request = self._GetSetRequest(client, health_check_ref, new_object) return client.MakeRequests([set_request])
def _Run(args, holder, include_l7_internal_load_balancing, include_log_config): """Issues the requests necessary for updating the health check.""" client = holder.client _ValidateArgs(args, include_log_config) health_check_arg = flags.HealthCheckArgument( 'gRPC', include_l7_internal_load_balancing=include_l7_internal_load_balancing) health_check_ref = health_check_arg.ResolveAsResource( args, holder.resources, default_scope=compute_scope.ScopeEnum.GLOBAL) if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): get_request = _GetRegionalGetRequest(client, health_check_ref) else: get_request = _GetGetRequest(client, health_check_ref) objects = client.MakeRequests([get_request]) new_object = _Modify(client, args, objects[0], include_log_config) # If existing object is equal to the proposed object or if # _Modify() returns None, then there is no work to be done, so we # print the resource and return. if objects[0] == new_object: log.status.Print('No change requested; skipping update for [{0}].'.format( objects[0].name)) return objects if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): set_request = _GetRegionalSetRequest(client, health_check_ref, new_object) else: set_request = _GetSetRequest(client, health_check_ref, new_object) return client.MakeRequests([set_request])
def Run(self, args): """Issues requests necessary to update UDP Health Checks.""" holder = base_classes.ComputeApiHolder(self.ReleaseTrack()) client = holder.client health_checks_utils.CheckProtocolAgnosticArgs(args) args_unset = not (args.port or args.check_interval or args.timeout or args.healthy_threshold or args.unhealthy_threshold or args.request or args.response) if args.description is None and args.port_name is None and args_unset: raise exceptions.ArgumentError('At least one property must be modified.') # Check that request and response are not empty. It is acceptable for it to # be None. if args.request is not None and not args.request: raise exceptions.ArgumentError( '"request" field for UDP can not be empty.') if args.response is not None and not args.response: raise exceptions.ArgumentError( '"response" field for UDP can not be empty.') health_check_ref = self.HEALTH_CHECK_ARG.ResolveAsResource( args, holder.resources) if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): get_request = self._GetRegionalGetRequest(client, health_check_ref) else: get_request = self._GetGetRequest(client, health_check_ref) objects = client.MakeRequests([get_request]) new_object = self.Modify(client, args, objects[0]) # If existing object is equal to the proposed object or if # Modify() returns None, then there is no work to be done, so we # print the resource and return. if objects[0] == new_object: log.status.Print( 'No change requested; skipping update for [{0}].'.format( objects[0].name)) return objects if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): set_request = self._GetRegionalSetRequest(client, health_check_ref, new_object) else: set_request = self._GetSetRequest(client, health_check_ref, new_object) return client.MakeRequests([set_request])
def _Run(holder, args, include_l7_internal_load_balancing): """Issues the request necessary for deleting the health check.""" client = holder.client health_check_arg = flags.HealthCheckArgument( '', plural=True, include_l7_internal_load_balancing=include_l7_internal_load_balancing) health_check_refs = health_check_arg.ResolveAsResource( args, holder.resources, scope_lister=compute_flags.GetDefaultScopeLister(client)) utils.PromptForDeletion(health_check_refs) requests = [] for health_check_ref in health_check_refs: if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): requests.append( (client.apitools_client.regionHealthChecks, 'Delete', client.messages.ComputeRegionHealthChecksDeleteRequest( **health_check_ref.AsDict()))) else: requests.append((client.apitools_client.healthChecks, 'Delete', client.messages.ComputeHealthChecksDeleteRequest( **health_check_ref.AsDict()))) return client.MakeRequests(requests)
def Run(self, args): # TODO(b/111311137): Cleanup to avoid code duplication. holder = base_classes.ComputeApiHolder(self.ReleaseTrack()) client = holder.client health_check_refs = self.HEALTH_CHECK_ARG.ResolveAsResource( args, holder.resources, scope_lister=compute_flags.GetDefaultScopeLister(client)) utils.PromptForDeletion(health_check_refs) requests = [] for health_check_ref in health_check_refs: if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): requests.append( (client.apitools_client.regionHealthChecks, 'Delete', client.messages.ComputeRegionHealthChecksDeleteRequest( **health_check_ref.AsDict()))) else: requests.append( (client.apitools_client.healthChecks, 'Delete', client.messages.ComputeHealthChecksDeleteRequest( **health_check_ref.AsDict()))) return client.MakeRequests(requests)
def _Run(args, holder, include_l7_internal_load_balancing, include_log_config): """Issues the request necessary for adding the health check.""" client = holder.client messages = client.messages # Check that port related flags are set for gRPC health check. args_unset = not (args.port or args.port_name or args.use_serving_port) if args_unset: raise exceptions.ToolException( 'Either --port, --port-name or --use-serving-port must be set for gRPC ' 'health check.' ) health_check_ref = flags.HealthCheckArgument( 'gRPC', include_l7_internal_load_balancing=include_l7_internal_load_balancing ).ResolveAsResource( args, holder.resources, default_scope=compute_scope.ScopeEnum.GLOBAL) grpc_health_check = messages.GRPCHealthCheck( port=args.port, portName=args.port_name, grpcServiceName=args.grpc_service_name) health_checks_utils.ValidateAndAddPortSpecificationToHealthCheck( args, grpc_health_check) if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): request = messages.ComputeRegionHealthChecksInsertRequest( healthCheck=messages.HealthCheck( name=health_check_ref.Name(), description=args.description, type=messages.HealthCheck.TypeValueValuesEnum.GRPC, grpcHealthCheck=grpc_health_check, checkIntervalSec=args.check_interval, timeoutSec=args.timeout, healthyThreshold=args.healthy_threshold, unhealthyThreshold=args.unhealthy_threshold), project=health_check_ref.project, region=health_check_ref.region) collection = client.apitools_client.regionHealthChecks else: request = messages.ComputeHealthChecksInsertRequest( healthCheck=messages.HealthCheck( name=health_check_ref.Name(), description=args.description, type=messages.HealthCheck.TypeValueValuesEnum.GRPC, grpcHealthCheck=grpc_health_check, checkIntervalSec=args.check_interval, timeoutSec=args.timeout, healthyThreshold=args.healthy_threshold, unhealthyThreshold=args.unhealthy_threshold), project=health_check_ref.project) collection = client.apitools_client.healthChecks if include_log_config: request.healthCheck.logConfig = health_checks_utils.CreateLogConfig( client, args) return client.MakeRequests([(collection, 'Insert', request)])
def _Run(args, holder, include_l7_internal_load_balancing): """Issues requests necessary to update the HTTP2 Health Checks.""" client = holder.client health_checks_utils.CheckProtocolAgnosticArgs(args) args_unset = not (args.port or args.request_path or args.check_interval or args.timeout or args.healthy_threshold or args.unhealthy_threshold or args.proxy_header or args.use_serving_port) if (args.description is None and args.host is None and args.response is None and args.port_name is None and args_unset): raise exceptions.ToolException( 'At least one property must be modified.') health_check_arg = flags.HealthCheckArgument( 'HTTP2', include_l7_internal_load_balancing=include_l7_internal_load_balancing) health_check_ref = health_check_arg.ResolveAsResource( args, holder.resources) if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): get_request = _GetRegionalGetRequest(client, health_check_ref) else: get_request = _GetGetRequest(client, health_check_ref) objects = client.MakeRequests([get_request]) new_object = _Modify(client, args, objects[0]) # If existing object is equal to the proposed object or if # _Modify() returns None, then there is no work to be done, so we # print the resource and return. if objects[0] == new_object: log.status.Print( 'No change requested; skipping update for [{0}].'.format( objects[0].name)) return objects if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): set_request = _GetRegionalSetRequest(client, health_check_ref, new_object) else: set_request = _GetSetRequest(client, health_check_ref, new_object) return client.MakeRequests([set_request])
def _Run(args, holder, include_l7_internal_load_balancing, include_log_config): """Issues the request necessary for adding the health check.""" client = holder.client messages = client.messages health_check_ref = flags.HealthCheckArgument( 'HTTP2', include_l7_internal_load_balancing=include_l7_internal_load_balancing ).ResolveAsResource(args, holder.resources, default_scope=compute_scope.ScopeEnum.GLOBAL) proxy_header = messages.HTTP2HealthCheck.ProxyHeaderValueValuesEnum( args.proxy_header) http2_health_check = messages.HTTP2HealthCheck( host=args.host, port=args.port, portName=args.port_name, requestPath=args.request_path, proxyHeader=proxy_header, response=args.response) health_checks_utils.ValidateAndAddPortSpecificationToHealthCheck( args, http2_health_check) if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): request = messages.ComputeRegionHealthChecksInsertRequest( healthCheck=messages.HealthCheck( name=health_check_ref.Name(), description=args.description, type=messages.HealthCheck.TypeValueValuesEnum.HTTP2, http2HealthCheck=http2_health_check, checkIntervalSec=args.check_interval, timeoutSec=args.timeout, healthyThreshold=args.healthy_threshold, unhealthyThreshold=args.unhealthy_threshold, ), project=health_check_ref.project, region=health_check_ref.region) collection = client.apitools_client.regionHealthChecks else: request = messages.ComputeHealthChecksInsertRequest( healthCheck=messages.HealthCheck( name=health_check_ref.Name(), description=args.description, type=messages.HealthCheck.TypeValueValuesEnum.HTTP2, http2HealthCheck=http2_health_check, checkIntervalSec=args.check_interval, timeoutSec=args.timeout, healthyThreshold=args.healthy_threshold, unhealthyThreshold=args.unhealthy_threshold), project=health_check_ref.project) collection = client.apitools_client.healthChecks if include_log_config: request.healthCheck.logConfig = health_checks_utils.CreateLogConfig( client, args) return client.MakeRequests([(collection, 'Insert', request)])
def _Run(args, holder, supports_response=False, supports_port_specification=False, regionalized=False): """Issues the request necessary for adding the health check.""" client = holder.client messages = client.messages health_check_ref = flags.HealthCheckArgument( 'HTTP2', include_alpha=regionalized).ResolveAsResource(args, holder.resources) proxy_header = messages.HTTP2HealthCheck.ProxyHeaderValueValuesEnum( args.proxy_header) http2_health_check = messages.HTTP2HealthCheck( host=args.host, port=args.port, portName=args.port_name, requestPath=args.request_path, proxyHeader=proxy_header) if supports_response: http2_health_check.response = args.response if supports_port_specification: health_checks_utils.ValidateAndAddPortSpecificationToHealthCheck( args, http2_health_check) if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): request = messages.ComputeRegionHealthChecksInsertRequest( healthCheck=messages.HealthCheck( name=health_check_ref.Name(), description=args.description, type=messages.HealthCheck.TypeValueValuesEnum.HTTP2, http2HealthCheck=http2_health_check, checkIntervalSec=args.check_interval, timeoutSec=args.timeout, healthyThreshold=args.healthy_threshold, unhealthyThreshold=args.unhealthy_threshold, ), project=health_check_ref.project, region=health_check_ref.region) collection = client.apitools_client.regionHealthChecks else: request = messages.ComputeHealthChecksInsertRequest( healthCheck=messages.HealthCheck( name=health_check_ref.Name(), description=args.description, type=messages.HealthCheck.TypeValueValuesEnum.HTTP2, http2HealthCheck=http2_health_check, checkIntervalSec=args.check_interval, timeoutSec=args.timeout, healthyThreshold=args.healthy_threshold, unhealthyThreshold=args.unhealthy_threshold), project=health_check_ref.project) collection = client.apitools_client.healthChecks return client.MakeRequests([(collection, 'Insert', request)])
def Run(self, args): holder = base_classes.ComputeApiHolder(self.ReleaseTrack()) client = holder.client health_checks_utils.CheckProtocolAgnosticArgs(args) args_unset = not (args.port or args.check_interval or args.timeout or args.healthy_threshold or args.unhealthy_threshold or args.proxy_header) if (args.description is None and args.request is None and args.response is None and args.port_name is None and args_unset): raise exceptions.ToolException( 'At least one property must be modified.') health_check_ref = self.HEALTH_CHECK_ARG.ResolveAsResource( args, holder.resources) if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): get_request = self._GetRegionalGetRequest(client, health_check_ref) else: get_request = self._GetGetRequest(client, health_check_ref) objects = client.MakeRequests([get_request]) new_object = self.Modify(client, args, objects[0]) # If existing object is equal to the proposed object or if # Modify() returns None, then there is no work to be done, so we # print the resource and return. if objects[0] == new_object: log.status.Print( 'No change requested; skipping update for [{0}].'.format( objects[0].name)) return objects if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): set_request = self._GetRegionalSetRequest(client, health_check_ref, new_object) else: set_request = self._GetSetRequest(client, health_check_ref, new_object) return client.MakeRequests([set_request])
def _Run(args, holder, include_l7_internal_load_balancing=False): """Issues the request necessary for adding the health check.""" client = holder.client health_check_ref = flags.HealthCheckArgument( 'UDP', include_l7_internal_load_balancing=include_l7_internal_load_balancing ).ResolveAsResource(args, holder.resources) # Check that request and response are not None and empty. if not args.request: raise exceptions.ToolException( '"request" field for UDP can not be empty.') if not args.response: raise exceptions.ToolException( '"response" field for UDP can not be empty.') if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): request = client.messages.ComputeRegionHealthChecksInsertRequest( healthCheck=client.messages.HealthCheck( name=health_check_ref.Name(), description=args.description, type=client.messages.HealthCheck.TypeValueValuesEnum.UDP, udpHealthCheck=client.messages.UDPHealthCheck( request=args.request, response=args.response, port=args.port, portName=args.port_name), checkIntervalSec=args.check_interval, timeoutSec=args.timeout, healthyThreshold=args.healthy_threshold, unhealthyThreshold=args.unhealthy_threshold, ), project=health_check_ref.project, region=health_check_ref.region) collection = client.apitools_client.regionHealthChecks else: request = client.messages.ComputeHealthChecksInsertRequest( healthCheck=client.messages.HealthCheck( name=health_check_ref.Name(), description=args.description, type=client.messages.HealthCheck.TypeValueValuesEnum.UDP, udpHealthCheck=client.messages.UDPHealthCheck( request=args.request, response=args.response, port=args.port, portName=args.port_name), checkIntervalSec=args.check_interval, timeoutSec=args.timeout, healthyThreshold=args.healthy_threshold, unhealthyThreshold=args.unhealthy_threshold, ), project=health_check_ref.project) collection = client.apitools_client.healthChecks return client.MakeRequests([(collection, 'Insert', request)])
def Run(self, args): """Issues the request necessary for adding the health check.""" holder = base_classes.ComputeApiHolder(self.ReleaseTrack()) client = holder.client health_check_ref = self.HEALTH_CHECK_ARG.ResolveAsResource( args, holder.resources) # Check that request and response are not None and empty. if not args.request: raise exceptions.ToolException( '"request" field for UDP can not be empty.') if not args.response: raise exceptions.ToolException( '"response" field for UDP can not be empty.') if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): request = client.messages.ComputeRegionHealthChecksInsertRequest( healthCheck=client.messages.HealthCheck( name=health_check_ref.Name(), description=args.description, type=client.messages.HealthCheck.TypeValueValuesEnum.UDP, udpHealthCheck=client.messages.UDPHealthCheck( request=args.request, response=args.response, port=args.port, portName=args.port_name), checkIntervalSec=args.check_interval, timeoutSec=args.timeout, healthyThreshold=args.healthy_threshold, unhealthyThreshold=args.unhealthy_threshold, ), project=health_check_ref.project, region=health_check_ref.region) collection = client.apitools_client.regionHealthChecks else: request = client.messages.ComputeHealthChecksInsertRequest( healthCheck=client.messages.HealthCheck( name=health_check_ref.Name(), description=args.description, type=client.messages.HealthCheck.TypeValueValuesEnum.UDP, udpHealthCheck=client.messages.UDPHealthCheck( request=args.request, response=args.response, port=args.port, portName=args.port_name), checkIntervalSec=args.check_interval, timeoutSec=args.timeout, healthyThreshold=args.healthy_threshold, unhealthyThreshold=args.unhealthy_threshold, ), project=health_check_ref.project) collection = client.apitools_client.healthChecks return client.MakeRequests([(collection, 'Insert', request)])
def _Run(args, release_track, include_l7_internal_load_balancing=False): """Issues the request necessary for adding the health check.""" holder = base_classes.ComputeApiHolder(release_track) client = holder.client messages = client.messages health_check_ref = flags.HealthCheckArgument( 'HTTP', include_l7_internal_load_balancing=include_l7_internal_load_balancing ).ResolveAsResource(args, holder.resources) proxy_header = messages.HTTPHealthCheck.ProxyHeaderValueValuesEnum( args.proxy_header) http_health_check = messages.HTTPHealthCheck( host=args.host, port=args.port, portName=args.port_name, requestPath=args.request_path, proxyHeader=proxy_header, response=args.response) health_checks_utils.ValidateAndAddPortSpecificationToHealthCheck( args, http_health_check) if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): request = messages.ComputeRegionHealthChecksInsertRequest( healthCheck=messages.HealthCheck( name=health_check_ref.Name(), description=args.description, type=messages.HealthCheck.TypeValueValuesEnum.HTTP, httpHealthCheck=http_health_check, checkIntervalSec=args.check_interval, timeoutSec=args.timeout, healthyThreshold=args.healthy_threshold, unhealthyThreshold=args.unhealthy_threshold), project=health_check_ref.project, region=health_check_ref.region) collection = client.apitools_client.regionHealthChecks else: request = messages.ComputeHealthChecksInsertRequest( healthCheck=messages.HealthCheck( name=health_check_ref.Name(), description=args.description, type=messages.HealthCheck.TypeValueValuesEnum.HTTP, httpHealthCheck=http_health_check, checkIntervalSec=args.check_interval, timeoutSec=args.timeout, healthyThreshold=args.healthy_threshold, unhealthyThreshold=args.unhealthy_threshold), project=health_check_ref.project) collection = client.apitools_client.healthChecks return client.MakeRequests([(collection, 'Insert', request)])
def Run(self, args): holder = base_classes.ComputeApiHolder(self.ReleaseTrack()) client = holder.client health_check_ref = self.HEALTH_CHECK_ARG.ResolveAsResource( args, holder.resources, scope_lister=compute_flags.GetDefaultScopeLister(client)) if health_checks_utils.IsRegionalHealthCheckRef(health_check_ref): request = client.messages.ComputeRegionHealthChecksGetRequest( **health_check_ref.AsDict()) collection = client.apitools_client.regionHealthChecks else: request = client.messages.ComputeHealthChecksGetRequest( **health_check_ref.AsDict()) collection = client.apitools_client.healthChecks return client.MakeRequests([(collection, 'Get', request)])[0]