Onu.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. from Base import Base
  2. from SnBind import SnBind
  3. from Tcont import Tcont
  4. from Gemport import Gemport
  5. from SwitchPort import SwitchPort
  6. from TrafficProfile import TrafficProfile
  7. from Client import Client
  8. from OnuModel import OnuModel
  9. from Util import Strings
  10. from ServicePort import ServicePort
  11. class Onu(Base):
  12. # Contains onu model
  13. onumodel = ""
  14. # Contains the serial number
  15. serial_number = ""
  16. # Contains value of property name of the file config
  17. name_onu = ""
  18. # Contains value of property state of the file config
  19. state = True
  20. # Contains sn-bind object
  21. sn_bind = None
  22. # Contains tcont object
  23. tcont = None
  24. # Contains gemport object
  25. gemport = None
  26. # Contains switch port mode object
  27. switchport_mode = None
  28. # Contains switch port vlan object
  29. switchport_vlan = None
  30. # Contains traffic profile of ingress object
  31. traffic_profile_ingress = None
  32. # Contains traffic profile of egress object
  33. traffic_profile_egress = None
  34. # Contains nap object
  35. nap = None
  36. # Contains client object
  37. client = None
  38. # Contains catv object
  39. catv = None
  40. # Contains ServicePort object
  41. service_port = []
  42. # Contains ONU position
  43. position = None
  44. def __init__(self):
  45. Base.__init__(self)
  46. def import_data_list(self, data_compare, obj, onu_id=None, olt_model=None):
  47. """
  48. Import data from list. Only import onu, type and sn value.
  49. :param data_compare: Contains data to compare in lower case.
  50. :param obj: Contains list of object.
  51. """
  52. if olt_model == 'Huawei' and onu_id is not None:
  53. self.id = onu_id
  54. index = Strings.index_value(data_compare, "desc")
  55. if index >= 0:
  56. self.onumodel = OnuModel()
  57. self.onumodel.name = obj[index + 1].strip().replace('"','')
  58. index = Strings.index_value(data_compare, "sn-auth")
  59. if index >= 0:
  60. self.serial_number = obj[index + 1].strip().replace('"','')
  61. else:
  62. index = Strings.index_value(data_compare, "onu")
  63. if index >= 0:
  64. self.id = obj[index + 1].strip()
  65. index = Strings.index_value(data_compare, "type")
  66. if index >= 0:
  67. self.onumodel = OnuModel()
  68. self.onumodel.name = obj[index + 1].strip()
  69. index = Strings.index_value(data_compare, "sn")
  70. if index >= 0:
  71. self.serial_number = obj[index + 1].strip()
  72. def import_data(self, data_compare, obj, olt_model=None):
  73. """
  74. Import data from object type IOSCfgLine.
  75. :param data_compare: Contains data to compare in lower case.
  76. :param obj: Contains object type IOSCfgLine.
  77. """
  78. data_compare = data_compare.strip()
  79. if olt_model == 'Huawei':
  80. if data_compare.startswith("ont add"):
  81. data = data_compare.split()
  82. self.position = data[3]
  83. self.client = Client()
  84. self.client.name = self.serial_number
  85. if data_compare.startswith("service-port"):
  86. data = data_compare.split()
  87. serv_port = ServicePort()
  88. serv_port.number = data[1]
  89. serv_port.vlan = data[3]
  90. serv_port.gemport = data[9]
  91. serv_port.type = 'voip' if data[9] == '0' else 'data'
  92. obj.service_port.append(serv_port)
  93. else:
  94. if data_compare.startswith("name"):
  95. self.name_onu = obj.text.strip()
  96. data_compare = obj.text.lower().split()
  97. self.client = Client()
  98. index = Strings.index_value(data_compare, "name")
  99. if index >= 0:
  100. self.client.name = data_compare[index + 1].strip()
  101. elif data_compare.startswith("sn-bind"):
  102. self.sn_bind = SnBind()
  103. self.sn_bind.name = obj.text.strip()
  104. elif data_compare.startswith("tcont"):
  105. self.tcont = Tcont()
  106. self.tcont.name = obj.text.strip()
  107. elif data_compare.startswith("gemport"):
  108. self.gemport = Gemport()
  109. self.gemport.name = obj.text.strip()
  110. elif data_compare.startswith("switchport") and \
  111. Strings.index_value(data_compare, "mode") > 0:
  112. self.switchport_mode = SwitchPort()
  113. self.switchport_mode.name = obj.text.strip()
  114. elif data_compare.startswith("switchport") and \
  115. Strings.index_value(data_compare, "vlan") > 0:
  116. self.switchport_vlan = SwitchPort()
  117. self.switchport_vlan.name = obj.text.strip()
  118. elif data_compare.startswith("traffic-profile") and \
  119. Strings.index_value(data_compare, "ingress") > 0:
  120. self.traffic_profile_ingress = TrafficProfile()
  121. self.traffic_profile_ingress.name = obj.text.strip()
  122. elif data_compare.startswith("traffic-profile") and \
  123. Strings.index_value(data_compare, "egress") > 0:
  124. self.traffic_profile_egress = TrafficProfile()
  125. self.traffic_profile_egress.name = obj.text.strip()
  126. elif data_compare.startswith("state"):
  127. index = Strings.index_value(data_compare, "state")
  128. data_compare = data_compare.lower().split()
  129. if str(data_compare[index + 1]).lower().strip() == 'deactive':
  130. self.state = False
  131. else:
  132. self.state = True
  133. def isValid(self):
  134. """
  135. Check if valid.
  136. :return: Return TRUE if valid onu. Checks id, serial_number and onumodel
  137. """
  138. return self.id > 0 and self.onumodel is not "" and self.serial_number is not ""