def load_configuration(section='Server'):
"""
The GNS3 Server (/Controller) is configured through the gns3_server.conf file.
GNS3 searches various locations depending on the platform. These locations are listed in the
documentation.
DOCUMENTATION / GNS3 SERVER CONFIGURATION FILE
http://docs.gns3.com/1f6uXq05vukccKdMCHhdki5MXFhV8vcwuGwiRvXMQvM0/
"""
platform_file_locations = {
# TODO add Linux/Windows file locations and test.
'Darwin': [
f'{str(Path.home())}/.config/GNS3/gns3_server.conf',
'./gns3_server.conf',
]
}
system_platform = platform.system()
if system_platform not in platform_file_locations.keys():
# TODO manual input option? Perhaps additional argument in staticmethod?
raise OSError('Operating system {} not supported')
# TODO verify behaviour ConfigParser vs GNS3 (i.e. does it merge or is there precedence?)
parser = ConfigParser()
found = parser.read(platform_file_locations[system_platform])
if found and section in parser.sections():
for k, v in dict(parser.items(section)).items():
setattr(GNS3API, k, v)
GNS3API.cred = HTTPBasicAuth(GNS3API.user, GNS3API.password)
GNS3API.base = f'{GNS3API.protocol}://{GNS3API.host}:{str(GNS3API.port)}/v2'
else:
print(f'Platform: {system_platform}\n'
'Looked for configuration files at these locations:\n')
for candidate in platform_file_locations[system_platform]:
print(f' {candidate}')
print('\n')
raise FileNotFoundError('No Valid Configuration File Found')
评论列表
文章目录