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

dns-update-system-records: add support for nsupdate output format #423

Closed
wants to merge 2 commits into from
Closed

dns-update-system-records: add support for nsupdate output format #423

wants to merge 2 commits into from

Conversation

MartinBasti
Copy link
Contributor

@MartinBasti MartinBasti commented Jan 31, 2017

Option --out does the trick

"""Store data in nsupdate format in file"""
def parse_rname_rtype(record):
"""Get rname and rtype from textual representation of record"""
l = record.split(' ', 5)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're limiting the amount of splits, I think 4 is the correct number here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


already_removed = set()
for key in self.record_groups:
if result.get(key):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use key in result here? It would improve readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not fixed, reverting. I did that on purpose to not generate empty location records

if key in result and result[key]:

can be replaced by

if result.get(key):

rname=r_name_type[0], rtype=r_name_type[1]
))
# add new
file.write("update add {}\n".format(val))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if update add ... is ran twice for the same record?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't happen

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the command update delete ... will remove for example all A records for a domain and that's why you're checking that it won't run twice. However, when the records are added, they should be all different (in case of A record, different IPv4). Is that correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes IPA doesn't return duplicated records


out = options.get('out') # output to file
if out:
with open(out, "w") as f:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be nice if we had try-catch block here to handle potential errors with file operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I'll use the same code as cert.py does for certificates

@tkrizek
Copy link
Contributor

tkrizek commented Feb 7, 2017

I added some in-line comments/questions.

'out?',
include='cli',
doc=_('file to store DNS records in nsupdate format')
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that this won't work, but you can use takes_options as usual here, MethodOverride will tak care of properly merging the remote and local options.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did exactly the same as was used in user.py plugin

with open(out, "w") as f:
self._nsupdate_output_file(f, result, labels)
except (OSError, IOError) as e:
raise errors.FileError(reason=unicode(e))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block should be moved to forward(), output_for_cli() is supposed to just format the result on the CLI, not write stuff to files.

@pvoborni
Copy link
Member

pvoborni commented Feb 8, 2017

I've added acceptance criteria and user story to the related FreeIPA ticket.

I miss a "how to use part" - a specific example. This should be in FreeIPA.org wiki, e.g. in design page (rest of the design page can be copied user story and empty), but the how to use section with both auth methods is a critical part.

Added option --out <path> creates a file with IPA DNS data in nsupdate
format.

https://fedorahosted.org/freeipa/ticket/6585
Get nsupdate data from dns-update-system-records, remove system records
and run nsupdate to verify that all system records were updated

https://fedorahosted.org/freeipa/ticket/6585
@MartinBasti
Copy link
Contributor Author

@pvoborni http://www.freeipa.org/page/Howto/Updating_FreeIPA_system_DNS_records_on_a_remote_DNS_server

Still WIP, but can be reviewed if format fulfill expectations.

@tkrizek
Copy link
Contributor

tkrizek commented Feb 14, 2017

Please update the ticket in trac/JIRA to mentiond the command does not support stdout. LGTM otherwise.

@tkrizek tkrizek added the ack Pull Request approved, can be merged label Feb 14, 2017
@MartinBasti MartinBasti added the pushed Pull Request has already been pushed label Feb 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ack Pull Request approved, can be merged pushed Pull Request has already been pushed
Projects
None yet
4 participants