Files
oopt-gnpy/gnpy/core/node.py
Jean-Luc Auge 8e046a9b50 Implement default values in xls parser for empty cells
*namedtuple default values are only applied if the cell is not read
*if the cell is read but is empty '', there is a need to provide default
values: which is what this fix does
*sanity checks are reinforced :
	-node_type is replaced by ROADM if degree <> 2: notify user
(print)
	-check that node type is in ('ILA','ROADM','FUSED')

Signed-off-by: Jean-Luc Auge <jeanluc.auge@orange.com>
2018-04-22 19:06:35 -04:00

82 lines
2.2 KiB
Python

#! /bin/usr/python3
'''
gnpy.core.node
==============
This module contains the base class for a network element.
Strictly, a network element is any callable which accepts an immutable
.info.SpectralInformation object and returns a .info.SpectralInformation object
(a copy.)
Network elements MUST implement two attributes .uid and .name representing a
unique identifier and a printable name.
This base class provides a mode convenient way to define a network element
via subclassing.
'''
from uuid import uuid4
from gnpy.core.utils import load_json
from gnpy.core.equipment import get_eqpt_params
class ConfigStruct:
def __init__(self, **config):
if config is None:
return None
if 'type_variety' in config:
#print('avant',config['type_variety'], config)
config['params'] = {**config.get('params',{}),
**get_eqpt_params(config['type_variety'])}
#print('apres', config)
self.set_config_attr(config)
def set_config_attr(self, config):
for k, v in config.items():
setattr(self, k, ConfigStruct(**v)
if isinstance(v, dict) else v)
def __repr__(self):
return f'{self.__dict__}'
class Node:
def __init__(self, config=None):
self.config = ConfigStruct(**config)
if self.config is None or not hasattr(self.config, 'uid'):
self.uid = uuid4()
else:
self.uid = self.config.uid
if hasattr(self.config, 'params'):
self.params = self.config.params
if hasattr(self.config, 'metadata'):
self.metadata = self.config.metadata
if hasattr(self.config, 'operational'):
self.operational = self.config.operational
@property
def coords(self):
return tuple(self.lng, self.lat)
@property
def location(self):
return self.config.metadata.location
@property
def loc(self): # Aliases .location
return self.location
@property
def lng(self):
return self.config.metadata.location.longitude
@property
def lat(self):
return self.config.metadata.location.latitude