Skip to content

Commit 3d2aef8

Browse files
committed
Clean and add more examples scripts using the API
MAinly to show the payload source.
1 parent 7375b9a commit 3d2aef8

8 files changed

+172
-8
lines changed

.idea/markdown-navigator.xml

+72
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/markdown-navigator/profiles_settings.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/preferred-vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Compare to the REST API there a few add-ons:
66
In addition to get,put,post,delete methods there is a set which will
77
try to post and if failing will put and collect the mkey directly.
88

9-
## Muli vdom
9+
## Multi vdom
1010
In multi vdom environment use vdom=global in the API call.
1111
As it is a reserved word the API will switch to use the global=1 and
1212
take care of the differences in the repsonses.

examples/firewallpolicy.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!env python
2+
#License upload using FORTIOSAPI from Github
3+
4+
import sys
5+
from fortiosapi import FortiOSAPI
6+
import json
7+
8+
def main():
9+
10+
# Parse for command line argument for fgt ip
11+
if len(sys.argv) < 2:
12+
# Requires fgt ip and vdom
13+
print "Please specify fgt ip address"
14+
exit()
15+
16+
# Initilize fgt connection
17+
ip = sys.argv[1]
18+
#fgt = FGT(ip)
19+
20+
# Hard coded vdom value for all requests
21+
vdom = "root"
22+
23+
# Login to the FGT ip
24+
25+
fgt = FortiOSAPI()
26+
27+
fgt.login(ip,'admin','')
28+
parameters = { 'global':'1' }
29+
upload_data={'source':'upload',
30+
'scope':'global'}
31+
files={'file': ('license',open("license.lic", 'r'), 'text/plain')}
32+
33+
fgt.upload('system/vmlicense','upload',
34+
data=upload_data,
35+
parameters=parameters,
36+
files=files)
37+
38+
39+
fgt.logout()
40+
41+
if __name__ == '__main__':
42+
main()

testlogin.py examples/testlogin.py

File renamed without changes.

examples/upload-license.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python
2+
#License upload using FORTIOSAPI from Github
3+
4+
import sys
5+
from fortiosapi import FortiOSAPI
6+
import json
7+
8+
def main():
9+
10+
# Parse for command line argument for fgt ip
11+
if len(sys.argv) < 2:
12+
# Requires fgt ip and vdom
13+
print "Please specify fgt ip address"
14+
exit()
15+
16+
# Initilize fgt connection
17+
ip = sys.argv[1]
18+
#fgt = FGT(ip)
19+
20+
# Hard coded vdom value for all requests
21+
vdom = "root"
22+
23+
# Login to the FGT ip
24+
25+
fgt = FortiOSAPI()
26+
27+
fgt.login(ip,'admin','')
28+
parameters = { 'global':'1' }
29+
upload_data={'source':'upload',
30+
'scope':'global'}
31+
files={'file': ('license',open("license.lic", 'r'), 'text/plain')}
32+
33+
fgt.upload('system/vmlicense','upload',
34+
data=upload_data,
35+
parameters=parameters,
36+
files=files)
37+
38+
39+
fgt.logout()
40+
41+
if __name__ == '__main__':
42+
main()

fortiosapi/fortiosapi.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,21 @@
2525
#
2626
###################################################################
2727

28-
import time
29-
import paramiko
30-
import subprocess
31-
import requests
32-
from collections import namedtuple
3328
import json
34-
import pprint
3529
# Set default logging handler to avoid "No handler found" warnings.
3630
import logging
31+
import subprocess
32+
import time
33+
34+
import paramiko
35+
import requests
36+
3737
try: # Python 2.7+
3838
from logging import NullHandler
3939
except ImportError:
4040
class NullHandler(logging.Handler):
4141
def emit(self, record):
4242
pass
43-
from argparse import Namespace
4443
# Disable warnings about certificates.
4544
from requests.packages.urllib3.exceptions import InsecureRequestWarning
4645
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

0 commit comments

Comments
 (0)