def CreateRecordSetFromArgs(args, api_version='v1'):
    """Creates and returns a record-set from the given args.

  Args:
    args: The arguments to use to create the record-set.
    api_version: [str], the api version to use for creating the RecordSet.

  Raises:
    UnsupportedRecordType: If given record-set type is not supported

  Returns:
    ResourceRecordSet, the record-set created from the given args.
  """
    messages = apis.GetMessagesModule('dns', api_version)
    rd_type = rdatatype.from_text(args.type)
    if import_util.GetRdataTranslation(rd_type) is None:
        raise UnsupportedRecordType('Unsupported record-set type [{0}]'.format(
            args.type))

    record_set = messages.ResourceRecordSet()
    # Need to assign kind to default value for useful equals comparisons.
    record_set.kind = record_set.kind
    record_set.name = util.AppendTrailingDot(args.name)
    record_set.ttl = args.ttl
    record_set.type = args.type
    record_set.rrdatas = args.data
    if rd_type is rdatatype.TXT or rd_type is rdatatype.SPF:
        record_set.rrdatas = [
            import_util.QuotedText(datum) for datum in args.data
        ]
    return record_set
def CreateRecordSetFromArgs(args):
    """Creates and returns a record-set from the given args.

  Args:
    args: The arguments to use to create the record-set.

  Raises:
    ToolException: If given record-set type is not supported

  Returns:
    ResourceRecordSet, the record-set created from the given args.
  """
    rd_type = rdatatype.from_text(args.type)
    if import_util.GetRdataTranslation(rd_type) is None:
        raise exceptions.ToolException(
            'unsupported record-set type [{0}]'.format(args.type))

    record_set = messages.ResourceRecordSet()
    # Need to assign kind to default value for useful equals comparisons.
    record_set.kind = record_set.kind
    record_set.name = util.AppendTrailingDot(args.name)
    record_set.ttl = args.ttl
    record_set.type = args.type
    record_set.rrdatas = args.data
    if rd_type is rdatatype.TXT or rd_type is rdatatype.SPF:
        record_set.rrdatas = [
            import_util.QuotedText(datum) for datum in args.data
        ]
    return record_set
def CreateRecordSetFromArgs(args,
                            api_version='v1',
                            allow_extended_records=False):
    """Creates and returns a record-set from the given args.

  Args:
    args: The arguments to use to create the record-set.
    api_version: [str], the api version to use for creating the RecordSet.
    allow_extended_records: [bool], enables extended records if true, otherwise
      throws an exception when given an extended record type.

  Raises:
    UnsupportedRecordType: If given record-set type is not supported

  Returns:
    ResourceRecordSet, the record-set created from the given args.
  """
    messages = apis.GetMessagesModule('dns', api_version)
    if allow_extended_records:
        if args.type in record_types.CLOUD_DNS_EXTENDED_TYPES:
            # Extended records are internal to Cloud DNS, so don't have wire values.
            rd_type = rdatatype.NONE
        else:
            rd_type = _TryParseRRTypeFromString(args.type)
    else:
        rd_type = _TryParseRRTypeFromString(args.type)

    record_set = messages.ResourceRecordSet()
    # Need to assign kind to default value for useful equals comparisons.
    record_set.kind = record_set.kind
    record_set.name = util.AppendTrailingDot(args.name)
    record_set.ttl = args.ttl
    record_set.type = args.type

    if args.rrdatas:
        record_set.rrdatas = args.rrdatas
        if rd_type is rdatatype.TXT or rd_type is rdatatype.SPF:
            record_set.rrdatas = [
                import_util.QuotedText(datum) for datum in args.rrdatas
            ]

    elif args.routing_policy_type == 'WRR':
        record_set.routingPolicy = messages.RRSetRoutingPolicy(
            wrr=messages.RRSetRoutingPolicyWrrPolicy(items=[]))
        for policy_item in args.routing_policy_data:
            if rd_type is rdatatype.TXT or rd_type is rdatatype.SPF:
                policy_item['rrdatas'] = [
                    import_util.QuotedText(datum)
                    for datum in policy_item['rrdatas']
                ]
            record_set.routingPolicy.wrr.items.append(
                messages.RRSetRoutingPolicyWrrPolicyWrrPolicyItem(
                    weight=float(policy_item['key']),
                    rrdatas=policy_item['rrdatas']))

    elif args.routing_policy_type == 'GEO':
        record_set.routingPolicy = messages.RRSetRoutingPolicy(
            geo=messages.RRSetRoutingPolicyGeoPolicy(items=[]))
        for policy_item in args.routing_policy_data:
            if rd_type is rdatatype.TXT or rd_type is rdatatype.SPF:
                policy_item['rrdatas'] = [
                    import_util.QuotedText(datum)
                    for datum in policy_item['rrdatas']
                ]
            record_set.routingPolicy.geo.items.append(
                messages.RRSetRoutingPolicyGeoPolicyGeoPolicyItem(
                    location=policy_item['key'],
                    rrdatas=policy_item['rrdatas']))

    return record_set