Revision: 1154
Author:
jane...@gmail.com
Date: Fri Jul 26 00:36:48 2013
Log: changes to dnsmass add for issue 341
http://code.google.com/p/roster-dns-management/source/detail?r=1154
Modified:
/trunk/roster-user-tools/scripts/dnsmassadd
/trunk/test/dnsmassadd_test.py
=======================================
--- /trunk/roster-user-tools/scripts/dnsmassadd Mon Nov 19 06:24:51 2012
+++ /trunk/roster-user-tools/scripts/dnsmassadd Fri Jul 26 00:36:48 2013
@@ -29,7 +29,7 @@
usage = ('\n'
'\n'
'To add a list of hosts from a file:\n'
- '\t%s massadd -f <file-name> -v <view-name> -z <zone-name>\n'
+ '\t%s -f <file-name> -v <view-name> -z <zone-name>\n'
'\nFile example:\n'
'192.168.1.5 computer1\n'
'192.168.1.8 host3\n'
@@ -140,60 +140,45 @@
for record_ip in records[view]:
for record in iter(records[view][record_ip]):
records_to_remove.append(record)
- if( not options.commit ):
- if( options.no_commit ):
- print('Commit flag not specified. '
- 'Changes will not be made to the database.\n')
- else:
- print('Commit flag not specified. '
- 'Would you like to commit?')
- user_input = ''
- while( user_input.lower() not in ['y', 'n'] ):
- user_input = raw_input('Respond y or n: ')
- if( user_input == 'y' ):
- options.commit = True
- print("HOSTS TO BE REMOVED: ")
- zone_list = ['zone']
- print_list = [['#', 'type', 'target', 'zone', 'view']]
- count = 0
- for record in records_to_remove:
- record_list = []
- record_list.append(count)
- count += 1
- record_list.append(record['record_type'])
- record_list.append(record['record_target'])
- record_list.append(record['record_zone_name'])
- record_list.append(record['view_name'])
- print_list.append(record_list)
- print cli_common_lib.PrintColumns(
- print_list=print_list, first_line_header=True)
+ for record in records_to_remove:
+ print 'Host: %s with ip address %s will be REMOVED'% (
+ record['host'], record['record_args_dict']['assignment_ip'])
- print("\nHOSTS TO BE ADDED: ")
- zone_list = ['zone']
- print_list = [['#', 'type', 'target', 'zone', 'view']]
count = 0
+ print_list = []
for record in records_to_add:
- record_list = []
- record_list.append(count)
count += 1
- record_list.append(record['record_type'])
- record_list.append(record['record_target'])
- record_list.append(record['record_zone_name'])
- record_list.append(options.view_name)
- print_list.append(record_list)
- print cli_common_lib.PrintColumns(
- print_list=print_list, first_line_header=True)
+ if ( record['record_zone_name'] == 'forward_zone' ):
+ print_list.append(record['record_arguments']['assignment_ip'])
+ else:
+ print_list.append(record['record_arguments']['assignment_host'])
+ print 'Host: %s with ip address %s will be ADDED'% (
+ print_list [count - 1], print_list [count - 2])
- if options.commit:
+ while( not options.commit and not options.no_commit ):
+ yes_no = raw_input('Do you want to commit these changes? (y/N): ')
+ if( yes_no.lower() not in ['y', 'yes', 'n', 'no', ''] ):
+ continue
+ if( yes_no.lower() in ['n', 'no', ''] ):
+ options.no_commit = True
+ if( yes_no.lower() in ['y', 'yes'] ):
+ options.commit = True
+ if( options.no_commit ):
+ print 'No changes made.'
+ sys.exit(0)
+
+
+ if( options.commit ):
roster_client_lib.RunFunction(
"ProcessRecordsBatch", options.username, credfile=options.credfile,
server_name=options.server,
kwargs={'delete_records': records_to_remove,
'add_records': records_to_add})
- else:
- print('\nCommit flag not specified. '
- 'Changes will not be made to the database.')
+ print 'Records Committed.'
+
+ if( options.no_commit ):
+ print 'No changes made.'
if __name__ == "__main__":
main(sys.argv[1:])
=======================================
--- /trunk/test/dnsmassadd_test.py Mon Nov 19 06:24:51 2012
+++ /trunk/test/dnsmassadd_test.py Fri Jul 26 00:36:48 2013
@@ -282,25 +282,15 @@
stdout=PIPE, stdin=PIPE, stderr=STDOUT)
## Check output of replaced hosts
- self.assertEqual(command.communicate(input='n')[0],
- 'Commit flag not specified. Would you like to commit?\n'
- 'Respond y or n: HOSTS TO BE REMOVED: \n'
- '# type target zone view\n'
- '--------------------------------------\n'
- '0 ptr 5 reverse_zone test_view\n'
- '1 a host3 forward_zone test_view\n'
- '2 a www.host3 forward_zone test_view\n'
- '3 aaaa host2 foward_zone_ipv6 test_view\n\n\n'
- 'HOSTS TO BE ADDED: \n'
- '# type target
zone view\n'
- '-----------------------------------------------------------------------\n'
- '0 a computer1
forward_zone test_view\n'
- '1 ptr 5
reverse_zone test_view\n'
- '2 aaaa computer2
forward_zone test_view\n'
- '3 ptr b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1
reverse_zone_ipv6 test_view\n'
- '4 aaaa computer3
forward_zone test_view\n'
- '5 ptr c.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1
reverse_zone_ipv6 test_view\n\n\n'
- 'Commit flag not specified. Changes will not be made to the
database.\n')
+ self.assertEqual(command.communicate(input='n')[0],
+ 'Host:
host2.university.edu with ip address 192.168.1.5 will be
REMOVED\n'
+ 'Host:
host3.university.edu with ip address 192.168.1.5 will be
REMOVED\n'
+ 'Host:
www.host3.university.edu with ip address 192.168.1.5 will be
REMOVED\n'
+ 'Host:
host2.university2.edu with ip address
4321:0000:0001:0002:0003:0004:0567:89ab will be REMOVED\n'
+ 'Host:
computer1.university.edu. with ip address 192.168.1.5 will be
ADDED\n'
+ 'Host:
computer2.university.edu. with ip address
4321:0000:0001:0002:0003:0004:0567:89ab will be ADDED\n'
+ 'Host:
computer3.university.edu. with ip address
4321:0000:0001:0002:0003:0004:0567:89ac will be ADDED\n'
+ 'Do you want to commit these changes? (y/N): No changes made.\n')
## Ensure nothing got changed
self.assertEqual(
@@ -355,24 +345,16 @@
## Check output of replaced hosts
self.assertEqual(command.communicate(input='y')[0],
- 'Commit flag not specified. Would you like to commit?\n'
- 'Respond y or n: HOSTS TO BE REMOVED: \n'
- '# type target zone view\n'
- '--------------------------------------\n'
- '0 ptr 5 reverse_zone test_view\n'
- '1 a host3 forward_zone test_view\n'
- '2 a www.host3 forward_zone test_view\n'
- '3 aaaa host2 foward_zone_ipv6 test_view\n\n\n'
- 'HOSTS TO BE ADDED: \n'
- '# type target
zone view\n'
- '-----------------------------------------------------------------------\n'
- '0 a computer1
forward_zone test_view\n'
- '1 ptr 5
reverse_zone test_view\n'
- '2 aaaa computer2
forward_zone test_view\n'
- '3 ptr b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1
reverse_zone_ipv6 test_view\n'
- '4 aaaa computer3
forward_zone test_view\n'
- '5 ptr c.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1
reverse_zone_ipv6 test_view\n\n')
-
+ 'Host:
host2.university.edu with ip address 192.168.1.5 will be
REMOVED\n'
+ 'Host:
host3.university.edu with ip address 192.168.1.5 will be
REMOVED\n'
+ 'Host:
www.host3.university.edu with ip address 192.168.1.5 will
be REMOVED\n'
+ 'Host:
host2.university2.edu with ip address
4321:0000:0001:0002:0003:0004:0567:89ab will be REMOVED\n'
+ 'Host:
computer1.university.edu. with ip address 192.168.1.5 will
be ADDED\n'
+ 'Host:
computer2.university.edu. with ip address
4321:0000:0001:0002:0003:0004:0567:89ab will be ADDED\n'
+ 'Host:
computer3.university.edu. with ip address
4321:0000:0001:0002:0003:0004:0567:89ac will be ADDED\n'
+ 'Do you want to commit these changes? (y/N): '
+ 'Records Committed.\n')
+
## Check output of replaced hosts
self.assertEqual(
self.core_instance.ListRecords(view_name=u'test_view'),
@@ -487,26 +469,15 @@
self.server_name, USERNAME, PASSWORD,
USER_CONFIG)))
## Check output of replaced hosts
- self.assertEqual(command.read(), (
- 'Commit flag not specified. Changes will not be made to the
database.\n\n'
- 'HOSTS TO BE REMOVED: \n'
- '# type target zone view\n'
- '--------------------------------------\n'
- '0 ptr 5 reverse_zone test_view\n'
- '1 a host3 forward_zone test_view\n'
- '2 a www.host3 forward_zone test_view\n'
- '3 aaaa host2 foward_zone_ipv6 test_view\n\n\n'
- 'HOSTS TO BE ADDED: \n'
- '# type target
zone view\n'
- '-----------------------------------------------------------------------\n'
- '0 a computer1
forward_zone test_view\n'
- '1 ptr 5
reverse_zone test_view\n'
- '2 aaaa computer2
forward_zone test_view\n'
- '3 ptr b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1
reverse_zone_ipv6 test_view\n'
- '4 aaaa computer3
forward_zone test_view\n'
- '5 ptr c.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1
reverse_zone_ipv6 test_view\n\n\n'
- 'Commit flag not specified. Changes will not be made to the
database.\n'))
-
+ self.assertEqual(command.read(), (
+ 'Host:
host2.university.edu with ip address 192.168.1.5 will be
REMOVED\n'
+ 'Host:
host3.university.edu with ip address 192.168.1.5 will be
REMOVED\n'
+ 'Host:
www.host3.university.edu with ip address 192.168.1.5 will
be REMOVED\n'
+ 'Host:
host2.university2.edu with ip address
4321:0000:0001:0002:0003:0004:0567:89ab will be REMOVED\n'
+ 'Host:
computer1.university.edu. with ip address 192.168.1.5 will
be ADDED\n'
+ 'Host:
computer2.university.edu. with ip address
4321:0000:0001:0002:0003:0004:0567:89ab will be ADDED\n'
+ 'Host:
computer3.university.edu. with ip address
4321:0000:0001:0002:0003:0004:0567:89ac will be ADDED\n'
+ 'No changes made.\n'))
command.close()
## Ensure nothing got changed
@@ -529,7 +500,7 @@
'ttl': 3600, u'minimum_seconds': 5, 'record_type': u'soa',
'view_name': u'test_view', 'last_user': u'sharrell',
'zone_name': u'foward_zone_ipv6',
- u'admin_email': u'admin.university.edu.', u'expiry_seconds':
5},
+ u'admin_email': u'admin.university.edu.', u'expiry_seconds':
5},
{u'serial_number': 2, u'refresh_seconds': 5, 'target': u'@',
u'name_server': u'ns1.university.edu.', u'retry_seconds': 5,
'ttl': 3600, u'minimum_seconds': 5, 'record_type': u'soa',
@@ -560,22 +531,14 @@
self.server_name, USERNAME, PASSWORD,
USER_CONFIG)))
self.assertEqual(command.read(), (
- 'HOSTS TO BE REMOVED: \n'
- '# type target zone view'
- '\n--------------------------------------\n'
- '0 ptr 5 reverse_zone test_view\n'
- '1 a host3 forward_zone test_view\n'
- '2 a www.host3 forward_zone test_view\n'
- '3 aaaa host2 foward_zone_ipv6 test_view\n\n\n'
- 'HOSTS TO BE ADDED: \n'
- '# type target
zone view\n'
- '-----------------------------------------------------------------------\n'
- '0 a computer1
forward_zone test_view\n'
- '1 ptr 5
reverse_zone test_view\n'
- '2 aaaa computer2
forward_zone test_view\n'
- '3 ptr b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1
reverse_zone_ipv6 test_view\n'
- '4 aaaa computer3
forward_zone test_view\n'
- '5 ptr c.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1
reverse_zone_ipv6 test_view\n\n'))
+ 'Host:
host2.university.edu with ip address 192.168.1.5 will be
REMOVED\n'
+ 'Host:
host3.university.edu with ip address 192.168.1.5 will be
REMOVED\n'
+ 'Host:
www.host3.university.edu with ip address 192.168.1.5 will
be REMOVED\n'
+ 'Host:
host2.university2.edu with ip address
4321:0000:0001:0002:0003:0004:0567:89ab will be REMOVED\n'
+ 'Host:
computer1.university.edu. with ip address 192.168.1.5 will
be ADDED\n'
+ 'Host:
computer2.university.edu. with ip address
4321:0000:0001:0002:0003:0004:0567:89ab will be ADDED\n'
+ 'Host:
computer3.university.edu. with ip address
4321:0000:0001:0002:0003:0004:0567:89ac will be ADDED\n'
+ 'Records Committed.\n'))
command.close()
## Check output of replaced hosts
@@ -620,7 +583,7 @@
'record_type': u'ptr', 'view_name': u'test_view', 'last_user':
u'sharrell', 'zone_name': u'reverse_zone_ipv6',
u'assignment_host':
u'computer2.university.edu.'}, {'target': u'computer3', 'ttl':
3600,
- 'record_type': u'aaaa', 'view_name': u'test_view', 'last_user':
+ 'record_type': u'aaaa', 'view_name': u'test_view', 'last_user':
u'sharrell', 'zone_name': u'forward_zone', u'assignment_ip':
u'4321:0000:0001:0002:0003:0004:0567:89ac'},
{'target': u'c.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1', 'ttl':
3600,
@@ -714,25 +677,14 @@
## Check output of replaced hosts
self.assertEqual(command.read(), (
- 'Commit flag not specified. Changes will not be made to the
database.\n\n'
- 'HOSTS TO BE REMOVED: \n'
- '# type target zone view\n'
- '--------------------------------------\n'
- '0 ptr 5 reverse_zone test_view\n'
- '1 a host3 forward_zone test_view\n'
- '2 a www.host3 forward_zone test_view\n'
- '3 aaaa host2 foward_zone_ipv6 test_view\n\n\n'
- 'HOSTS TO BE ADDED: \n'
- '# type target
zone view\n'
- '-----------------------------------------------------------------------\n'
- '0 a computer1
forward_zone any\n'
- '1 ptr 5
reverse_zone any\n'
- '2 aaaa computer2
forward_zone any\n'
- '3 ptr b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1
reverse_zone_ipv6 any\n'
- '4 aaaa computer3
forward_zone any\n'
- '5 ptr c.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1
reverse_zone_ipv6 any\n\n\n'
- 'Commit flag not specified. Changes will not be made to the
database.\n'))
-
+ 'Host:
host2.university.edu with ip address 192.168.1.5 will be
REMOVED\n'
+ 'Host:
host3.university.edu with ip address 192.168.1.5 will be
REMOVED\n'
+ 'Host:
www.host3.university.edu with ip address 192.168.1.5 will
be REMOVED\n'
+ 'Host:
host2.university2.edu with ip address
4321:0000:0001:0002:0003:0004:0567:89ab will be REMOVED\n'
+ 'Host:
computer1.university.edu. with ip address 192.168.1.5 will
be ADDED\n'
+ 'Host:
computer2.university.edu. with ip address
4321:0000:0001:0002:0003:0004:0567:89ab will be ADDED\n'
+ 'Host:
computer3.university.edu. with ip address
4321:0000:0001:0002:0003:0004:0567:89ac will be ADDED\n'
+ 'No changes made.\n'))
command.close()
## Ensure nothing got changed
@@ -746,22 +698,14 @@
self.server_name, USERNAME, PASSWORD,
USER_CONFIG)))
self.assertEqual(command.read(),
- 'HOSTS TO BE REMOVED: \n'
- '# type target zone view\n'
- '--------------------------------------\n'
- '0 ptr 5 reverse_zone test_view\n'
- '1 a host3 forward_zone test_view\n'
- '2 a www.host3 forward_zone test_view\n'
- '3 aaaa host2 foward_zone_ipv6 test_view\n\n\n'
- 'HOSTS TO BE ADDED: \n'
- '# type target
zone view\n'
- '-----------------------------------------------------------------------\n'
- '0 a computer1
forward_zone any\n'
- '1 ptr 5
reverse_zone any\n'
- '2 aaaa computer2
forward_zone any\n'
- '3 ptr b.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1
reverse_zone_ipv6 any\n'
- '4 aaaa computer3
forward_zone any\n'
- '5 ptr c.a.9.8.7.6.5.0.4.0.0.0.3.0.0.0.2.0.0.0.1
reverse_zone_ipv6 any\n\n')
+ 'Host:
host2.university.edu with ip address 192.168.1.5 will be
REMOVED\n'
+ 'Host:
host3.university.edu with ip address 192.168.1.5 will be
REMOVED\n'
+ 'Host:
www.host3.university.edu with ip address 192.168.1.5 will
be REMOVED\n'
+ 'Host:
host2.university2.edu with ip address
4321:0000:0001:0002:0003:0004:0567:89ab will be REMOVED\n'
+ 'Host:
computer1.university.edu. with ip address 192.168.1.5 will
be ADDED\n'
+ 'Host:
computer2.university.edu. with ip address
4321:0000:0001:0002:0003:0004:0567:89ab will be ADDED\n'
+ 'Host:
computer3.university.edu. with ip address
4321:0000:0001:0002:0003:0004:0567:89ac will be ADDED\n'
+ 'Records Committed.\n')
command.close()
## Check output of replaced hosts