Skip to content

Commit 675ffde

Browse files
Add files via upload
1 parent 7ae5eea commit 675ffde

File tree

5 files changed

+556
-0
lines changed

5 files changed

+556
-0
lines changed

Fortimanager_2/Cutover.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
gw_subnet=(data.vlan_list[x]["gw_subnet"])
15+
current_phy_interface=(data.vlan_list[x]["current_phy_interface"])
16+
current_vlan_interface = (data.vlan_list[x]["current_vlan_interface"])
17+
print ("")
18+
print("Logging into Fortimanager Controller:{}".format(host))
19+
print("Configure the FW :{}".format(device_name))
20+
print("Disable the old interface :{} on Subnet {}".format(current_vlan_interface,gw_subnet))
21+
ACTION = input("Are you sure you want to push the configuration (y/n): ")
22+
if ACTION in ("y","yes","Y","YES"):
23+
FM=FortiManager(usr, pwd, host)
24+
print("Calling the Master function -> Authenticating into the FM Controller")
25+
t0=FM.login()
26+
t1=FM.cutover_vlan_interface(device_name, vdom_name,current_vlan_interface,current_phy_interface)
27+
t8=FM.quick_install_device(adom, device_name,current_vlan_interface) ### Push the configuration from Fortimanager to Fortigate Firewall.
28+
t10=FM.logout()
29+
elif ACTION in ("n","no","N","No"):
30+
print("Ending the script")
31+
else:
32+
print("Please enter yes or no.")
33+
except IndexError:
34+
print("Oops! Out of the vlan migration range. please check and Try again...")
35+
36+
if __name__ == '__main__':
37+
main()

Fortimanager_2/FMPrework.py

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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_network=(data.vlan_list[x]["gw_network"])
17+
gw_mask=(data.vlan_list[x]["gw_mask"])
18+
l3out_phy_interface=(data.vlan_list[x]["l3out_phy_interface"])
19+
l3out_ipadd=(data.vlan_list[x]["l3out_ipadd"])
20+
aci_l3out_nexthop=(data.vlan_list[x]["aci_l3out_nexthop"])
21+
l3out_rm_name=(data.vlan_list[x]["l3out_rm_name"])
22+
l3out_nh_interface=l3out_int_name
23+
l3out_vlan_name=l3out_int_name+"_L3out"
24+
distance = "10"
25+
prefix ="prefix"
26+
zone_name= l3out_int_name+"_Zone"
27+
access_list = "rof_adv_list"
28+
#Network = "192.168.6.0"
29+
#SubnetMask = "255.255.255.0"
30+
gw_subnet = gw_network +"/"+ gw_mask
31+
config_block="router/access-list" #"system/zone" or "router/ospf" or "router/static" or "router/access-list" or "router/route-map"
32+
interface_block="global/system/interface"
33+
print ("")
34+
print("Logging into Fortimanager Controller:{}".format(host))
35+
print("Configure the FW :{}".format(device_name))
36+
print("Configure the new L3out interface :{}".format(l3out_int_name))
37+
print("Associate the new L3out int. into member of :{}".format(zone_name))
38+
print("Configure the .1Q Sub-interface vlan for L3out #:{}".format(vlan_id))
39+
print("Configure the Physical interface for new L3out:{}".format(l3out_phy_interface))
40+
print("Configure the Next-hop IP address ACI :{}".format(aci_l3out_nexthop))
41+
print("Configure the GW_subnet Next-hop to ACI :{}".format(gw_subnet))
42+
print("Configure the IP address on L3out interface:{}".format(l3out_ipadd))
43+
print("Configure the Route-map {} on FW:{}".format(l3out_rm_name,device_name))
44+
print("Configure the Access-list {} on the FW:{}".format(access_list,device_name))
45+
46+
47+
ACTION = input("Are you sure you want to push the configuration (y/n): ")
48+
if ACTION in ("y","yes","Y","YES"):
49+
FM=FortiManager(usr, pwd, host)
50+
print("Calling the Master function -> Authenticating into the FM Controller")
51+
t0=FM.login()
52+
#t1=FM.add_vlan_interface(device_name, l3out_vlan_name, vdom_name, l3out_ipadd,vlan_id,l3out_phy_interface)
53+
#t2=FM.add_zone_interface(device_name, zone_name, l3out_vlan_name)
54+
#t3=FM.add_static_route(device_name, l3out_vlan_name, gw_subnet, distance, aci_l3out_nexthop)
55+
t7=FM.get_config_block(device_name,scope, "router/access-list")
56+
#print(t7)
57+
res=t7
58+
#print(res)
59+
curr_data = res["result"][0]["data"][0]["rule"]
60+
curr_data1 = res["result"][0]["data"][0]
61+
acl_rule=curr_data1["rule"]
62+
acl_name=curr_data1["name"]
63+
acl_prefix=curr_data[0]["prefix"]
64+
#print(acl_rule)
65+
#print(acl_name)
66+
print(acl_prefix[0])
67+
print(acl_prefix[1])
68+
if None == acl_rule and acl_name == access_list:
69+
print("ACL Entries not exist.")
70+
t4= FM.add_access_list(device_name, gw_subnet, access_list)
71+
elif acl_prefix[0]==gw_network and acl_prefix[1]==gw_mask:
72+
print("ACL entire already exist")
73+
else:
74+
print("Append the new entire in the access-list")
75+
t8=FM.append_access_list(device_name, gw_subnet, t7,access_list)
76+
#if gw_subnet not in acl:
77+
# print("Appending the new prefixes into the existing access-list")
78+
# t8=FM.append_access_list(device_name, gw_subnet, t7,access_list)
79+
# break
80+
81+
#t5= FM.add_acl_to_rm(device_name, l3out_rm_name, access_list)
82+
#t6=FM.add_rm_to_ospf(device_name, l3out_rm_name)
83+
#t7=FM.get_config_block(device_name,scope, config_block)
84+
#t8=FM.append_access_list(device_name, gw_subnet, t7,access_list)
85+
#t8=FM.get_interface_block(device_name, interface_block)
86+
#t8=FM.quick_install_device(adom, device_name,l3out_vlan_name) ### Push the configuration from Fortimanager to Fortigate Firewall.
87+
t10=FM.logout()
88+
elif ACTION in ("n","no","N","No"):
89+
print("Ending the script")
90+
else:
91+
print("Please enter yes or no.")
92+
except IndexError:
93+
print("Oops! Out of the vlan migration range. please check and Try again...")
94+
95+
if __name__ == '__main__':
96+
main()

0 commit comments

Comments
 (0)