Collection of CheckMK checks (see https://checkmk.com/). All checks and plugins are provided as is. Absolutely no warranty. Send any comments to thl-cmk[at]outlook[dot]com

Skip to content
Snippets Groups Projects
Commit 92ff9b2f authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

added default IOS/IOS-XE config file fallback

parent cfd7ff19
No related branches found
No related tags found
No related merge requests found
2022-12-14: added count in status page
added check if image/config file is available
2022-12-15: renamed ./vars/vars.py to ./vars/settings.py
stop on import error for images.py and platforms.py
removed extending path variable to ./vars
2023-01-26: reorg platforms.py and images.py in images.json
reorg settings.py in open-pnp.ini
remove imports for platforms.py/images.py/settings.py
added reload data function
changed open-pnp.ini/images.json to open-pnp.toml/images.toml for better handling
2023-01-27: added default IOS/IOS-XE config file fallback
\ No newline at end of file
2023-01-26: reorg platforms.py and images.py in images.json
reorg settings.py in open-pnp.ini
remove imports for platforms.py/images.py/settings.py
add reload data function
changed open-pnp.ini/images.json to toml (better to handle)
\ No newline at end of file
......@@ -26,7 +26,7 @@ models = []
version = "17.6.4"
md5 = "2caa962f5ed0ecc52f99b90c733c54de"
size = 706565772
models = ["C1117-4PMLTEEAWE"]
models = []
["c1100-universalk9.17.09.01a.SPA.bin"]
version = "17.9.1a"
......@@ -34,6 +34,18 @@ md5 = "b3efb230d869fa6e77a98b4130c89585"
size = 684976080
models = []
["c1100-universalk9.17.09.02a.SPA.bin"]
version = "17.9.2a"
md5 = "5a1e3c44a40d63d6d8d83370fe37d21d"
size = 685295244
models = ["C1117-4PMLTEEAWE"]
["c1100-universalk9.17.10.01a.SPA.bin"]
version = "17.10.1a"
md5 = "a0cd6218c42f19bed425e3c63a11bcda"
size = 689542648
models = []
["c3560cx-universalk9-mz.152-7.E7.bin"]
version = "15.2(7)E7"
md5 = "1c4c0597d355a0926c3d7198c1167cae"
......
......@@ -14,12 +14,17 @@
#
# Cisco doc on https://developer.cisco.com/site/open-plug-n-play/learn/learn-open-pnp-protocol/
#
# 20-12-14: added count in status page
# added check if image/config file available
# 20-12-15: renamed ./vars/vars.py to ./vars/settings.py
# stop on import error for images.py and platforms.py
# removed extending path variable to ./vars
# changed open-pnp.ini/images.json to toml (better to handle)
# 2022-12-14: added count in status page
# added check if image/config file is available
# 2022-12-15: renamed ./vars/vars.py to ./vars/settings.py
# stop on import error for images.py and platforms.py
# removed extending path variable to ./vars
# 2023-01-26: reorg platforms.py and images.py in images.json
# reorg settings.py in open-pnp.ini
# remove imports for platforms.py/images.py/settings.py
# added reload data function
# changed open-pnp.ini/images.json to open-pnp.toml/images.toml for better handling
# 2023-01-27: added default IOS/IOS-XE config file fallback
#
# pip install flask xmltodict requests ifaddr tomli
......@@ -52,6 +57,7 @@ LOG_FILE: Optional[str] = None # 'log/pnp_debug.log'
IMAGES: Optional[Dict[str, any]] = None # {}
IMAGE_BASE_URL: Optional[str] = None # ''
CONFIG_BASE_URL: Optional[str] = None # ''
DEFAULT_CFG_FILE: Optional[str] = None # 'DEFAULT.cfg'
class SoftwareImage:
......@@ -281,11 +287,13 @@ def load_data():
global LOG_FILE
global IMAGE_BASE_URL
global CONFIG_BASE_URL
global DEFAULT_CFG_FILE
settings = {
'BIND_PNP_SERVER': '0.0.0.0',
'CONFIG_BASE_URL': '',
'DEBUG': False,
'DEFAULT_CFG_FILE': 'DEFAULT.cfg',
'IMAGE_BASE_URL': '',
'IMAGE_DATA': 'images.toml',
'LOG_FILE': 'log/pnp_debug.log',
......@@ -315,6 +323,7 @@ def load_data():
IMAGE_DATA = settings.get('IMAGE_DATA')
IMAGE_BASE_URL = settings.get('IMAGE_BASE_URL').rstrip('/')
CONFIG_BASE_URL = settings.get('CONFIG_BASE_URL').rstrip('/')
DEFAULT_CFG_FILE = settings.get('DEFAULT_CFG_FILE')
try:
with open(IMAGE_DATA, 'rb') as f:
......@@ -408,24 +417,30 @@ def pnp_install_image(udi: str, correlator: str) -> Optional[str]:
def pnp_config_upgrade(udi: str, correlator: str) -> Optional[str]:
device = devices[udi]
response = head(f'{CONFIG_BASE_URL}/{device.serial}.cfg')
if response.status_code == 200:
device.current_job = 'urn:cisco:pnp:device-info'
device.pnp_flow = PNPFLOW.CONFIG_START
jinja_context = {
'udi': udi,
'correlator': correlator,
'base_url': CONFIG_BASE_URL,
'serial_number': device.serial,
'delay': 30, # reload in seconds
}
_template = render_template('config_upgrade.xml', **jinja_context)
if DEBUG:
log_info(_template)
return _template
else:
device.error_code = ERROR.ERROR_NO_CFG_FILE
device.hard_error = True
cfg_file = f'{device.serial}.cfg'
response = head(f'{CONFIG_BASE_URL}/{cfg_file}')
if response.status_code != 200: # SERIAL.cfg not found
cfg_file = DEFAULT_CFG_FILE
response = head(f'{CONFIG_BASE_URL}/{cfg_file}')
if response.status_code != 200: # DEFAULT.cfg also not found
device.error_code = ERROR.ERROR_NO_CFG_FILE
device.hard_error = True
return
device.current_job = 'urn:cisco:pnp:device-info'
device.pnp_flow = PNPFLOW.CONFIG_START
jinja_context = {
'udi': udi,
'correlator': correlator,
'base_url': CONFIG_BASE_URL,
'serial_number': cfg_file,
'delay': 30, # reload in seconds
'cfg_file': cfg_file,
}
_template = render_template('config_upgrade.xml', **jinja_context)
if DEBUG:
log_info(_template)
return _template
def pnp_bye(udi: str, correlator: str) -> str:
......
......@@ -7,6 +7,7 @@ STATUS_REFRESH = 10
# DEBUG = false
# LOG_TO_FILE = true
# LOG_FILE = "log/pnp_debug.log"
# DEFAULT_CFG_FILE = "DEFAULT.cfg"
# IMAGE_DATA = "images.json"
IMAGE_BASE_URL = "http://192.168.10.133:8080/images"
CONFIG_BASE_URL = "http://192.168.10.133:8080/configs"
......@@ -4,7 +4,7 @@
<config details="all">
<copy>
<source>
<location>{{ base_url }}/{{ serial_number }}.cfg</location>
<location>{{ base_url }}/{{ cfg_file }}</location>
</source>
</copy>
<!-- <applyto>startup</applyto> --> <!-- don't now where to place this -->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment