Transfer Zones to GTM
Problem this snippet solves:
This pyControl v2 script will transfer Zones to a GTM.
How to use this snippet:
Syntax/Usage
This pyControl v2 script will transfer Zones to a GTM.
Usage: Transfer-Zones.py
Script
Transfer-Zones.py
Code :
#!/bin/env python ''' ---------------------------------------------------------------------------- The contents of this file are subject to the "END USER LICENSE AGREEMENT FOR F5 Software Development Kit for iControl"; you may not use this file except in compliance with the License. The License is included in the iControl Software Development Kit. Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is iControl Code and related documentation distributed by F5. The Initial Developer of the Original Code is F5 Networks, Inc. Seattle, WA, USA. Portions created by F5 are Copyright (C) 1996-2004 F5 Networks, Inc. All Rights Reserved. iControl (TM) is a registered trademark of F5 Networks, Inc. Alternatively, the contents of this file may be used under the terms of the GNU General Public License (the "GPL"), in which case the provisions of GPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of the GPL and not to allow others to use your version of this file under the License, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under either the License or the GPL. ---------------------------------------------------------------------------- ''' import sys import pycontrol.pycontrol as pc import time ####################################################################################### # Example of how to transfer zones from pycontrol v.2. This example passes in # the 'fromurl' keyword as True (default is False), which tells pycontrol # to fetch the WSDL from the remote BigIP. # For more information: # https://devcentral.f5.com/s/wiki/iControl.Management__Zone__transfer_zone.ashx ####################################################################################### if pc.__version__.startswith('2.0'): pass else: print "Requires pycontrol version 2.x!" sys.exit() if len(sys.argv) < 4: print "Usage %s ip_address username password" % sys.argv[0] sys.exit() a = sys.argv[1:] b = pc.BIGIP( hostname = a[0], username = a[1], password = a[2], fromurl = True, wsdls = ['Management.Zone']) # Setup a shortcut z = b.Management.Zone # Variables for USER to fill in dns_server = "10.70.65.1" view = "external" src_zone_names = [ "f5lab1.com.", "f5lab2.com." ] # transfer_zone() function takes four params: # # transfer_zone( # in String [] server_names, # in String [] src_zone_names, # in String [] dst_view_names, # in Management__ZoneInfo [] zone_records # ); # You pass arrays in iControl to do things in batch # so even though you may be grabbing all zones from one server, # you need to repeat that same server for every zone # ex. # src_zone_names = ["f5lab1.com.", "f5lab2.com.", "f5lab3.com." ] # server_names = ["10.70.65.1", "10.70.65.1", "10.70.65.1" ] # # so will assume # 1) transfering from one dns server # 2) Zones will end up as type Master # 3) Zones will be named same as zone name with "db." + view prepended similar to BIGIP Defaults # and just auto-populate the arrays # # obviously make sure you have the BIGIP Self IP in "allow-transfer {10.70.11.1;};" options of originating zone. #Master Lists to pack things in so can make batch calls: src_zone_names_array = src_zone_names server_names_array = [] dst_view_names_array = [] zone_records_array = [] #Autopopulate other arrays using src_zone_names info for zone_name in src_zone_names_array: #1st Param server_names_array.append(dns_server) #3rd Param dst_view_names_array.append(view) #Set up ZoneInfo [] object which you feed to zone_records array zone_info_obj = z.typefactory.create('Management.ZoneInfo') zone_info_obj.view_name = view zone_info_obj.zone_name = zone_name #Again, making an Assumption here on what type of Zone zone_type = z.typefactory.create('Management.ZoneType') zone_info_obj.zone_type = zone_type.MASTER zone_info_obj.zone_file = "db." + view + "." + zone_name zone_info_obj.option_seq = [ "allow-update { localhost; };" ] #4th param zone_records_array.append(zone_info_obj) print "Transferring Zones...." try: z.transfer_zone( server_names = server_names_array, src_zone_names = src_zone_names_array, dst_view_names = dst_view_names_array, zone_records = zone_records_array ) except Exception, e: print "Error transferring Zones %s" % src_zone_names print e print "Retrieving Current Zones:\n" zone_names_output = [] try: zone_names_output = z.get_zone_name( view_names = [ view ] ) except Exception, e: print "Error transferring Zones %s" % view print e for zone_name in zone_names_output: print " " + zone_name.zone_name
Published Mar 09, 2015
Version 1.0Alex__Applebaum
Employee
Joined June 12, 2006
Alex__Applebaum
Employee
Joined June 12, 2006
No CommentsBe the first to comment