1+ def main ():
2+ from Fortimanager_Master import FortiManager
3+ import fwinput_cfg as data
4+ host = "https://172.19.255.53/jsonrpc"
5+ usr = "fortiapi"
6+ pwd = "fortiapi"
7+ i = input ("Enter the no.of vlan's you want to Migration:" )
8+ for x in range (int (i )):
9+ try :
10+ device_name = (data .vlan_list [x ]["device_name" ])
11+ scope = (data .vlan_list [x ]["scope" ])
12+ adom = (data .vlan_list [x ]["adom" ])
13+ vdom_name = (data .vlan_list [x ]["vdom_name" ])
14+ l3out_int_name = (data .vlan_list [x ]["l3out_int_name" ])
15+ vlan_id = (data .vlan_list [x ]["vlan_id" ])
16+ gw_subnet = (data .vlan_list [x ]["gw_subnet" ])
17+ vlan_phy_interface = (data .vlan_list [x ]["vlan_phy_interface" ])
18+ l3out_ipadd = (data .vlan_list [x ]["l3out_ipadd" ])
19+ aci_l3out_nexthop = (data .vlan_list [x ]["aci_l3out_nexthop" ])
20+ l3out_rm_name = (data .vlan_list [x ]["l3out_rm_name" ])
21+ l3out_nh_interface = l3out_int_name
22+ l3out_vlan_name = l3out_int_name + "_L3out"
23+ advertise_subnet = gw_subnet
24+ distance = "10"
25+ zone_name = l3out_int_name + "_Zone"
26+ advertise_subnet = gw_subnet
27+ access_list = "rof_adv_list"
28+ config_block = "router/access-list" #"system/zone" or "router/ospf" or "router/static" or "router/access-list" or "router/route-map"
29+ interface_block = "global/system/interface"
30+ print ("" )
31+ print ("Logging into Fortimanager Controller:{}" .format (host ))
32+ print ("Configure the FW :{}" .format (device_name ))
33+ print ("Configure the new L3out interface :{}" .format (l3out_int_name ))
34+ print ("Associate the new L3out int. into memeber of :{}" .format (zone_name ))
35+ print ("Configure the .1Q Sub-interface vlan for L3out #:{}" .format (vlan_id ))
36+ print ("Configure the Physical interface for new L3out:{}" .format (vlan_phy_interface ))
37+ print ("Configure the Next-hop IP address ACI :{}" .format (aci_l3out_nexthop ))
38+ print ("Configure the IP address on L3out interface:{}" .format (l3out_ipadd ))
39+ print ("Configure the Route-map {} on FW:{}" .format (l3out_rm_name ,device_name ))
40+ print ("Configure the Access-list {} on the FW:{}" .format (access_list ,device_name ))
41+
42+
43+ ACTION = input ("Are you sure you want to push the configuration (y/n): " )
44+ if ACTION in ("y" ,"yes" ,"Y" ,"YES" ):
45+ FM = FortiManager (usr , pwd , host )
46+ print ("Calling the Master function -> Authenticating into the FM Controller" )
47+ t0 = FM .login ()
48+ t1 = FM .add_vlan_interface (device_name , l3out_vlan_name , vdom_name , l3out_ipadd ,vlan_id ,vlan_phy_interface )
49+ t2 = FM .add_zone_interface (device_name , zone_name , l3out_vlan_name )
50+ t3 = FM .add_static_route (device_name , l3out_vlan_name , gw_subnet , distance , aci_l3out_nexthop )
51+ t4 = FM .add_access_list (device_name , advertise_subnet , access_list )
52+ t5 = FM .add_acl_to_rm (device_name , l3out_rm_name , access_list )
53+ t6 = FM .add_rm_to_ospf (device_name , l3out_rm_name )
54+ #t7=FM.get_config_block(device_name,scope, config_block)
55+ t8 = FM .get_interface_block (device_name , interface_block )
56+ t8 = FM .quick_install_device (adom , device_name ,l3out_vlan_name ) ### Push the configuration from Fortimanager to Fortigate Firewall.
57+ t10 = FM .logout ()
58+ elif ACTION in ("n" ,"no" ,"N" ,"No" ):
59+ print ("Ending the script" )
60+ else :
61+ print ("Please enter yes or no." )
62+ except IndexError :
63+ print ("Oops! Out of the vlan migration range. please check and Try again..." )
64+
65+ if __name__ == '__main__' :
66+ main ()
0 commit comments