示例#1
0
    def enable_onu(self, o):
        volt_service = o.pon_port.olt_device.volt_service

        log.info("Enabling device %s in voltha" % o.device_id)
        try:
            get_voltha_client(volt_service).enable_device(o.device_id)
        except Exception as e:
            e.message = "[Enable ONU] " + e.message
            log.error(e.message)
            raise e
示例#2
0
    def get_ids_from_logical_device(o):
        logical_devices = get_voltha_client(
            o.volt_service).list_logical_devices()
        for ld in logical_devices:
            if ld.root_device_id == o.device_id:
                o.of_id = ld.id
                o.dp_id = "of:%s" % (Helpers.datapath_id_to_hex(ld.datapath_id)
                                     )  # Convert to hex
                return o

        raise Exception("Can't find a logical_device for OLT device id: %s" %
                        o.device_id)
示例#3
0
 def fetch_onu_ports(self, onu):
     try:
         onu_ports = get_voltha_client(self.volt_service).list_device_ports(
             onu.device_id)
         if onu_ports is None:
             return
         log.debug("[ONU pull step] received ports",
                   ports=onu_ports,
                   onu=onu.device_id)
         self.create_or_update_ports(onu_ports, onu)
     except Exception as e:
         log.error("[ONU pull step] " + e.message)
         return
示例#4
0
    def fetch_olt_ports(self, olt_device_id):
        """
        Given an olt device_id, query VOLTHA for the set of ports associated with that OLT.

        :param olt_device_id: The given OLT device id.
        :return: List of port dictionaries, or None in case of error.
        """
        try:
            olt_ports = get_voltha_client(
                self.volt_service).list_device_ports(olt_device_id)
            if olt_ports is not None:
                log.debug("[OLT pull step] received ports",
                          ports=olt_ports,
                          olt=olt_device_id)
            return olt_ports
        except Exception as e:
            log.error("[OLT pull step] " + e.message)
            return None
示例#5
0
    def pull_records(self):
        log.debug("[OLT pull step] pulling OLT devices from VOLTHA")
        try:
            self.volt_service = VOLTService.objects.all()[0]
        except IndexError:
            log.warn('VOLTService not found')
            return

        try:
            olt_devices = get_voltha_client(
                self.volt_service).list_olt_devices()
            if olt_devices is None:
                log.debug("[OLT pull step] Blank response received")
                return
            log.debug("[OLT pull step] received devices", olts=olt_devices)
            olts_in_voltha = self.create_or_update_olts(olt_devices)
            self.delete_olts(olts_in_voltha)
        except Exception as e:
            log.error("[OLT pull step] " + e.message)
            return
示例#6
0
    def get_ids_from_logical_device(o):
        # FIXME: this should return a single device from VOLTHA since an instance of Voltha has a single OLT
        try:
            logical_devices = get_voltha_client(
                o.volt_service).list_logical_devices()
        except Exception as e:
            log.error("[OLT pull step] " + e.message)
            raise e

        for ld in logical_devices:
            if ld.root_device_id == o.device_id:
                o.of_id = ld.id
                o.dp_id = "of:" + Helpers.datapath_id_to_hex(
                    ld.datapath_id)  # convert to hex

        # Note: If the device is administratively disabled, then it's likely we won't find a logical device for
        # it. Only throw the exception for OLTs that are enabled.

        if not o.of_id and not o.dp_id and o.admin_state == "ENABLED":
            raise Exception("Can't find a logical device for device id: %s" %
                            o.device_id)
示例#7
0
    def pre_provision_olt_device(self, olt_xos_model):
        log.info("Pre-provisioning OLT device in VOLTHA",
                 object=str(olt_xos_model),
                 **olt_xos_model.tologdict())

        try:
            resp_dev = get_voltha_client(
                olt_xos_model.volt_service).create_olt_device(olt_xos_model)
            log.info("Device has been pushed to VOLTHA with ID: %s",
                     resp_dev.id)
        except Exception as e:
            log.error("ASDASD")
            log.error(e)
            log.error(e.message)
            raise e

        log.debug("Add device response", device=resp_dev)

        # TODO(smbaker): Potential partial failure. If device is created in Voltha but synchronizer crashes before the
        # model is saved, then synchronizer will continue to try to preprovision and fail due to preexisting
        # device.

        # Device ID comes from Voltha and it is allocated with device is created
        if resp_dev.id == '':
            raise Exception(
                'VOLTHA Device Id is empty. This probably means that the OLT device is already provisioned in VOLTHA'
            )
        else:
            olt_xos_model.device_id = resp_dev.id
            # Only update the serial number if it is not already populated. See comments in similar code in the
            # pull step. Let the pull step handle emitting any error message if the serial numbers differ.
            if resp_dev.serial_number != '' and (
                    not olt_xos_model.serial_number):
                log.info("Sync step learned OLT serial number from voltha",
                         model_serial_number=olt_xos_model.serial_number,
                         voltha_serial_number=resp_dev.serial_number,
                         olt_id=olt_xos_model.id)
                olt_xos_model.serial_number = resp_dev.serial_number
            log.info("save_changed_fields1")
            olt_xos_model.save_changed_fields()
示例#8
0
    def delete_record(self, model):
        log.info("Deleting OLT device", object=str(model), **model.tologdict())

        if not model.device_id or model.backend_code == 2:
            # NOTE if the device was not synchronized, just remove it from the data model
            log.warning(
                "OLTDevice %s has no device_id, it was never saved in VOLTHA" %
                model.name)
            return
        else:
            voltha_client = get_voltha_client(model.volt_service)
            try:
                voltha_client.disable_device(model.device_id)
            except ConnectionError as e:
                e.message = "[Disable OLT] " + e.message
                log.warn(e.message)
                return
            except Exception as e:
                e.message = "[Disable OLT] " + e.message
                log.error(e.message)
                raise e

            # NOTE [teo] wait some time after the disable to let VOLTHA doing its things
            for i in list(reversed(range(10))):
                sleep(1)
                log.info("[Delete OLT] Deleting the OLT in %s seconds" % i)

            # Delete the OLT device
            try:
                voltha_client.delete_device(model.device_id)
            except ConnectionError as e:
                e.message = "[Delete OLT] " + e.message
                log.warn(e.message)
                return
            except Exception as e:
                e.message = "[Delete OLT] " + e.message
                log.error(e.message)
                raise e
示例#9
0
    def pull_records(self):
        log.debug("[ONU pull step] pulling ONU devices from VOLTHA")

        try:
            self.volt_service = VOLTService.objects.all()[0]
        except IndexError:
            log.warn('VOLTService not found')
            return
        try:
            onu_devices = get_voltha_client(
                self.volt_service).list_onu_devices()
            if onu_devices is None:
                return
            if len(onu_devices) > 0:
                log.debug("received devices", onus=onu_devices)
                onus_in_voltha = self.create_or_update_onus(onu_devices)

                # TODO
                # [ ] delete ONUS as ONUDevice.objects.all() - updated ONUs
            else:
                log.debug("[ONU pull step] Blank response received")
        except Exception as e:
            log.error("[ONU pull step] " + e.message)
            return
示例#10
0
    def activate_olt(self, model):
        attempted = 0

        # Enable device
        voltha_client = get_voltha_client(model.volt_service)
        try:
            voltha_client.enable_device(model.device_id)
        except Exception as e:
            e.message = "[OLT enable] " + e.message
            log.error(e.message)
            raise e

        model.backend_status = "Waiting for device to be activated"
        log.info("save_changed_fields2")
        model.save_changed_fields(always_update_timestamp=False
                                  )  # we don't want to kickoff a new loop

        # Read state
        olt_dev = None
        try:
            olt_dev = voltha_client.get_device(model.device_id)
            model.oper_status = common_pb2.OperStatus.Types.Name(
                olt_dev.oper_status)
        except ConnectionError as e:
            # Strange behaviour, previous call was successful but this gives connection error.
            log.error(e.message)
            # Anyway, continue and retry again
        except Exception as e:
            log.warn(e.message)

        while model.oper_status == "ACTIVATING" and attempted < self.max_attempt:
            log.info("Waiting for OLT device %s (%s) to activate" %
                     (model.name, model.device_id))
            sleep(5)
            try:
                olt_dev = voltha_client.get_device(model.device_id)
            except ConnectionError as e:
                # Strange behaviour, previous call was successful but this gives connection error.
                log.error(e.message)
                # Anyway, continue and retry again
            except Exception as e:
                log.warn(e.message)
                olt_dev = None
            if olt_dev is not None:
                model.oper_status = common_pb2.OperStatus.Types.Name(
                    olt_dev.oper_status)
            attempted = attempted + 1

        # FIXME: possible NoneType if get_device always except
        # Only update the serial number if it is not already populated. See comments in similar code in the
        # pull step. Let the pull step handle emitting any error message if the serial numbers differ.
        if olt_dev.serial_number != '' and (not model.serial_number):
            log.info("Sync step learned olt serial number from voltha",
                     model_serial_number=model.serial_number,
                     voltha_serial_number=olt_dev.serial_number,
                     olt_id=model.id)
            model.serial_number = olt_dev.serial_number

        if model.oper_status != "ACTIVE":
            raise Exception(
                "It was not possible to activate OLTDevice with id %s" %
                model.id)

        # Find the of_id of the device
        self.get_ids_from_logical_device(model)
        log.info("save_changed_fields3")
        model.save_changed_fields()
示例#11
0
 def deactivate_olt(self, model):
     get_voltha_client(model.volt_service).disable_device(model.device_id)