123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820 |
- from Base import Base
- from Flowdat.Client import Client
- from Util import Strings
- class Olt(Base):
- SQL = {}
- SQL_DELETE = {}
- ONU_DEACTIVATE = []
- def __init__(self):
- Base.__init__(self)
- self.SQL_DELETE['olt'] = []
- self.SQL_DELETE['vlan'] = []
- self.SQL_DELETE['tcont_profile'] = []
- self.SQL_DELETE['traffic_profile'] = []
- self.SQL_DELETE['profile'] = []
- self.SQL_DELETE['nap'] = []
- self.SQL_DELETE['client'] = []
- self.SQL_DELETE['onu_model'] = []
- self.SQL_DELETE['onus'] = []
- self.SQL_DELETE['service_ports'] = []
- self.SQL['vlan'] = []
- self.SQL['tcont_profile'] = []
- self.SQL['traffic_profile'] = []
- self.SQL['profile'] = []
- self.SQL['nap'] = []
- self.SQL['client'] = []
- self.SQL['onu_model'] = []
- self.SQL['onus'] = []
- self.SQL['service_ports'] = []
- def delete_sql_olt(self, database, olt, tenancy_id):
- """
- Create sql delete for olt and add to property SQL_DELETE
- :param database: Database name
- :param olt: Object olt
- :param tenancy_id: Tenancy id
- """
- self.SQL_DELETE['olt'] = Strings.delete_table(database, "olt",
- Strings.get_values_delete(
- {"id": olt.idDataBase, "tenancy_id": tenancy_id})) + "\n"
- def create_sql_olt(self, database, olt, tenancy_id, olt_model_id):
- """
- Create sql insert for olt
- :param database: Database name
- :param olt: Object olt
- :param tenancy_id: Tenancy id
- :param olt_model_id: Model id for olt
- :return: Return string with sql insert
- """
- return Strings.insert_table(database, "olt",
- "id, tenancy_id, model_id, name",
- Strings.get_values([olt.idDataBase, tenancy_id, olt_model_id, olt.name])) + "\n"
- def create_sql_object(self, load_disabled, database, database_client, tenancy_id, init_vlan, init_tcont_profile,
- init_traffic_profile, init_profile, init_nap, init_client, init_onu_model, init_onus, init_service_ports):
- """
- Create sql insert for all object
- :param load_disabled: Load disabled onus
- :param database: Database name
- :param database_client: Database name for client table
- :param tenancy_id: Tenancy id
- :param init_vlan: Value to init id for vlan table
- :param init_tcont_profile: Value to init id for tcont_profile table
- :param init_traffic_profile: Value to init id for taffic_profile table
- :param init_profile: Value to init id for profile table
- :param init_nap: Value to init id for nap table
- :param init_client: Value to init id for client table
- :param init_onu_model: Value to init id for onu_model table
- :param init_onus: Value to init id for onus table
- :return: Return string with sql insert
- """
- init_vlan = int(init_vlan)
- init_tcont_profile = int(init_tcont_profile)
- init_traffic_profile = int(init_traffic_profile)
- init_profile = int(init_profile)
- init_nap = int(init_nap)
- init_client = int(init_client)
- init_onu_model = int(init_onu_model)
- init_onus = int(init_onus)
- init_service_ports = int(init_service_ports)
- for gpon in self.child:
- if gpon:
- for obj in gpon.child:
- if obj.state:
- init_vlan = self.vlan(obj, database, init_vlan, tenancy_id)
- init_tcont_profile = self.tcont_profile(obj, database, init_tcont_profile, tenancy_id)
- init_traffic_profile = self.traffic_profile_ingress(obj, database, init_traffic_profile,
- tenancy_id)
- init_traffic_profile = self.traffic_profile_egress(obj, database, init_traffic_profile,
- tenancy_id)
- init_profile = self.profile_ingress(obj, database, init_profile, tenancy_id)
- init_profile = self.profile_egress(obj, database, init_profile, tenancy_id)
- init_nap = self.nap(obj, database, init_nap, tenancy_id)
- if obj.client is None:
- obj.client = Client()
- obj.client.name = obj.serial_number
- init_client = self.client(obj, database_client, init_client, tenancy_id)
- init_onu_model = self.onu_model(obj, database, init_onu_model, tenancy_id)
- init_onus = self.onus(gpon, obj, database, init_onus, tenancy_id)
-
- init_service_ports = self.service_ports(gpon, obj, database, init_service_ports, tenancy_id)
- else:
- if load_disabled == 1:
- # init_vlan = self.vlan(obj, database, init_vlan, tenancy_id)
- # init_tcont_profile = self.tcont_profile(obj, database, init_tcont_profile, tenancy_id)
- # init_traffic_profile = self.traffic_profile_ingress(obj, database, init_traffic_profile,
- # tenancy_id)
- # init_traffic_profile = self.traffic_profile_egress(obj, database, init_traffic_profile,
- # tenancy_id)
- # init_profile = self.profile_ingress(obj, database, init_profile, tenancy_id)
- # init_profile = self.profile_egress(obj, database, init_profile, tenancy_id)
- init_nap = self.nap(obj, database, init_nap, tenancy_id)
- if obj.client is None:
- obj.client = Client()
- obj.client.name = obj.serial_number
- init_client = self.client(obj, database_client, init_client, tenancy_id)
- init_onu_model = self.onu_model(obj, database, init_onu_model, tenancy_id)
- init_onus = self.onus_disabled(obj, database, init_onus, tenancy_id)
- else:
- self.ONU_DEACTIVATE.append("-- ONU Desactivada. Nombre: " + obj.name + ", serial numbre: " + obj.serial_number)
- return self.print_sql()
- def print_sql_delete(self):
- """
- :return: Create string in order to execute en sql console
- """
- resp = ""
- for obj in self.SQL_DELETE['onus']:
- resp = resp + obj + "\n"
- resp = resp + "\n"
- resp = resp + self.SQL_DELETE['olt']
- resp = resp + "\n"
- for obj in self.SQL_DELETE['vlan']:
- resp = resp + obj + "\n"
- resp = resp + "\n"
- for obj in self.SQL_DELETE['tcont_profile']:
- resp = resp + obj + "\n"
- resp = resp + "\n"
- for obj in self.SQL_DELETE['traffic_profile']:
- resp = resp + obj + "\n"
- resp = resp + "\n"
- for obj in self.SQL_DELETE['profile']:
- resp = resp + obj + "\n"
- resp = resp + "\n"
- for obj in self.SQL_DELETE['nap']:
- resp = resp + obj + "\n"
- resp = resp + "\n"
- for obj in self.SQL_DELETE['client']:
- resp = resp + obj + "\n"
- resp = resp + "\n"
- for obj in self.SQL_DELETE['onu_model']:
- resp = resp + obj + "\n"
- resp = resp + "\n"
- for obj in self.SQL_DELETE['service_ports']:
- resp = resp + obj + "\n"
- resp = resp + "\n"
- return resp
- def print_sql(self):
- """
- :return: Create string in order to execute en sql console
- """
- resp = ""
- for obj in self.SQL['vlan']:
- resp = resp + obj['sql'] + "\n"
- resp = resp + "\n"
- for obj in self.SQL['tcont_profile']:
- resp = resp + obj['sql'] + "\n"
- resp = resp + "\n"
- for obj in self.SQL['traffic_profile']:
- resp = resp + obj['sql'] + "\n"
- resp = resp + "\n"
- for obj in self.SQL['profile']:
- resp = resp + obj['sql'] + "\n"
- resp = resp + "\n"
- for obj in self.SQL['nap']:
- resp = resp + obj['sql'] + "\n"
- resp = resp + "\n"
- for obj in self.SQL['client']:
- resp = resp + obj['sql'] + "\n"
- resp = resp + "\n"
- for obj in self.SQL['onu_model']:
- resp = resp + obj['sql'] + "\n"
- resp = resp + "\n"
- for obj in self.SQL['onus']:
- resp = resp + obj['sql'] + "\n"
- resp = resp + "\n"
- for obj in self.SQL['service_ports']:
- resp = resp + obj['sql'] + "\n"
- resp = resp + "\n"
- return resp
- def add_list_delete(self, position, delete):
- """
- Add delete value
- :param position: Name of position in SQL property
- :param delete: SQL delete
- :return: Return -1 if value not exists or value of id
- """
- self.SQL_DELETE[position].append(delete)
- def add_list(self, position, val, sql, init):
- """
- Add value to sql list
- :param position: Name of position in SQL property
- :param val: Unique value
- :param sql: Sql generated
- :param init: Value of id
- :return: Return -1 if value not exists or value of id
- """
- id_prov = None
- try:
- for obj in self.SQL[position]:
- if obj['val'] == val:
- id_prov = obj['id']
- break
- except Exception:
- id_prov = -1
- if id_prov == -1 or id_prov == None:
- self.SQL[position].append({'id': init, 'sql': sql, 'val': val})
- id_prov = -1
- return id_prov
- def vlan(self, obj, database, init, tenancy_id):
- """
- Check object for vlan
- :param obj: Object Onu
- :param database: Database name
- :param init: Value for id
- :param tenancy_id: Tenancy id
- :return: Return last id
- """
- val = 0
- if obj.switchport_vlan:
- val = int(obj.switchport_vlan.get_vlan_id())
- tmp = Strings.insert_table(database, "vlan_id",
- "id, tenancy_id, name, value",
- Strings.get_values([init,
- tenancy_id,
- val,
- val]))
- else:
- tmp = "Error al cargar el vlan id. No existe el objeto. Objeto padre " + obj.name
- obj.add_error(tmp)
- tmp = ""
- if len(tmp) > 0 and val > 0:
- id = self.add_list('vlan', val, tmp, init)
- if id == -1:
- id = init
- init += 1
- self.add_list_delete("vlan",
- Strings.delete_table(database, "vlan_id",
- Strings.get_values_delete(
- {"id": id, "tenancy_id": tenancy_id, "name": val})))
- obj.switchport_vlan.idDataBase = id
- return init
- def tcont_profile(self, obj, database, init, tenancy_id):
- """
- Check object for tcont_profile
- :param obj: Object Onu
- :param database: Database name
- :param init: Value for id
- :param tenancy_id: Tenancy id
- :return: Return last id
- """
- val = 0
- if obj.tcont:
- val = int(obj.tcont.get_tcont_id())
- tmp = Strings.insert_table(database, "tcont_profile",
- "id, tenancy_id, name, value, used_by_default",
- Strings.get_values([init,
- tenancy_id,
- obj.tcont.get_tcont_profile(),
- val,
- 0]))
- else:
- tmp = "Error al cargar el tcont. No existe el objeto. Objeto padre " + obj.name
- obj.add_error(tmp)
- tmp = ""
- if len(tmp) > 0 and val > 0:
- id = self.add_list('tcont_profile', val, tmp, init)
- if id == -1:
- id = init
- init += 1
- self.add_list_delete("tcont_profile",
- Strings.delete_table(database, "tcont_profile",
- Strings.get_values_delete(
- {"id": id, "tenancy_id": tenancy_id,
- "name": obj.tcont.get_tcont_profile()})))
- obj.tcont.idDataBase = id
- return init
- def traffic_profile_ingress(self, obj, database, init, tenancy_id):
- """
- Check object for traffic_profile
- :param obj: Object Onu
- :param database: Database name
- :param init: Value for id
- :param tenancy_id: Tenancy id
- :return: Return last id
- """
- val = 0
- if obj.traffic_profile_ingress:
- val = obj.traffic_profile_ingress.get_traffic_profile()
- tmp = Strings.insert_table(database, "traffic_profile",
- "id, tenancy_id, name, value, used_by_default",
- Strings.get_values([init,
- tenancy_id,
- val,
- val,
- 0]))
- else:
- tmp = "Error al cargar el perfil de trafico. No existe el objeto. Objeto padre " + obj.name
- obj.add_error(tmp)
- tmp = ""
- if len(tmp) > 0 and val > 0:
- id = self.add_list('traffic_profile', val, tmp, init)
- if id == -1:
- id = init
- init += 1
- self.add_list_delete("traffic_profile",
- Strings.delete_table(database, "traffic_profile",
- Strings.get_values_delete(
- {"id": id, "tenancy_id": tenancy_id,
- "name": val})))
- obj.traffic_profile_ingress.idDataBase = id
- return init
- def traffic_profile_egress(self, obj, database, init, tenancy_id):
- """
- Check object for traffic_profile
- :param obj: Object Onu
- :param database: Database name
- :param init: Value for id
- :param tenancy_id: Tenancy id
- :return: Return last id
- """
- val = 0
- if obj.traffic_profile_egress:
- val = obj.traffic_profile_egress.get_traffic_profile()
- tmp = Strings.insert_table(database, "traffic_profile",
- "id, tenancy_id, name, value, used_by_default",
- Strings.get_values([init,
- tenancy_id,
- val,
- val,
- 0]))
- else:
- tmp = "Error al cargar el perfil de trafico. No existe el objeto. Objeto padre " + obj.name
- obj.add_error(tmp)
- tmp = ""
- if len(tmp) > 0 and val > 0:
- id = self.add_list('traffic_profile', val, tmp, init)
- if id == -1:
- id = init
- init += 1
- self.add_list_delete("traffic_profile",
- Strings.delete_table(database, "traffic_profile",
- Strings.get_values_delete(
- {"id": id, "tenancy_id": tenancy_id,
- "name": val})))
- obj.traffic_profile_ingress.idDataBase = id
- return init
- def profile_ingress(self, obj, database, init, tenancy_id):
- """
- Check object for profile
- :param obj: Object Onu
- :param database: Database name
- :param init: Value for id
- :param tenancy_id: Tenancy id
- :return: Return last id
- """
- val = ""
- if obj.traffic_profile_ingress:
- val = obj.traffic_profile_ingress.get_traffic_profile()
- tmp = Strings.insert_table(database, "profile",
- "id, tenancy_id, name",
- Strings.get_values([init,
- tenancy_id,
- val]))
- else:
- tmp = "Error al cargar el profile. No existe el objeto. Objeto padre " + obj.name
- obj.add_error(tmp)
- tmp = ""
- if len(tmp) > 0 and len(val) > 0:
- id = self.add_list('profile', val, tmp, init)
- if id == -1:
- id = init
- init += 1
- self.add_list_delete("profile",
- Strings.delete_table(database, "profile",
- Strings.get_values_delete(
- {"id": id, "tenancy_id": tenancy_id, "name": val})))
- obj.traffic_profile_ingress.idDataBaseProfile = id
- return init
- def profile_egress(self, obj, database, init, tenancy_id):
- """
- Check object for profile
- :param obj: Object Onu
- :param database: Database name
- :param init: Value for id
- :param tenancy_id: Tenancy id
- :return: Return last id
- """
- val = ""
- if obj.traffic_profile_egress:
- val = obj.traffic_profile_egress.get_traffic_profile()
- tmp = Strings.insert_table(database, "profile",
- "id, tenancy_id, name",
- Strings.get_values([init,
- tenancy_id,
- val]))
- else:
- tmp = "Error al cargar el profile. No existe el objeto. Objeto padre " + obj.name
- obj.add_error(tmp)
- tmp = ""
- if len(tmp) > 0 and len(val) > 0:
- id = self.add_list('profile', val, tmp, init)
- if id == -1:
- id = init
- init += 1
- self.add_list_delete("profile",
- Strings.delete_table(database, "profile",
- Strings.get_values_delete(
- {"id": id, "tenancy_id": tenancy_id, "name": val})))
- obj.traffic_profile_ingress.idDataBaseProfile = id
- return init
- def nap(self, obj, database, init, tenancy_id):
- """
- Check object for nap
- :param obj: Object Onu
- :param database: Database name
- :param init: Value for id
- :param tenancy_id: Tenancy id
- :return: Return last id
- """
- val = ""
- if obj.nap:
- val = obj.nap.name.strip()
- tmp1, slot, link = val.split("/")
- tmp = Strings.insert_table(database, "nap",
- "id, tenancy_id, name, capacity, slot, link, olt_id",
- Strings.get_values([init,
- tenancy_id,
- val,
- 256,
- slot,
- link,
- self.idDataBase]))
- else:
- tmp = "Error al cargar el nap. No existe el objeto. Objeto padre " + obj.name
- obj.add_error(tmp)
- tmp = ""
- if len(tmp) > 0 and len(val) > 0:
- id = self.add_list('nap', val, tmp, init)
- if id == -1:
- id = init
- init += 1
- self.add_list_delete("nap",
- Strings.delete_table(database, "nap",
- Strings.get_values_delete(
- {"id": id, "tenancy_id": tenancy_id, "name": val})))
- obj.nap.idDataBase = id
- return init
- def client(self, obj, database, init, tenancy_id):
- """
- Check object for client
- :param obj: Object Onu
- :param database: Database name
- :param init: Value for id
- :param tenancy_id: Tenancy id
- :return: Return last id
- """
- val = ""
- if obj.client:
- val = obj.client.name.strip()
- tmp = Strings.insert_table(database, "client",
- "id, tenancy_id, name, created, updated",
- Strings.get_values([init,
- tenancy_id,
- val,
- "now()",
- "now()"]))
- else:
- tmp = "Error al cargar el cliente. No existe el objeto. Objeto padre " + obj.name
- obj.add_error(tmp)
- tmp = ""
- if len(tmp) > 0 and len(val) > 0:
- id = self.add_list('client', val, tmp, init)
- if id == -1:
- id = init
- init += 1
- self.add_list_delete("client",
- Strings.delete_table(database, "client",
- Strings.get_values_delete(
- {"id": id, "tenancy_id": tenancy_id, "name": val})))
- obj.client.idDataBase = id
- return init
- def onu_model(self, obj, database, init, tenancy_id):
- """
- Check object for onu_model
- :param obj: Object Onu
- :param database: Database name
- :param init: Value for id
- :param tenancy_id: Tenancy id
- :return: Return last id
- """
- val = ""
- if obj.onumodel:
- val = obj.onumodel.name.strip()
- tmp = Strings.insert_table(database, "onumodel",
- "id, tenancy_id, name",
- Strings.get_values([init,
- tenancy_id,
- val]))
- else:
- tmp = "Error al cargar el modelo de onu. No existe el objeto. Objeto padre " + obj.name
- obj.add_error(tmp)
- tmp = ""
- if len(tmp) > 0 and len(val) > 0:
- id = self.add_list('onu_model', val, tmp, init)
- if id == -1:
- id = init
- init += 1
- self.add_list_delete("onu_model",
- Strings.delete_table(database, "onumodel",
- Strings.get_values_delete(
- {"id": id, "tenancy_id": tenancy_id, "name": val})))
- obj.onumodel.idDataBase = id
- return init
- def onus(self, gpon, obj, database, init, tenancy_id):
- """
- Check object for onus
- :param obj: Object Onu
- :param database: Database name
- :param init: Value for id
- :param tenancy_id: Tenancy id
- :return: Return last id
- """
- val = obj.serial_number
- if obj.onumodel and \
- obj.nap and \
- obj.tcont and \
- obj.traffic_profile_ingress and \
- obj.switchport_vlan and \
- obj.serial_number and \
- obj.client and \
- obj.onumodel.idDataBase > 0 and \
- obj.nap.idDataBase > 0 and \
- obj.tcont.idDataBase > 0 and \
- obj.traffic_profile_ingress.idDataBase > 0 and \
- obj.switchport_vlan.idDataBase > 0 and \
- obj.client.idDataBase > 0:
- fields_default = "id, tenancy_id, olt_id, model_id, nap_id, tcontprofile_id, " \
- "traffic_profile_id, profile_id, vlan_id, client_id, serial_number, " \
- "pon_serial_number, pon_serial_number_aux, position, created, updated"
- values_default = [init, tenancy_id, self.idDataBase, obj.onumodel.idDataBase, obj.nap.idDataBase,
- obj.tcont.idDataBase, obj.traffic_profile_ingress.idDataBase,
- obj.traffic_profile_ingress.idDataBaseProfile, obj.switchport_vlan.idDataBase,
- obj.client.idDataBase, obj.serial_number, obj.serial_number,
- obj.serial_number,
- obj.id, "now()", "now()"]
- if obj.catv is not None:
- fields_default = fields_default + ", catv"
- values_default.append(obj.catv.is_catv())
- tmp = Strings.insert_table(database, "onu",
- fields_default,
- Strings.get_values(values_default))
- elif obj.onumodel and obj.nap and obj.serial_number and \
- obj.client and obj.onumodel.idDataBase > 0 and \
- obj.nap.idDataBase > 0 and obj.client.idDataBase > 0:
- fields_default = "id, tenancy_id, olt_id, model_id, nap_id, " \
- "client_id, serial_number, " \
- "pon_serial_number, pon_serial_number_aux, " \
- "position, created, updated"
- values_default = [init, tenancy_id, self.idDataBase, obj.onumodel.idDataBase,
- obj.nap.idDataBase, obj.client.idDataBase, obj.serial_number,
- obj.serial_number, obj.serial_number, obj.position, "now()", "now()"]
-
- if obj.catv is not None:
- fields_default = fields_default + ", catv"
- values_default.append(obj.catv.is_catv())
- tmp = Strings.insert_table(database, "onu",
- fields_default,
- Strings.get_values(values_default))
- else:
- tmp = "Error al cargar la onu con serial number: " + obj.serial_number + ", "
- if not obj.onumodel or obj.onumodel.idDataBase == 0:
- tmp = tmp + " no posee modelo de onu, "
- if not obj.nap or obj.nap.idDataBase == 0:
- tmp = tmp + " no posee nap, "
- if not obj.tcont or obj.tcont.idDataBase == 0:
- tmp = tmp + " no posee tcont, "
- if not obj.traffic_profile_ingress or obj.traffic_profile_ingress.idDataBase == 0:
- tmp = tmp + " no posee perfil de trafico de ingreso, "
- if not obj.switchport_vlan or obj.switchport_vlan.idDataBase == 0:
- tmp = tmp + " no posee vlan, "
- if not obj.client or obj.client.idDataBase == 0:
- tmp = tmp + " no posee cliente, "
- tmp = tmp[:-2]
- gpon.add_error(tmp)
- tmp = ""
- if len(tmp) > 0 and len(val) > 0:
- id = self.add_list('onus', val, tmp, init)
- if id == -1:
- id = init
- init += 1
- self.add_list_delete("onus",
- Strings.delete_table(database, "onu",
- Strings.get_values_delete(
- {"id": id, "tenancy_id": tenancy_id,
- "pon_serial_number": obj.serial_number})))
- obj.idDataBase = id
- return init
- def onus_disabled(self, obj, database, init, tenancy_id):
- """
- Check object for onus
- :param obj: Object Onu
- :param database: Database name
- :param init: Value for id
- :param tenancy_id: Tenancy id
- :return: Return last id
- """
- val = obj.serial_number
- fields_default = "id, tenancy_id, olt_id, model_id, nap_id, tcontprofile_id, " \
- "traffic_profile_id, profile_id, vlan_id, client_id, serial_number, " \
- "pon_serial_number, pon_serial_number_aux, position, created, updated"
- onumodel_id = "null"
- if obj.onumodel is not None and obj.onumodel.idDataBase > 0:
- onumodel_id = obj.onumodel.idDataBase
- nap_id = "null"
- if obj.nap is not None and obj.nap.idDataBase > 0:
- nap_id = obj.nap.idDataBase
- tcont_id = "null"
- if obj.tcont is not None and obj.tcont.idDataBase > 0:
- tcont_id = obj.tcont.idDataBase
- traffic_profile_ingress_id = "null"
- if obj.traffic_profile_ingress is not None and obj.traffic_profile_ingress.idDataBase > 0 :
- traffic_profile_ingress_id = obj.traffic_profile_ingress.idDataBase
- traffic_profile_ingress_id_profile = "null"
- if obj.traffic_profile_ingress is not None and obj.traffic_profile_ingress.idDataBaseProfile > 0 :
- traffic_profile_ingress_id_profile = obj.traffic_profile_ingress.idDataBaseProfile
- switchport_vlan_id = "null"
- if obj.switchport_vlan is not None and obj.switchport_vlan.idDataBase > 0 :
- switchport_vlan_id = obj.switchport_vlan.idDataBase
- client_id = "null"
- if obj.client is not None and obj.client.idDataBase > 0:
- client_id = obj.client.idDataBase
- values_default = [init, tenancy_id, self.idDataBase, onumodel_id, nap_id,
- tcont_id, traffic_profile_ingress_id,
- traffic_profile_ingress_id_profile, switchport_vlan_id,
- client_id, obj.serial_number, obj.serial_number,
- obj.serial_number,
- obj.id, "now()", "now()"]
- if obj.catv is not None:
- fields_default = fields_default + ", catv"
- values_default.append(obj.catv.is_catv())
- tmp = Strings.insert_table(database, "onu",
- fields_default,
- Strings.get_values(values_default))
- if len(tmp) > 0 and len(val) > 0:
- id = self.add_list('onus', val, tmp, init)
- if id == -1:
- id = init
- init += 1
- self.add_list_delete("onus",
- Strings.delete_table(database, "onu",
- Strings.get_values_delete(
- {"id": id, "tenancy_id": tenancy_id,
- "pon_serial_number": obj.serial_number})))
- obj.idDataBase = id
- return init
- def change_error_a_string(self, obj):
- """
- Transform error object into string
- :param obj: Object to check
- :return: Return string
- """
- if obj.error and len(obj.error) > 0:
- resp = "\n"
- for err in obj.error:
- resp = resp + "-- " + err + "\n"
- else:
- resp = ""
- return resp
- def add_value_error(self, errores, key, value):
- """
- Add error
- :param errores: Property error
- :param key: Contains key to add
- :param value: Contains value to add
- :return: Retorna param errores
- """
- if not errores.get(key):
- errores[key] = []
- if len(value) > 0:
- errores[key].append(value)
- return errores
- def obtains_errors(self, list_error_key=None):
- """
- Obtains errors for all object
- :param list_error_key: List error to show. Default None
- :return: Return with all errors
- """
- errores = {}
- resp = ""
- for gpon in self.child:
- if gpon:
- self.add_value_error(errores, 'gpon', self.change_error_a_string(gpon))
- # errores de los objetos hijos
- for obj in gpon.child:
- self.add_value_error(errores, 'onu', self.change_error_a_string(obj))
- if obj.sn_bind:
- self.add_value_error(errores, 'sn_bind', self.change_error_a_string(obj.sn_bind))
- if obj.tcont:
- self.add_value_error(errores, 'tcont', self.change_error_a_string(obj.tcont))
- if obj.gemport:
- self.add_value_error(errores, 'gemport', self.change_error_a_string(obj.gemport))
- if obj.switchport_mode:
- self.add_value_error(errores, 'switchport_mode',
- self.change_error_a_string(obj.switchport_mode))
- if obj.switchport_vlan:
- self.add_value_error(errores, 'switchport_vlan',
- self.change_error_a_string(obj.switchport_vlan))
- if obj.traffic_profile_ingress:
- self.add_value_error(errores, 'traffic_profile_ingress',
- self.change_error_a_string(obj.traffic_profile_ingress))
- if obj.traffic_profile_egress:
- self.add_value_error(errores, 'traffic_profile_egress',
- self.change_error_a_string(obj.traffic_profile_egress))
- if obj.nap:
- self.add_value_error(errores, 'nap', self.change_error_a_string(obj.nap))
- if obj.client:
- self.add_value_error(errores, 'client', self.change_error_a_string(obj.client))
- self.add_value_error(errores, 'olt', self.change_error_a_string(self))
- for deactivate in self.ONU_DEACTIVATE:
- resp = resp + deactivate + "\n"
- if resp:
- resp = resp + "\n"
- for key in errores:
- if list_error_key == None or len(list_error_key) == 0 or key in list_error_key:
- for err in errores[key]:
- resp = resp + err
- return resp
-
- def service_ports(self, gpon, obj, database, init, tenancy_id):
- """
- Check object for onus
- :param obj: Object Onu
- :param database: Database name
- :param init: Value for id
- :param tenancy_id: Tenancy id
- :return: Return last id
- """
- val = obj.serial_number
- if obj.service_port and \
- obj.nap and \
- obj.serial_number and \
- obj.client and \
- obj.onumodel.idDataBase > 0 and \
- obj.nap.idDataBase > 0 and \
- obj.client.idDataBase > 0:
- for sp in obj.service_port:
- fields_default = "id, olt_id, onu_id, number, gemport, vlan, type"
- values_default = [init, self.idDataBase, obj.idDataBase, sp.number, sp.gemport, sp.vlan, sp.type]
- tmp = Strings.insert_table(database, "service_port",
- fields_default,
- Strings.get_values(values_default))
- val = sp.number
- if len(tmp) > 0:
- id = self.add_list('service_ports', val, tmp, init)
- if id == -1:
- id = init
- init += 1
- self.add_list_delete("service_ports",
- Strings.delete_table(database, "service_port",
- Strings.get_values_delete(
- {"id": id, "tenancy_id": tenancy_id})))
- sp.idDataBase = id
- return init
|