diff --git a/src/azure-cli/azure/cli/command_modules/network/custom.py b/src/azure-cli/azure/cli/command_modules/network/custom.py index 3d569a5077d..b294e88f814 100644 --- a/src/azure-cli/azure/cli/command_modules/network/custom.py +++ b/src/azure-cli/azure/cli/command_modules/network/custom.py @@ -2474,7 +2474,13 @@ def export_zone(cmd, resource_group_name, zone_name, file_name=None): # pylint: if record_type not in zone_obj[record_set_name]: zone_obj[record_set_name][record_type] = [] - if record_type == 'aaaa' or record_type == 'a': + # Checking for alias record + if (record_type == 'a' or record_type == 'aaaa' or record_type == 'cname') and record_set.target_resource.id: + target_resource_id = record_set.target_resource.id + record_obj.update({'target-resource-id': record_type.upper() + " " + target_resource_id}) + record_type = 'alias' + zone_obj[record_set_name][record_type] = [] + elif record_type == 'aaaa' or record_type == 'a': record_obj.update({'ip': ''}) elif record_type == 'cname': record_obj.update({'alias': ''}) diff --git a/src/azure-cli/azure/cli/command_modules/network/zone_file/parse_zone_file.py b/src/azure-cli/azure/cli/command_modules/network/zone_file/parse_zone_file.py index 07fb76e08aa..77c17bb2c5b 100644 --- a/src/azure-cli/azure/cli/command_modules/network/zone_file/parse_zone_file.py +++ b/src/azure-cli/azure/cli/command_modules/network/zone_file/parse_zone_file.py @@ -71,7 +71,8 @@ 'ptr': r'(?P[@\*\w\.-]*)\s+(?:(?P\d+\w*)\s+)?(?:(?Pin)\s+)?(?Pptr)\s+(?P[\w\.-]+)', 'srv': r'(?P[@\*\w\.-]*)\s+(?:(?P\d+\w*)\s+)?(?:(?Pin)\s+)?(?Psrv)\s+(?P\d+)\s+(?P\d+)\s+(?P\d+)\s+(?P[@\w\.-]+)', 'spf': r'(?P[@\*\w\.-]*)\s+(?:(?P\d+\w*)\s+)?(?:(?Pin)\s+)?(?Pspf)\s+(?P.+)', - 'uri': r'(?P[@\*\w\.-]*)\s+(?:(?P\d+\w*)\s+)?(?:(?Pin)\s+)?(?Puri)\s+(?P\d+)\s+(?P\d+)\s+(?P[\w\.]+)' + 'uri': r'(?P[@\*\w\.-]*)\s+(?:(?P\d+\w*)\s+)?(?:(?Pin)\s+)?(?Puri)\s+(?P\d+)\s+(?P\d+)\s+(?P[\w\.]+)', + 'alias': r'(?P[@\*\w\.-]*)\s+(?:(?P\d+\w*)\s+)?(?:(?Pazure)\s+)?(?Palias)\s+(?Paaaa|a|cname)\s+(?P[a-zA-Z0-9/._-]*)', } _COMPILED_REGEX = {k: re.compile(v, re.IGNORECASE) for k, v in _REGEX.items()} diff --git a/src/azure-cli/azure/cli/command_modules/network/zone_file/record_processors.py b/src/azure-cli/azure/cli/command_modules/network/zone_file/record_processors.py index d9896a6b83f..0c3de6eba9e 100644 --- a/src/azure-cli/azure/cli/command_modules/network/zone_file/record_processors.py +++ b/src/azure-cli/azure/cli/command_modules/network/zone_file/record_processors.py @@ -83,8 +83,12 @@ def process_rr(io, data, record_type, record_keys, name, print_name): elif not isinstance(record_keys, list): raise ValueError('record_keys must be a string or list of strings') + in_or_azure = "IN" + if record_type == 'ALIAS': + in_or_azure = "AZURE" + name_display = name if print_name else ' ' * len(name) - print('{} {} IN {} '.format(name_display, data['ttl'], record_type), end='', file=io) + print('{} {} {} {} '.format(name_display, data['ttl'], in_or_azure, record_type), end='', file=io) for i, key in enumerate(record_keys): print(data[key], end='\n' if i == len(record_keys) - 1 else ' ', file=io) @@ -124,3 +128,7 @@ def process_txt(io, data, name, print_name=False): def process_srv(io, data, name, print_name=False): return process_rr(io, data, 'SRV', ['priority', 'weight', 'port', 'target'], name, print_name) + + +def process_alias(io, data, name, print_name=False): + return process_rr(io, data, 'ALIAS', 'target-resource-id', name, print_name)