def Run(self, args): zones_client = managed_zones.Client.FromApiVersion('v1') messages = apis.GetMessagesModule('dns', 'v1') forwarding_config = None if args.IsSpecified('forwarding_targets') or args.IsSpecified( 'private_forwarding_targets'): forwarding_config = command_util.ParseManagedZoneForwardingConfigWithForwardingPath( messages=messages, server_list=args.forwarding_targets, private_server_list=args.private_forwarding_targets) else: forwarding_config = None peering_config = None if args.target_project and args.target_network: peering_network = 'https://www.googleapis.com/compute/v1/projects/{}/global/networks/{}'.format( args.target_project, args.target_network) peering_config = messages.ManagedZonePeeringConfig() peering_config.targetNetwork = messages.ManagedZonePeeringConfigTargetNetwork( networkUrl=peering_network) visibility_config = None if args.networks: networks = args.networks if args.networks != [''] else [] def GetNetworkSelfLink(network): return util.GetRegistry('v1').Parse( network, collection='compute.networks', params={ 'project': properties.VALUES.core.project.GetOrFail }).SelfLink() network_urls = [GetNetworkSelfLink(n) for n in networks] network_configs = [ messages.ManagedZonePrivateVisibilityConfigNetwork(networkUrl=nurl) for nurl in network_urls ] visibility_config = messages.ManagedZonePrivateVisibilityConfig( networks=network_configs) reverse_lookup_config = None if args.IsSpecified( 'managed_reverse_lookup') and args.managed_reverse_lookup: reverse_lookup_config = messages.ManagedZoneReverseLookupConfig() return _Update( zones_client, args, private_visibility_config=visibility_config, forwarding_config=forwarding_config, peering_config=peering_config, reverse_lookup_config=reverse_lookup_config)
def Run(self, args): # We explicitly want to allow --networks='' as a valid option and we need # to differentiate between that option and not passing --networks at all. if args.visibility == 'public' and args.IsSpecified('networks'): raise exceptions.InvalidArgumentException( '--networks', 'If --visibility is set to public (default), setting networks is ' 'not allowed.') if args.visibility == 'private' and args.networks is None: raise exceptions.RequiredArgumentException('--networks', (""" If --visibility is set to private, a list of networks must be provided.' NOTE: You can provide an empty value ("") for private zones that have NO network binding. """)) dns = util.GetApiClient('v1') messages = apis.GetMessagesModule('dns', 'v1') registry = util.GetRegistry('v1') zone_ref = registry.Parse(args.dns_zone, params={ 'project': properties.VALUES.core.project.GetOrFail, }, collection='dns.managedZones') visibility = messages.ManagedZone.VisibilityValueValuesEnum( args.visibility) visibility_config = None if visibility == messages.ManagedZone.VisibilityValueValuesEnum.private: # Handle explicitly empty networks case (--networks='') networks = args.networks if args.networks != [''] else [] def GetNetworkSelfLink(network): return registry.Parse(network, collection='compute.networks', params={ 'project': zone_ref.project }).SelfLink() network_urls = [GetNetworkSelfLink(n) for n in networks] network_configs = [ messages.ManagedZonePrivateVisibilityConfigNetwork( networkUrl=nurl) for nurl in network_urls ] visibility_config = messages.ManagedZonePrivateVisibilityConfig( networks=network_configs) if args.IsSpecified('forwarding_targets') or args.IsSpecified( 'private_forwarding_targets'): forwarding_config = command_util.ParseManagedZoneForwardingConfigWithForwardingPath( messages=messages, server_list=args.forwarding_targets, private_server_list=args.private_forwarding_targets) else: forwarding_config = None dnssec_config = _MakeDnssecConfig(args, messages) labels = labels_util.ParseCreateArgs(args, messages.ManagedZone.LabelsValue) peering_config = None if args.target_project and args.target_network: peering_network = 'https://www.googleapis.com/compute/v1/projects/{}/global/networks/{}'.format( args.target_project, args.target_network) peering_config = messages.ManagedZonePeeringConfig() peering_config.targetNetwork = messages.ManagedZonePeeringConfigTargetNetwork( networkUrl=peering_network) reverse_lookup_config = None if args.IsSpecified( 'managed_reverse_lookup') and args.managed_reverse_lookup: reverse_lookup_config = messages.ManagedZoneReverseLookupConfig() service_directory_config = None if args.IsSpecified('service_directory_namespace' ) and args.service_directory_namespace: service_directory_config = messages.ManagedZoneServiceDirectoryConfig( namespace=messages.ManagedZoneServiceDirectoryConfigNamespace( namespaceUrl=args.service_directory_namespace)) cloud_logging_config = None if args.IsSpecified('log_dns_queries'): cloud_logging_config = messages.ManagedZoneCloudLoggingConfig() cloud_logging_config.enableLogging = args.log_dns_queries zone = messages.ManagedZone( name=zone_ref.managedZone, dnsName=util.AppendTrailingDot(args.dns_name), description=args.description, dnssecConfig=dnssec_config, labels=labels, visibility=visibility, forwardingConfig=forwarding_config, privateVisibilityConfig=visibility_config, peeringConfig=peering_config, reverseLookupConfig=reverse_lookup_config, serviceDirectoryConfig=service_directory_config, cloudLoggingConfig=cloud_logging_config) result = dns.managedZones.Create( messages.DnsManagedZonesCreateRequest(managedZone=zone, project=zone_ref.project)) log.CreatedResource(zone_ref) return [result]
def Run(self, args): api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args) location = args.location if api_version == 'v2' else None zones_client = managed_zones.Client.FromApiVersion( api_version, location) messages = zones_client.messages forwarding_config = None if args.forwarding_targets or args.private_forwarding_targets: forwarding_config = command_util.ParseManagedZoneForwardingConfigWithForwardingPath( messages=messages, server_list=args.forwarding_targets, private_server_list=args.private_forwarding_targets) else: forwarding_config = None peering_config = None if args.target_project and args.target_network: peering_network = 'https://www.googleapis.com/compute/v1/projects/{}/global/networks/{}'.format( args.target_project, args.target_network) peering_config = messages.ManagedZonePeeringConfig() peering_config.targetNetwork = messages.ManagedZonePeeringConfigTargetNetwork( networkUrl=peering_network) visibility_config = None # When the Python object is converted to JSON for the HTTP request body, all # fields that are their default value will be omitted by default. This is # problematic for list fields, as an empty list signals that the list field # should be cleared in a PATCH request, but an empty list is also the # default list value. # # Cleared fields tracks the fields that should be included as their default # value in the HTTP request body's JSON. Cleared fields is ultimately # passed to the JSON encoder in the SDK library internals to achieve this. cleared_fields = [] if args.networks is not None or args.gkeclusters is not None: # If the user explicitly gave an empty value to networks, clear the field. # Note that a value of 'None' means the user did not include the networks # flag, so it should not be cleared in that case. if args.networks == []: # pylint: disable=g-explicit-bool-comparison cleared_fields.append('privateVisibilityConfig.networks') networks = args.networks if args.networks else [] def GetNetworkSelfLink(network): return util.GetRegistry(api_version).Parse( network, collection='compute.networks', params={ 'project': properties.VALUES.core.project.GetOrFail }).SelfLink() network_urls = [GetNetworkSelfLink(n) for n in networks] network_configs = [ messages.ManagedZonePrivateVisibilityConfigNetwork( networkUrl=nurl) for nurl in network_urls ] # If the user explicitly gave an empty value to clusters, clear the field. if args.gkeclusters == []: # pylint: disable=g-explicit-bool-comparison cleared_fields.append('privateVisibilityConfig.gkeClusters') gkeclusters = args.gkeclusters if args.gkeclusters else [] gkecluster_configs = [ messages.ManagedZonePrivateVisibilityConfigGKECluster( gkeClusterName=name) for name in gkeclusters ] visibility_config = messages.ManagedZonePrivateVisibilityConfig( networks=network_configs, gkeClusters=gkecluster_configs) reverse_lookup_config = None if args.IsSpecified( 'managed_reverse_lookup') and args.managed_reverse_lookup: reverse_lookup_config = messages.ManagedZoneReverseLookupConfig() cloud_logging_config = None if args.IsSpecified('log_dns_queries'): cloud_logging_config = messages.ManagedZoneCloudLoggingConfig() cloud_logging_config.enableLogging = args.log_dns_queries return _Update(zones_client, args, private_visibility_config=visibility_config, forwarding_config=forwarding_config, peering_config=peering_config, reverse_lookup_config=reverse_lookup_config, cloud_logging_config=cloud_logging_config, api_version=api_version, cleared_fields=cleared_fields)
def Run(self, args): zones_client = managed_zones.Client.FromApiVersion('v1') messages = apis.GetMessagesModule('dns', 'v1') forwarding_config = None if args.IsSpecified('forwarding_targets') or args.IsSpecified( 'private_forwarding_targets'): forwarding_config = command_util.ParseManagedZoneForwardingConfigWithForwardingPath( messages=messages, server_list=args.forwarding_targets, private_server_list=args.private_forwarding_targets) else: forwarding_config = None peering_config = None if args.target_project and args.target_network: peering_network = 'https://www.googleapis.com/compute/v1/projects/{}/global/networks/{}'.format( args.target_project, args.target_network) peering_config = messages.ManagedZonePeeringConfig() peering_config.targetNetwork = messages.ManagedZonePeeringConfigTargetNetwork( networkUrl=peering_network) visibility_config = None # When the Python object is converted to JSON for the HTTP request body, all # fields that are their default value will be omitted by default. This is # problematic for list fields, as an empty list signals that the list field # should be cleared in a PATCH request, but an empty list is also the # default list value. # # Cleared fields tracks the fields that should be included as their default # value in the HTTP request body's JSON. Cleared fields is ultimately # passed to the JSON encoder in the SDK library internals to achieve this. cleared_fields = [] if args.networks is not None: networks = args.networks # If networks is an empty array, it should clear the networks value. if not networks: cleared_fields.append('privateVisibilityConfig.networks') def GetNetworkSelfLink(network): return util.GetRegistry('v1').Parse( network, collection='compute.networks', params={ 'project': properties.VALUES.core.project.GetOrFail }).SelfLink() network_urls = [GetNetworkSelfLink(n) for n in networks] network_configs = [ messages.ManagedZonePrivateVisibilityConfigNetwork( networkUrl=nurl) for nurl in network_urls ] visibility_config = messages.ManagedZonePrivateVisibilityConfig( networks=network_configs) reverse_lookup_config = None if args.IsSpecified( 'managed_reverse_lookup') and args.managed_reverse_lookup: reverse_lookup_config = messages.ManagedZoneReverseLookupConfig() cloud_logging_config = None if args.IsSpecified('log_dns_queries'): cloud_logging_config = messages.ManagedZoneCloudLoggingConfig() cloud_logging_config.enableLogging = args.log_dns_queries return _Update(zones_client, args, private_visibility_config=visibility_config, forwarding_config=forwarding_config, peering_config=peering_config, reverse_lookup_config=reverse_lookup_config, cloud_logging_config=cloud_logging_config, cleared_fields=cleared_fields)