forked from skanner909/PAN-AF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade.py
64 lines (57 loc) · 1.85 KB
/
upgrade.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
import xml.etree.ElementTree as ET
import fw_creds
import datetime
fwhost = fw_creds.fwhost
fwkey = fw_creds.fwkey
def fwCmd(cmd):
values = {'type': 'op', 'cmd': cmd, 'key': fwkey}
palocall = 'https://%s/api/' % (fwhost)
try:
r = requests.post(palocall, data=values, verify=False)
except error as e:
return false
if r:
tree = ET.fromstring(r.text)
if tree.get('status') == "success":
return tree
else:
return false
def runningLatest(tree):
if tree.find('./result/sw-updates/msg').text == "No updates available":
return True
else:
return False
def getCurrent(tree):
for version in tree.findall('./result/sw-updates/versions/entry'):
if version.find('current').text == "yes":
return version.find('version').text
return False
def getLatest(tree):
for version in tree.findall('./result/sw-updates/versions/entry'):
if version.find('latest').text == "yes":
return version.find('version').text
return False
def checkDownloaded(tree, latest):
for version in tree.findall('./result/sw-updates/versions/entry'):
if version.find('version').text == latest:
if version.find('downloaded').text == "yes":
return True
else:
return False
#Get firewall software version info
cmd = "<request><system><software><check></check></software></system></request>"
versions = fwCmd(cmd)
if versions is not False:
if not runningLatest(versions):
current = getCurrent(versions)
latest = getLatest(versions)
if latest is not False:
if checkDownloaded(versions, latest) is False:
print("Downloading the latest PAN-OS")
#download
print("Installing the latest PAN-OS")
#install