Skip to content

Instantly share code, notes, and snippets.

@coxley
Last active September 28, 2015 20:14
Show Gist options
  • Save coxley/f8836bd7b29bc4f21311 to your computer and use it in GitHub Desktop.
Save coxley/f8836bd7b29bc4f21311 to your computer and use it in GitHub Desktop.
'''
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.
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