Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cname_add should have an option to set the ttl #173

Open
oyvindhagberg opened this issue Oct 24, 2023 · 1 comment
Open

cname_add should have an option to set the ttl #173

oyvindhagberg opened this issue Oct 24, 2023 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@oyvindhagberg
Copy link
Contributor

The API lets you set a ttl on a cname that is different from the ttl setting on the host object.
But the CLI doesn't let you do that, yet.
Let's add an option to the cname_add command. And consider doing something similar to cname_replace so you can modify the ttl value without deleting the cname and adding it again.

mreg-cli/mreg_cli/host.py

Lines 1292 to 1341 in 9a66b8c

def cname_add(args):
"""Add a CNAME record to host.
"""
# Get host info or raise exception
info = host_info_by_name(args.name)
alias = clean_hostname(args.alias)
# If alias name already exist as host, abort.
try:
host_info_by_name(alias)
cli_error("The alias name is in use by an existing host. Find a new alias.")
except HostNotFoundWarning:
pass
# Check if cname already in use
if cname_exists(alias):
cli_warning("The alias is already in use.")
# Check if the cname is in a zone controlled by mreg
check_zone_for_hostname(alias, args.force)
data = {'host': info['id'],
'name': alias}
# Create CNAME record
path = "/api/v1/cnames/"
history.record_post(path, "", data, undoable=False)
post(path, **data)
cli_info("Added cname alias {} for {}".format(alias, info["name"]),
print_msg=True)
# Add 'cname_add' as a sub command to the 'host' command
host.add_command(
prog='cname_add',
description='Add a CNAME record to host. If NAME is an alias '
'the cname host is used as target for ALIAS.',
short_desc='Add CNAME.',
callback=cname_add,
flags=[
Flag('name',
description='Name of target host.',
metavar='NAME'),
Flag('alias',
description='Name of CNAME host.',
metavar='ALIAS'),
Flag('-force',
action='store_true',
description='Enable force.'),
],
)

@oyvindhagberg oyvindhagberg added enhancement New feature or request good first issue Good for newcomers labels Oct 24, 2023
@terjekv
Copy link
Collaborator

terjekv commented Jan 30, 2024

#151 suggests that one can use host set_ttl <cname> <ttl> to set the ttl of a cname. The current workflow thus seems to be:

host cname_add arecord cname
host set_ttl cname 400

This should be documented. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants