mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-25 17:27:01 +00:00
Initial system configuration and customization interface.
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
############################################################
|
||||
#
|
||||
# ONL System Configuration
|
||||
#
|
||||
############################################################
|
||||
import os
|
||||
import sys
|
||||
import yaml
|
||||
import types
|
||||
import onl.onlyaml
|
||||
import platform as pp
|
||||
from onl.platform.current import OnlPlatform
|
||||
|
||||
class DotDict(dict):
|
||||
""" Access keys in a nested dictionary using dot notation """
|
||||
|
||||
def __getattr__(self, attr):
|
||||
item = self.get(attr, None)
|
||||
|
||||
if item is None:
|
||||
raise AttributeError("'%s' object has no attribute '%s'" % (type(self), attr))
|
||||
|
||||
if type(item) == types.DictType:
|
||||
item = DotDict(item)
|
||||
|
||||
return item
|
||||
|
||||
__setattr__= dict.__setitem__
|
||||
__delattr__= dict.__delitem__
|
||||
|
||||
|
||||
class OnlSystemConfig(object):
|
||||
SYSTEM_CONFIG_DIR = '/etc/onl/config'
|
||||
|
||||
def __init__(self):
|
||||
|
||||
platform = OnlPlatform()
|
||||
self.variables = {}
|
||||
self.variables['PLATFORM'] = platform.platform()
|
||||
self.variables['ARCH'] = pp.machine()
|
||||
self.variables['PARCH'] = dict(ppc='powerpc',
|
||||
x86_64='amd64',
|
||||
armv7l='armel')[pp.machine()]
|
||||
|
||||
self.config = {}
|
||||
|
||||
for root, dirs, files in os.walk(self.SYSTEM_CONFIG_DIR):
|
||||
for f in files:
|
||||
if f.endswith('.yml'):
|
||||
d = onl.onlyaml.loadf(os.path.join(root, f), self.variables)
|
||||
self.config.update(d)
|
||||
|
||||
self.config['pc'] = platform.platform_config
|
||||
|
||||
def dump(self):
|
||||
return yaml.dump(self.config, default_flow_style=False)
|
||||
|
||||
x = OnlSystemConfig()
|
||||
sysconfig = DotDict(x.config)
|
||||
sysconfig['OnlSystemConfig'] = x
|
||||
Reference in New Issue
Block a user