Merge pull request #16 from dbarrosop/FortiOSDriver

Added fortigate support
This commit is contained in:
David Barroso committed 2015-04-24 14:27:28 +02:00
commit 70041a0328
9 files changed
+10986

No files matched your search

+99
View File
@@ -0,0 +1,99 @@
# Copyright 2015 Spotify AB. All rights reserved.
#
# The contents of this file are licensed under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
from pyFG.fortios import FortiOS, FortiConfig
from pyFG.exceptions import FailedCommit, CommandExecutionException
from base import NetworkDriver
from exceptions import ReplaceConfigException, MergeConfigException
class FortiOSDriver(NetworkDriver):
def __init__(self, hostname, username, password):
self.hostname = hostname
self.username = username
self.password = password
self.device = FortiOS(hostname, username=username, password=password)
self.config_replace = False
def open(self):
self.device.open()
def close(self):
self.device.close()
def _load_config(self, filename, config):
if filename is None:
configuration = config
else:
with open(filename) as f:
configuration = f.read()
self.device.load_config(in_candidate=True, config_text=configuration)
def load_replace_candidate(self, filename=None, config=None):
self.config_replace = True
self.device.candidate_config = FortiConfig('candidate')
self.device.running_config = FortiConfig('running')
self._load_config(filename, config)
self.device.load_config(empty_candidate=True)
def load_merge_candidate(self, filename=None, config=None):
self.config_replace = False
self.device.candidate_config = FortiConfig('candidate')
self.device.running_config = FortiConfig('running')
self._load_config(filename, config)
for block in self.device.candidate_config.get_block_names():
try:
self.device.load_config(path=block, empty_candidate=True)
except CommandExecutionException as e:
raise MergeConfigException(e.message)
def compare_config(self):
return self.device.compare_config()
def commit_config(self):
try:
self.device.execute_command('execute backup config flash commit_with_napalm')
self.device.commit()
self.discard_config()
except FailedCommit as e:
if self.config_replace:
raise ReplaceConfigException(e.message)
else:
raise MergeConfigException(e.message)
def discard_config(self):
self.device.candidate_config = FortiConfig('candidate')
self.device.load_config(in_candidate=True)
def rollback(self):
output = self.device.execute_command('fnsysctl ls -l data2/config')
rollback_file = output[-2].split()[-1]
rollback_config = self.device.execute_command('fnsysctl cat data2/config/%s' % rollback_file)
self.device.load_config(empty_candidate=True)
self.load_replace_candidate(config=rollback_config)
self.device.candidate_config['vpn certificate local']['Fortinet_CA_SSLProxy'].del_param('private-key')
self.device.candidate_config['vpn certificate local']['Fortinet_CA_SSLProxy'].del_param('certificate')
self.device.candidate_config['vpn certificate local']['Fortinet_SSLProxy'].del_param('private-key')
self.device.candidate_config['vpn certificate local']['Fortinet_SSLProxy'].del_param('certificate')
self.device.commit()
+31
View File
@@ -0,0 +1,31 @@
# Copyright 2015 Spotify AB. All rights reserved.
#
# The contents of this file are licensed under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
import unittest
from napalm.fortios import FortiOSDriver
from base import TestNetworkDriver
class TestFortiOSDriver(unittest.TestCase, TestNetworkDriver):
@classmethod
def setUpClass(cls):
hostname = '192.168.76.13'
username = 'dbarroso'
password = 'this_is_not_a_secure_password'
cls.vendor = 'fortios'
cls.device = FortiOSDriver(hostname, username, password)
cls.device.open()
File diff suppressed because it is too large. Load diff
+170
View File
@@ -0,0 +1,170 @@
config firewall address
edit "SSLVPN_TUNNEL_ADDR1"
set uuid 14ab4b18-d0bc-51e4-42cc-e6268d0c3020
set type iprange
set start-ip 10.212.134.200
set end-ip 10.212.134.210
next
edit "all"
set uuid 14ab6396-d0bc-51e4-303f-a22a56b1b1f0
next
edit "apple"
set uuid 14ab6c9c-d0bc-51e4-ab3c-b4a5ebc7b3d8
set type fqdn
set fqdn "*.apple.com"
next
edit "dropbox.com"
set uuid 14ab7106-d0bc-51e4-bee2-22d724c1149e
set type fqdn
set fqdn "*.dropbox.com"
next
edit "Gotomeeting"
set uuid 14ab7534-d0bc-51e4-8b80-57efd48d6a1d
set type fqdn
set fqdn "*.gotomeeting.com"
next
edit "icloud"
set uuid 14ab7962-d0bc-51e4-7b12-f830ed19cebc
set type fqdn
set fqdn "*.icloud.com"
next
edit "itunes"
set uuid 14ab7d7c-d0bc-51e4-9a5a-1cdc1e3aa425
set type fqdn
set fqdn "*itunes.apple.com"
next
edit "android"
set uuid 14ab82f4-d0bc-51e4-2ea7-fd6a490020c7
set type fqdn
set fqdn "*.android.com"
next
edit "skype"
set uuid 14ab87fe-d0bc-51e4-1463-3fedbf794ba4
set type fqdn
set fqdn "*.messenger.live.com"
next
edit "swscan.apple.com"
set uuid 14ab8c22-d0bc-51e4-3aa5-092d2aa70543
set type fqdn
set fqdn "swscan.apple.com"
next
edit "update.microsoft.com"
set uuid 14ab9046-d0bc-51e4-502b-34f428147fcc
set type fqdn
set fqdn "update.microsoft.com"
next
edit "appstore"
set uuid 14ab9460-d0bc-51e4-fde5-6bfec2054e7c
set type fqdn
set fqdn "*.appstore.com"
next
edit "eease"
set uuid 14ab987a-d0bc-51e4-6475-044176a9c484
set type fqdn
set fqdn "*.eease.com"
next
edit "google-drive"
set uuid 14ab9c94-d0bc-51e4-bd96-c87043788769
set type fqdn
set fqdn "*drive.google.com"
next
edit "google-play"
set uuid 14aba0a4-d0bc-51e4-df4f-815e9e59002b
set type fqdn
set fqdn "play.google.com"
next
edit "google-play2"
set uuid 14aba4be-d0bc-51e4-334e-19dfeed1da37
set type fqdn
set fqdn "*.ggpht.com"
next
edit "google-play3"
set uuid 14aba8ce-d0bc-51e4-a44d-e52c963127e9
set type fqdn
set fqdn "*.books.google.com"
next
edit "microsoft"
set uuid 14abace8-d0bc-51e4-861c-53e4c6f97f2c
set type fqdn
set fqdn "*.microsoft.com"
next
edit "adobe"
set uuid 14abb0f8-d0bc-51e4-8f52-5828ef1739f0
set type fqdn
set fqdn "*.adobe.com"
next
edit "Adobe Login"
set uuid 14abb508-d0bc-51e4-6d68-0d16caaa6a50
set type fqdn
set fqdn "*.adobelogin.com"
next
edit "fortinet"
set uuid 14abb918-d0bc-51e4-6ddf-088ff0d0d63a
set type fqdn
set fqdn "*.fortinet.com"
next
edit "googleapis.com"
set uuid 14abbd32-d0bc-51e4-ef13-99e9aca25675
set type fqdn
set fqdn "*.googleapis.com"
next
edit "citrix"
set uuid 14abc142-d0bc-51e4-24b7-2bf9195c781f
set type fqdn
set fqdn "*.citrixonline.com"
next
edit "verisign"
set uuid 14abc552-d0bc-51e4-34bd-d27697a15f0d
set type fqdn
set fqdn "*.verisign.com"
next
edit "Windows update 2"
set uuid 14abc96c-d0bc-51e4-20ec-bb9ccb34d43e
set type fqdn
set fqdn "*.windowsupdate.com"
next
edit "*.live.com"
set uuid 14abcd86-d0bc-51e4-b673-5442c5b749e3
set type fqdn
set fqdn "*.live.com"
next
edit "auth.gfx.ms"
set uuid 14abd196-d0bc-51e4-7db4-42298470181d
set type fqdn
set fqdn "auth.gfx.ms"
next
edit "autoupdate.opera.com"
set uuid 14abd5b0-d0bc-51e4-e312-925574ac450a
set type fqdn
set fqdn "autoupdate.opera.com"
next
edit "softwareupdate.vmware.com"
set uuid 14abd9ca-d0bc-51e4-c4f3-4523961ea3ef
set type fqdn
set fqdn "softwareupdate.vmware.com"
next
edit "firefox update server"
set uuid 14abdde4-d0bc-51e4-5f31-012b6025ebe4
set type fqdn
set fqdn "aus*.mozilla.org"
next
edit "host2"
set uuid a77e1942-db8f-51e4-6305-65ac867a3d30
set subnet 1.1.1.3 255.255.255.255
next
edit "host3"
set uuid a77e1dfc-db8f-51e4-a149-0c3b3701c0e3
set subnet 1.1.1.3 255.255.255.255
next
edit "host4"
set subnet 1.1.1.4 255.255.255.255
next
edit "host5"
set subnet 1.1.1.5 255.255.255.255
next
end
config firewall addrgrp
edit "hosts"
set member "host2" "host3" "host4" "host5"
next
end
+15
View File
@@ -0,0 +1,15 @@
config firewall address
delete host4
delete host5
edit none
set subnet 0.0.0.0 255.255.255.255
next
edit host1
set subnet 1.1.1.1 255.255.255.255
next
end
config firewall addrgrp
edit hosts
set member "host2" "host3" "host1"
next
end
+170
View File
@@ -0,0 +1,170 @@
config firewl address
edit "SSLVPN_TUNNEL_ADDR1"
set uuid 14ab4b18-d0bc-51e4-42cc-e6268d0c3020
set type iprange
set start-ip 10.212.134.200
set end-ip 10.212.134.210
next
edit "all"
set uuid 14ab6396-d0bc-51e4-303f-a22a56b1b1f0
next
edit "apple"
set uuid 14ab6c9c-d0bc-51e4-ab3c-b4a5ebc7b3d8
set type fqdn
set fqdn "*.apple.com"
next
edit "dropbox.com"
set uuid 14ab7106-d0bc-51e4-bee2-22d724c1149e
set type fqdn
set fqdn "*.dropbox.com"
next
edit "Gotomeeting"
set uuid 14ab7534-d0bc-51e4-8b80-57efd48d6a1d
set type fqdn
set fqdn "*.gotomeeting.com"
next
edit "icloud"
set uuid 14ab7962-d0bc-51e4-7b12-f830ed19cebc
set type fqdn
set fqdn "*.icloud.com"
next
edit "itunes"
set uuid 14ab7d7c-d0bc-51e4-9a5a-1cdc1e3aa425
set type fqdn
set fqdn "*itunes.apple.com"
next
edit "android"
set uuid 14ab82f4-d0bc-51e4-2ea7-fd6a490020c7
set type fqdn
set fqdn "*.android.com"
next
edit "skype"
set uuid 14ab87fe-d0bc-51e4-1463-3fedbf794ba4
set type fqdn
set fqdn "*.messenger.live.com"
next
edit "swscan.apple.com"
set uuid 14ab8c22-d0bc-51e4-3aa5-092d2aa70543
set type fqdn
set fqdn "swscan.apple.com"
next
edit "update.microsoft.com"
set uuid 14ab9046-d0bc-51e4-502b-34f428147fcc
set type fqdn
set fqdn "update.microsoft.com"
next
edit "appstore"
set uuid 14ab9460-d0bc-51e4-fde5-6bfec2054e7c
set type fqdn
set fqdn "*.appstore.com"
next
edit "eease"
set uuid 14ab987a-d0bc-51e4-6475-044176a9c484
set type fqdn
set fqdn "*.eease.com"
next
edit "google-drive"
set uuid 14ab9c94-d0bc-51e4-bd96-c87043788769
set type fqdn
set fqdn "*drive.google.com"
next
edit "google-play"
set uuid 14aba0a4-d0bc-51e4-df4f-815e9e59002b
set type fqdn
set fqdn "play.google.com"
next
edit "google-play2"
set uuid 14aba4be-d0bc-51e4-334e-19dfeed1da37
set type fqdn
set fqdn "*.ggpht.com"
next
edit "google-play3"
set uuid 14aba8ce-d0bc-51e4-a44d-e52c963127e9
set type fqdn
set fqdn "*.books.google.com"
next
edit "microsoft"
set uuid 14abace8-d0bc-51e4-861c-53e4c6f97f2c
set type fqdn
set fqdn "*.microsoft.com"
next
edit "adobe"
set uuid 14abb0f8-d0bc-51e4-8f52-5828ef1739f0
set type fqdn
set fqdn "*.adobe.com"
next
edit "Adobe Login"
set uuid 14abb508-d0bc-51e4-6d68-0d16caaa6a50
set type fqdn
set fqdn "*.adobelogin.com"
next
edit "fortinet"
set uuid 14abb918-d0bc-51e4-6ddf-088ff0d0d63a
set type fqdn
set fqdn "*.fortinet.com"
next
edit "googleapis.com"
set uuid 14abbd32-d0bc-51e4-ef13-99e9aca25675
set type fqdn
set fqdn "*.googleapis.com"
next
edit "citrix"
set uuid 14abc142-d0bc-51e4-24b7-2bf9195c781f
set type fqdn
set fqdn "*.citrixonline.com"
next
edit "verisign"
set uuid 14abc552-d0bc-51e4-34bd-d27697a15f0d
set type fqdn
set fqdn "*.verisign.com"
next
edit "Windows update 2"
set uuid 14abc96c-d0bc-51e4-20ec-bb9ccb34d43e
set type fqdn
set fqdn "*.windowsupdate.com"
next
edit "*.live.com"
set uuid 14abcd86-d0bc-51e4-b673-5442c5b749e3
set type fqdn
set fqdn "*.live.com"
next
edit "auth.gfx.ms"
set uuid 14abd196-d0bc-51e4-7db4-42298470181d
set type fqdn
set fqdn "auth.gfx.ms"
next
edit "autoupdate.opera.com"
set uuid 14abd5b0-d0bc-51e4-e312-925574ac450a
set type fqdn
set fqdn "autoupdate.opera.com"
next
edit "softwareupdate.vmware.com"
set uuid 14abd9ca-d0bc-51e4-c4f3-4523961ea3ef
set type fqdn
set fqdn "softwareupdate.vmware.com"
next
edit "firefox update server"
set uuid 14abdde4-d0bc-51e4-5f31-012b6025ebe4
set type fqdn
set fqdn "aus*.mozilla.org"
next
edit "host2"
set uuid a77e1942-db8f-51e4-6305-65ac867a3d30
set subnet 1.1.1.3 255.255.255.255
next
edit "host3"
set uuid a77e1dfc-db8f-51e4-a149-0c3b3701c0e3
set subnet 1.1.1.3 255.255.255.255
next
edit "host4"
set subnet 1.1.1.4 255.255.255.255
next
edit "host5"
set subnet 1.1.1.5 255.255.255.255
next
end
config firewall addrgrp
edit "hosts"
set member "host2" "host3" "host4" "host5"
next
end
File diff suppressed because it is too large. Load diff
+11
View File
@@ -0,0 +1,11 @@
config firewall address
delete host1
delete host2
delete host3
end
config firewall addrgrp
delete hosts
end
config firewall policy
delete 1
end
File diff suppressed because it is too large. Load diff