def Run(self, args):
        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)

        messages = apis.GetMessagesModule('dns', api_version)

        dns_client = util.GetApiClient(api_version)

        zone_ref = util.GetRegistry(api_version).Parse(
            args.zone,
            params=util.GetParamsForRegistry(api_version, args),
            collection='dns.managedZones')
        param = util.GetParamsForRegistry(api_version,
                                          args,
                                          parent='managedZones')
        param['name'] = args.name
        rrsets_ref = util.GetRegistry(api_version).Parse(
            args.type, params=param, collection='dns.resourceRecordSets')

        request = messages.DnsResourceRecordSetsDeleteRequest(
            project=zone_ref.project,
            managedZone=zone_ref.Name(),
            name=util.AppendTrailingDot(args.name),
            type=args.type)

        if api_version == 'v2' and self._BetaOrAlpha():
            request.location = args.location

        result = dns_client.resourceRecordSets.Delete(request)
        log.DeletedResource(rrsets_ref)

        return result
    def Run(self, args):
        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)

        messages = apis.GetMessagesModule('dns', api_version)

        dns_client = util.GetApiClient(api_version)

        zone_ref = util.GetRegistry(api_version).Parse(
            args.zone,
            params=util.GetParamsForRegistry(api_version, args),
            collection='dns.managedZones')
        request = messages.DnsResourceRecordSetsCreateRequest(
            project=zone_ref.project,
            managedZone=zone_ref.Name(),
            resourceRecordSet=rrsets_util.CreateRecordSetFromArgs(
                args,
                api_version,
                allow_extended_records=(
                    self.ReleaseTrack() == base.ReleaseTrack.ALPHA)))

        if api_version == 'v2':
            request.location = args.location

        result = dns_client.resourceRecordSets.Create(request)

        return result
    def Run(self, args):
        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
        client = util.GetApiClient(api_version)
        messages = apis.GetMessagesModule('dns', api_version)

        # Get Response Policy Rule
        registry = util.GetRegistry(api_version)
        response_policy_rule_ref = registry.Parse(
            args.response_policy_rule,
            util.GetParamsForRegistry(api_version,
                                      args,
                                      parent='responsePolicies'),
            collection='dns.responsePolicyRules')
        response_policy_rule_name = response_policy_rule_ref.Name()

        delete_request = messages.DnsResponsePolicyRulesDeleteRequest(
            responsePolicy=args.response_policy,
            project=response_policy_rule_ref.project,
            responsePolicyRule=response_policy_rule_name)

        if api_version == 'v2' and self._BetaOrAlpha():
            delete_request.location = args.location

        result = client.responsePolicyRules.Delete(delete_request)

        log.DeletedResource(response_policy_rule_ref,
                            kind='ResponsePolicyRule')

        return result
Exemplo n.º 4
0
    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)
        registry = util.GetRegistry(api_version)

        zone_ref = registry.Parse(args.zone,
                                  util.GetParamsForRegistry(api_version, args),
                                  collection='dns.managedZones')
        return zones_client.Get(zone_ref)
  def Run(self, args):
    api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
    client = util.GetApiClient(api_version)
    messages = apis.GetMessagesModule('dns', api_version)

    # Get Response Policy Rule
    registry = util.GetRegistry(api_version)
    response_policy_rule_ref = registry.Parse(
        args.response_policy_rule,
        util.GetParamsForRegistry(api_version, args, parent='responsePolicies'),
        collection='dns.responsePolicyRules')
    response_policy_rule_name = response_policy_rule_ref.Name()

    response_policy_rule = messages.ResponsePolicyRule(
        ruleName=response_policy_rule_name)

    response_policy_rule.dnsName = args.dns_name

    if args.IsSpecified('behavior') and args.IsSpecified('local_data'):
      raise exceptions.ConflictingArgumentsException(
          'Only one of arguments [--behavior, --local-data] is allowed.')

    if args.IsSpecified('behavior'):
      response_policy_rule.behavior = command_util.ParseResponsePolicyRulesBehavior(
          args, api_version)
    elif args.IsSpecified('local_data'):
      rrsets = []
      for rrset in args.local_data:
        resource_record_set = messages.ResourceRecordSet(
            name=rrset.get('name'),
            type=rrset.get('type'),
            ttl=rrset.get('ttl'),
            rrdatas=rrset.get('rrdatas').split('|'))
        rrsets.append(resource_record_set)

      local_data = messages.ResponsePolicyRuleLocalData(
          localDatas=rrsets)
      response_policy_rule.localData = local_data

    create_request = messages.DnsResponsePolicyRulesCreateRequest(
        responsePolicy=args.response_policy,
        project=response_policy_rule_ref.project,
        responsePolicyRule=response_policy_rule)

    if api_version == 'v2' and self._BetaOrAlpha():
      create_request.location = args.location

    result = client.responsePolicyRules.Create(create_request)

    log.CreatedResource(response_policy_rule_ref, kind='ResponsePolicyRule')

    return result
Exemplo n.º 6
0
    def Run(self, args):
        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
        client = util.GetApiClient(api_version)
        messages = apis.GetMessagesModule('dns', api_version)

        # Get Response Policy
        registry = util.GetRegistry(api_version)
        response_policy_ref = registry.Parse(args.response_policies,
                                             util.GetParamsForRegistry(
                                                 api_version, args),
                                             collection='dns.responsePolicies')
        to_update = self._FetchResponsePolicy(response_policy_ref, api_version)

        if not (args.IsSpecified('networks') or args.IsSpecified('description')
                or (self._BetaOrAlpha() and args.IsSpecified('gkeclusters'))):
            log.status.Print('Nothing to update.')
            return to_update

        if args.IsSpecified('networks'):
            if args.networks == ['']:
                args.networks = []
            to_update.networks = command_util.ParseResponsePolicyNetworks(
                args.networks, response_policy_ref.project, api_version)

        if self._BetaOrAlpha() and args.IsSpecified('gkeclusters'):
            gkeclusters = args.gkeclusters
            to_update.gkeClusters = [
                messages.ResponsePolicyGKECluster(gkeClusterName=name)
                for name in gkeclusters
            ]

        if args.IsSpecified('description'):
            to_update.description = args.description

        update_req = messages.DnsResponsePoliciesUpdateRequest(
            responsePolicy=response_policy_ref.Name(),
            responsePolicyResource=to_update,
            project=response_policy_ref.project)

        if api_version == 'v2':
            update_req.location = args.location

        updated_response_policy = client.responsePolicies.Update(update_req)

        log.UpdatedResource(updated_response_policy.responsePolicy,
                            kind='ResponsePolicy')

        return updated_response_policy
  def Run(self, args):
    api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
    dns = util.GetApiClient(api_version)
    registry = util.GetRegistry(api_version)

    zone_ref = registry.Parse(
        args.dns_zone,
        util.GetParamsForRegistry(api_version, args),
        collection='dns.managedZones')
    request = dns.MESSAGES_MODULE.DnsManagedZonesDeleteRequest(
        managedZone=zone_ref.managedZone, project=zone_ref.project)

    if api_version == 'v2':
      # For a request with location, use v2 api.
      request.location = args.location

    result = dns.managedZones.Delete(request)
    log.DeletedResource(zone_ref)
    return result
    def Run(self, args):
        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
        client = util.GetApiClient(api_version)
        messages = apis.GetMessagesModule('dns', api_version)

        # Get Response Policy
        registry = util.GetRegistry(api_version)
        response_policy_ref = registry.Parse(args.response_policies,
                                             util.GetParamsForRegistry(
                                                 api_version, args),
                                             collection='dns.responsePolicies')

        list_request = messages.DnsResponsePolicyRulesListRequest(
            responsePolicy=response_policy_ref.Name(),
            project=response_policy_ref.project)

        if api_version == 'v2' and self._BetaOrAlpha():
            list_request.location = args.location

        return list_pager.YieldFromList(client.responsePolicyRules,
                                        list_request,
                                        field='responsePolicyRules')
Exemplo n.º 9
0
  def Run(self, args):
    api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
    client = util.GetApiClient(api_version)
    messages = apis.GetMessagesModule('dns', api_version)

    # Get Response Policy Rule
    registry = util.GetRegistry(api_version)
    response_policy_rule_ref = registry.Parse(
        args.response_policy_rule,
        util.GetParamsForRegistry(api_version, args, parent='responsePolicies'),
        collection='dns.responsePolicyRules')
    response_policy_rule_name = response_policy_rule_ref.Name()

    request = messages.DnsResponsePolicyRulesGetRequest(
        responsePolicy=args.response_policy,
        responsePolicyRule=response_policy_rule_name,
        project=properties.VALUES.core.project.GetOrFail())

    if api_version == 'v2' and self._BetaOrAlpha():
      request.location = args.location

    return client.responsePolicyRules.Get(request)
Exemplo n.º 10
0
  def Run(self, args):
    api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)

    dns_client = util.GetApiClient(api_version)

    zone_ref = util.GetRegistry(api_version).Parse(
        args.zone,
        params=util.GetParamsForRegistry(api_version, args),
        collection='dns.managedZones')

    list_request = dns_client.MESSAGES_MODULE.DnsResourceRecordSetsListRequest(
        project=zone_ref.project,
        managedZone=zone_ref.Name(),
        name=util.AppendTrailingDot(args.name),
        type=args.type)

    if api_version == 'v2' and self._BetaOrAlpha():
      list_request.location = args.location

    return list_pager.YieldFromList(
        dns_client.resourceRecordSets,
        list_request,
        limit=args.limit,
        field='rrsets')
Exemplo n.º 11
0
    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':
            if 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 and args.gkeclusters is None:
            raise exceptions.RequiredArgumentException(
                '--networks, --gkeclusters',
                ("""If --visibility is set to private, a list of networks or list of
           GKE clusters must be provided.'
         NOTE: You can provide an empty value ("") for private zones that
          have NO network or GKE clusters binding.
          """))

        # We explicitly want to allow --gkeclusters='' as an optional flag.
        if args.visibility == 'public' and args.IsSpecified('gkeclusters'):
            raise exceptions.InvalidArgumentException(
                '--gkeclusters',
                'If --visibility is set to public (default), setting gkeclusters is '
                'not allowed.')

        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
        dns = util.GetApiClient(api_version)
        messages = apis.GetMessagesModule('dns', api_version)
        registry = util.GetRegistry(api_version)

        zone_ref = registry.Parse(args.dns_zone,
                                  util.GetParamsForRegistry(api_version, args),
                                  collection='dns.managedZones')

        visibility_flag = args.visibility
        private_enum = None
        if api_version == 'v2':
            # v2 doesn't set lower_camel_enums, so enums are in upper case
            private_enum = messages.ManagedZone.VisibilityValueValuesEnum.PRIVATE
            visibility_flag = args.visibility.upper()
        else:
            private_enum = messages.ManagedZone.VisibilityValueValuesEnum.private
        visibility = messages.ManagedZone.VisibilityValueValuesEnum(
            visibility_flag)
        visibility_config = None
        if visibility == private_enum:
            # Handle explicitly empty networks case (--networks='')
            networks = args.networks if args.networks and 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
            ]

            # Handle the case when '--gkeclusters' is not specified.
            gkeclusters = args.gkeclusters or []

            gkecluster_configs = [
                messages.ManagedZonePrivateVisibilityConfigGKECluster(
                    gkeClusterName=name) for name in gkeclusters
            ]
            visibility_config = messages.ManagedZonePrivateVisibilityConfig(
                networks=network_configs, gkeClusters=gkecluster_configs)

        if args.forwarding_targets or args.private_forwarding_targets:
            forwarding_config = command_util.BetaParseManagedZoneForwardingConfigWithForwardingPath(
                messages=messages,
                server_list=args.forwarding_targets,
                private_server_list=args.private_forwarding_targets)
        else:
            forwarding_config = None

        dnssec_config = _MakeDnssecConfig(args, messages, api_version)
        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)

        request = messages.DnsManagedZonesCreateRequest(
            managedZone=zone, project=zone_ref.project)

        if api_version == 'v2':
            # For a request with location, use v2 api.
            request.location = args.location

        result = dns.managedZones.Create(request)
        log.CreatedResource(zone_ref)
        return [result]
    def Run(self, args):
        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)

        if not os.path.exists(args.records_file):
            raise import_util.RecordsFileNotFound(
                'Specified record file [{0}] not found.'.format(
                    args.records_file))
        if os.path.isdir(args.records_file):
            raise import_util.RecordsFileIsADirectory(
                'Specified record file [{0}] is a directory'.format(
                    args.records_file))

        dns = util.GetApiClient(api_version)

        # Get the managed-zone.
        zone_ref = util.GetRegistry(api_version).Parse(
            args.zone,
            params=util.GetParamsForRegistry(api_version, args),
            collection='dns.managedZones')

        try:
            get_request = dns.MESSAGES_MODULE.DnsManagedZonesGetRequest(
                project=zone_ref.project, managedZone=zone_ref.managedZone)

            if api_version == 'v2' and self._IsBetaOrAlpha():
                get_request.location = args.location

            zone = dns.managedZones.Get(get_request)
        except apitools_exceptions.HttpError as error:
            raise calliope_exceptions.HttpException(error)

        # Get the current record-sets.
        current = {}
        list_request = dns.MESSAGES_MODULE.DnsResourceRecordSetsListRequest(
            project=zone_ref.project, managedZone=zone_ref.Name())

        if api_version == 'v2':
            list_request.location = args.location

        for record in list_pager.YieldFromList(dns.resourceRecordSets,
                                               list_request,
                                               field='rrsets'):
            current[(record.name, record.type)] = record

        # Get the imported record-sets.
        try:
            with files.FileReader(args.records_file) as import_file:
                if args.zone_file_format:
                    imported = import_util.RecordSetsFromZoneFile(
                        import_file, zone.dnsName, api_version=api_version)
                else:
                    imported = import_util.RecordSetsFromYamlFile(
                        import_file,
                        include_extended_records=self._IsAlpha(),
                        api_version=api_version)
        except Exception as exp:
            msg = (
                'Unable to read record-sets from specified records-file [{0}] '
                'because [{1}]')
            msg = msg.format(args.records_file, exp.message)
            raise import_util.UnableToReadRecordsFile(msg)

        # Get the change resulting from the imported record-sets.
        change = import_util.ComputeChange(current,
                                           imported,
                                           args.delete_all_existing,
                                           zone.dnsName,
                                           args.replace_origin_ns,
                                           api_version=api_version)
        if not change:
            msg = 'Nothing to do, all the records in [{0}] already exist.'.format(
                args.records_file)
            log.status.Print(msg)
            return None

        # Send the change to the service.
        create_request = dns.MESSAGES_MODULE.DnsChangesCreateRequest(
            change=change, managedZone=zone.name, project=zone_ref.project)

        if api_version == 'v2' and self._IsBetaOrAlpha():
            create_request.location = args.location

        result = dns.changes.Create(create_request)
        param = util.GetParamsForRegistry(api_version,
                                          args,
                                          parent='managedZones')
        param['changeId'] = result.id
        change_ref = util.GetRegistry(api_version).Parse(
            line=None, collection='dns.changes', params=param)
        msg = 'Imported record-sets from [{0}] into managed-zone [{1}].'.format(
            args.records_file, zone_ref.Name())
        log.status.Print(msg)
        log.CreatedResource(change_ref)
        return result
    def Run(self, args):
        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)
        client = util.GetApiClient(api_version)
        messages = apis.GetMessagesModule('dns', api_version)

        # Get Response Policy
        registry = util.GetRegistry(api_version)
        response_policy_ref = registry.Parse(args.response_policies,
                                             util.GetParamsForRegistry(
                                                 api_version, args),
                                             collection='dns.responsePolicies')
        response_policy_name = response_policy_ref.Name()

        response_policy = messages.ResponsePolicy(
            responsePolicyName=response_policy_name)

        if args.IsSpecified('networks') or (self._BetaOrAlpha() and
                                            args.IsSpecified('gkeclusters')):
            if args.networks == ['']:
                args.networks = []
            response_policy.networks = command_util.ParseResponsePolicyNetworks(
                args.networks, response_policy_ref.project, api_version)

            if (self.ReleaseTrack()
                    in (base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA)
                    and args.IsSpecified('gkeclusters')):
                gkeclusters = args.gkeclusters
                response_policy.gkeClusters = [
                    messages.ResponsePolicyGKECluster(gkeClusterName=name)
                    for name in gkeclusters
                ]

        else:
            if self._BetaOrAlpha():
                raise exceptions.RequiredArgumentException(
                    '--networks', ("""A list of networks must be provided.'
           NOTE: You can provide an empty value ("") for response policies that
           have NO network binding.
            """))

            raise exceptions.RequiredArgumentException(
                '--networks,--gkeclusters',
                ("""A list of networks or GKE clusters must be provided.'
         NOTE: You can provide an empty value ("") for response policies that
          have NO network or GKE clusters binding.
          """))

        if args.IsSpecified('description'):
            response_policy.description = args.description

        create_request = messages.DnsResponsePoliciesCreateRequest(
            responsePolicy=response_policy,
            project=response_policy_ref.project)

        if api_version == 'v2':
            create_request.location = args.location

        result = client.responsePolicies.Create(create_request)

        log.CreatedResource(response_policy_ref, kind='ResponsePolicy')

        return result
def _Update(zones_client,
            args,
            private_visibility_config=None,
            forwarding_config=None,
            peering_config=None,
            reverse_lookup_config=None,
            cloud_logging_config=None,
            api_version='v1',
            cleared_fields=None):
    """Helper function to perform the update.

  Args:
    zones_client: the managed zones API client.
    args: the args provided by the user on the command line.
    private_visibility_config: zone visibility config.
    forwarding_config: zone forwarding config.
    peering_config: zone peering config.
    reverse_lookup_config: zone reverse lookup config.
    cloud_logging_config: Stackdriver logging config.
    api_version: the API version of this request.
    cleared_fields: the fields that should be included in the request JSON as
      their default value (fields that are their default value will be omitted
      otherwise).

  Returns:
    The update labels and PATCH call response.
  """
    registry = util.GetRegistry(api_version)

    zone_ref = registry.Parse(args.zone,
                              util.GetParamsForRegistry(api_version, args),
                              collection='dns.managedZones')

    dnssec_config = command_util.ParseDnssecConfigArgs(args,
                                                       zones_client.messages,
                                                       api_version)
    labels_update = labels_util.ProcessUpdateArgsLazy(
        args, zones_client.messages.ManagedZone.LabelsValue,
        lambda: zones_client.Get(zone_ref).labels)

    update_results = []

    if labels_update.GetOrNone():
        update_results.append(
            zones_client.UpdateLabels(zone_ref, labels_update.GetOrNone()))

    kwargs = {}
    if private_visibility_config:
        kwargs['private_visibility_config'] = private_visibility_config
    if forwarding_config:
        kwargs['forwarding_config'] = forwarding_config
    if peering_config:
        kwargs['peering_config'] = peering_config
    if reverse_lookup_config:
        kwargs['reverse_lookup_config'] = reverse_lookup_config
    if cloud_logging_config:
        kwargs['cloud_logging_config'] = cloud_logging_config

    if dnssec_config or args.description or kwargs:
        update_results.append(
            zones_client.Patch(zone_ref,
                               args.async_,
                               dnssec_config=dnssec_config,
                               description=args.description,
                               labels=None,
                               cleared_fields=cleared_fields,
                               **kwargs))

    return update_results
    def Run(self, args):
        api_version = util.GetApiFromTrackAndArgs(self.ReleaseTrack(), args)

        dns = util.GetApiClient(api_version)

        # Get the managed-zone.
        zone_ref = util.GetRegistry(api_version).Parse(
            args.zone,
            params=util.GetParamsForRegistry(api_version, args),
            collection='dns.managedZones')
        try:
            get_request = dns.MESSAGES_MODULE.DnsManagedZonesGetRequest(
                project=zone_ref.project, managedZone=zone_ref.managedZone)

            if api_version == 'v2' and self._IsBetaOrAlpha():
                get_request.location = args.location

            zone = dns.managedZones.Get(get_request)
        except apitools_exceptions.HttpError as error:
            raise calliope_exceptions.HttpException(error)

        # Get all the record-sets.
        record_sets = []
        list_request = dns.MESSAGES_MODULE.DnsResourceRecordSetsListRequest(
            project=zone_ref.project, managedZone=zone_ref.Name())

        if api_version == 'v2' and self._IsBetaOrAlpha():
            list_request.location = args.location

        for record_set in list_pager.YieldFromList(dns.resourceRecordSets,
                                                   list_request,
                                                   field='rrsets'):
            # Alpha is handled differently as it supports ALIAS records.
            if self._IsAlpha():
                # For BIND file format, ALIAS record sets must be ignored, as they are
                # not DNS standards. A zone will have at most one ALIAS record.
                if args.zone_file_format:
                    if record_set.type == 'ALIAS':
                        log.warning(
                            'Skippig ALIAS record found in zone, as ALIAS record are custom'
                            ' to Cloud DNS and do not have a standard BIND format. To '
                            'export ALIAS records, use YAML format instead.')
                        continue
            else:  # beta or GA
                # Quietly ignore ALIAS records in beta/GA - they aren't supported yet.
                if record_set.type == 'ALIAS':
                    continue

            record_sets.append(record_set)

        # Export the record-sets.
        try:
            with files.FileWriter(args.records_file) as export_file:
                if args.zone_file_format:
                    export_util.WriteToZoneFile(export_file, record_sets,
                                                zone.dnsName)
                else:
                    export_util.WriteToYamlFile(export_file, record_sets)
        except Exception as exp:
            msg = 'Unable to export record-sets to file [{0}]: {1}'.format(
                args.records_file, exp)
            raise export_util.UnableToExportRecordsToFile(msg)

        log.status.Print('Exported record-sets to [{0}].'.format(
            args.records_file))