from Base import Base from SnBind import SnBind from Tcont import Tcont from Gemport import Gemport from SwitchPort import SwitchPort from TrafficProfile import TrafficProfile from Client import Client from OnuModel import OnuModel from Util import Strings from ServicePort import ServicePort class Onu(Base): # Contains onu model onumodel = "" # Contains the serial number serial_number = "" # Contains value of property name of the file config name_onu = "" # Contains value of property state of the file config state = True # Contains sn-bind object sn_bind = None # Contains tcont object tcont = None # Contains gemport object gemport = None # Contains switch port mode object switchport_mode = None # Contains switch port vlan object switchport_vlan = None # Contains traffic profile of ingress object traffic_profile_ingress = None # Contains traffic profile of egress object traffic_profile_egress = None # Contains nap object nap = None # Contains client object client = None # Contains catv object catv = None # Contains ServicePort object service_port = [] # Contains ONU position position = None def __init__(self): Base.__init__(self) def import_data_list(self, data_compare, obj, onu_id=None, olt_model=None): """ Import data from list. Only import onu, type and sn value. :param data_compare: Contains data to compare in lower case. :param obj: Contains list of object. """ if olt_model == 'Huawei' and onu_id is not None: self.id = onu_id index = Strings.index_value(data_compare, "desc") if index >= 0: self.onumodel = OnuModel() self.onumodel.name = obj[index + 1].strip().replace('"','') index = Strings.index_value(data_compare, "sn-auth") if index >= 0: self.serial_number = obj[index + 1].strip().replace('"','') else: index = Strings.index_value(data_compare, "onu") if index >= 0: self.id = obj[index + 1].strip() index = Strings.index_value(data_compare, "type") if index >= 0: self.onumodel = OnuModel() self.onumodel.name = obj[index + 1].strip() index = Strings.index_value(data_compare, "sn") if index >= 0: self.serial_number = obj[index + 1].strip() def import_data(self, data_compare, obj, olt_model=None): """ Import data from object type IOSCfgLine. :param data_compare: Contains data to compare in lower case. :param obj: Contains object type IOSCfgLine. """ data_compare = data_compare.strip() if olt_model == 'Huawei': if data_compare.startswith("ont add"): data = data_compare.split() self.position = data[3] self.client = Client() self.client.name = self.serial_number if data_compare.startswith("service-port"): data = data_compare.split() serv_port = ServicePort() serv_port.number = data[1] serv_port.vlan = data[3] serv_port.gemport = data[9] serv_port.type = 'voip' if data[9] == '0' else 'data' obj.service_port.append(serv_port) else: if data_compare.startswith("name"): self.name_onu = obj.text.strip() data_compare = obj.text.lower().split() self.client = Client() index = Strings.index_value(data_compare, "name") if index >= 0: self.client.name = data_compare[index + 1].strip() elif data_compare.startswith("sn-bind"): self.sn_bind = SnBind() self.sn_bind.name = obj.text.strip() elif data_compare.startswith("tcont"): self.tcont = Tcont() self.tcont.name = obj.text.strip() elif data_compare.startswith("gemport"): self.gemport = Gemport() self.gemport.name = obj.text.strip() elif data_compare.startswith("switchport") and \ Strings.index_value(data_compare, "mode") > 0: self.switchport_mode = SwitchPort() self.switchport_mode.name = obj.text.strip() elif data_compare.startswith("switchport") and \ Strings.index_value(data_compare, "vlan") > 0: self.switchport_vlan = SwitchPort() self.switchport_vlan.name = obj.text.strip() elif data_compare.startswith("traffic-profile") and \ Strings.index_value(data_compare, "ingress") > 0: self.traffic_profile_ingress = TrafficProfile() self.traffic_profile_ingress.name = obj.text.strip() elif data_compare.startswith("traffic-profile") and \ Strings.index_value(data_compare, "egress") > 0: self.traffic_profile_egress = TrafficProfile() self.traffic_profile_egress.name = obj.text.strip() elif data_compare.startswith("state"): index = Strings.index_value(data_compare, "state") data_compare = data_compare.lower().split() if str(data_compare[index + 1]).lower().strip() == 'deactive': self.state = False else: self.state = True def isValid(self): """ Check if valid. :return: Return TRUE if valid onu. Checks id, serial_number and onumodel """ return self.id > 0 and self.onumodel is not "" and self.serial_number is not ""