Last active
September 28, 2015 20:14
-
-
Save coxley/f8836bd7b29bc4f21311 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Convert nsot csv to commands | |
''' | |
PATH = 'update.csv' | |
def create_net_cmd(resource): | |
'''pynsot bulk csv (colon) -> cli commands''' | |
cidr, attrs = resource.rsplit(':', 1) | |
return 'nsot networks add -c %s -a \'%s\'' % (cidr, attrs) | |
def main(): | |
'''Entrypoint''' | |
with open(PATH) as file_: | |
resources = file_.read() \ | |
.splitlines()[1:] # First line is csv header | |
commands = [create_net_cmd(i) for i in resources] | |
print '\n'.join(commands) | |
if __name__ == '__main__': | |
main() |
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cidr:attributes | |
2001::/64:desc=test | |
2001:1::/64:desc=test2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment