def sync_record(self, o):

        if o.policy_code != 1:
            raise DeferredException("Waiting for ModelPolicy to complete")

        volt_service = VOLTService.objects.get(id=o.owner_id)

        log.info("Synching OLTServiceInstance", object=str(o), **o.tologdict())

        olt_device = o.onu_device.pon_port.olt_device

        try:
            # NOTE each ONU has only one UNI port!
            uni_port_id = o.onu_device.uni_ports.first().port_no
        except AttributeError:
            # This is because the ONUDevice is set by model_policy
            raise DeferredException("Waiting for ONUDevice %s " %
                                    olt_device.name)

        if not olt_device.dp_id:
            raise DeferredException(
                "Waiting for OLTDevice %s to be synchronized" %
                olt_device.name)

        log.debug("Adding subscriber with info",
                  uni_port_id=uni_port_id,
                  dp_id=olt_device.dp_id)

        # Send request to ONOS
        onos_voltha = Helpers.get_onos_voltha_info(volt_service)
        onos_voltha_basic_auth = HTTPBasicAuth(onos_voltha['user'],
                                               onos_voltha['pass'])

        handle = "%s/%s" % (olt_device.dp_id, uni_port_id)

        full_url = "%s:%d/onos/olt/oltapp/%s" % (onos_voltha['url'],
                                                 onos_voltha['port'], handle)

        log.info("Sending request to onos-voltha", url=full_url)

        request = requests.post(full_url, auth=onos_voltha_basic_auth)

        if request.status_code != 200:
            raise Exception("Failed to add subscriber in onos-voltha: %s" %
                            request.text)

        o.backend_handle = handle
        o.save(update_fields=["backend_handle"])

        log.info("Added Subscriber in onos voltha", response=request.text)
    def sync_record(self, o):
        self.log.info("Sync'ing Fabric Crossconnect Service Instance",
                      service_instance=o)

        if (o.policed is None) or (o.policed < o.updated):
            raise DeferredException(
                "Waiting for model_policy to run on fcsi %s" % o.id)

        onos = self.get_fabric_onos_info(o)

        si = ServiceInstance.objects.get(id=o.id)

        if (o.s_tag is None):
            raise Exception(
                "Cannot sync FabricCrossconnectServiceInstance if s_tag is None on fcsi %s"
                % o.id)

        if (o.source_port is None):
            raise Exception(
                "Cannot sync FabricCrossconnectServiceInstance if source_port is None on fcsi %s"
                % o.id)

        if (not o.switch_datapath_id):
            raise Exception(
                "Cannot sync FabricCrossconnectServiceInstance if switch_datapath_id is unset on fcsi %s"
                % o.id)

        bng_mapping = self.find_bng(s_tag=o.s_tag)
        if not bng_mapping:
            raise Exception("Unable to determine BNG port for s_tag %s" %
                            o.s_tag)
        east_port = bng_mapping.switch_port

        data = {
            "deviceId": o.switch_datapath_id,
            "vlanId": o.s_tag,
            "ports": [int(o.source_port), int(east_port)]
        }

        url = onos['url'] + '/onos/segmentrouting/xconnect'

        self.log.info("Sending request to ONOS", url=url, body=data)

        r = requests.post(url,
                          json=data,
                          auth=HTTPBasicAuth(onos['user'], onos['pass']))

        if r.status_code != 200:
            raise Exception(
                "Failed to create fabric crossconnect in ONOS: %s" % r.text)

        # TODO(smbaker): If the o.backend_handle changed, then someone must have changed the
        #   FabricCrossconnectServiceInstance. If so, then we potentially need to clean up the old
        #   entry in ONOS. Furthermore, we might want to also save the two port numbers that we used,
        #   to detect someone changing those.

        o.backend_handle = self.make_handle(o.s_tag, o.switch_datapath_id)
        o.save(update_fields=["backend_handle"])

        self.log.info("ONOS response", res=r.text)
示例#3
0
    def sync_record(self, o):
        log.info("Sync'ing", model=o.tologdict())
        if hasattr(o, 'service_instance'):
            # this is a ServiceInstanceAttribute model just push the config
            if 'ONOSApp' in o.service_instance.leaf_model.class_names:
                return self.add_config(o)
            return  # if it's not an ONOSApp do nothing

        if not self.check_app_dependencies(o.dependencies):
            raise DeferredException(
                'Deferring installation of ONOSApp with id %s as dependencies are not met'
                % o.id)

        # getting onos url and auth
        onos_url = "%s:%s" % (Helpers.format_url(
            o.owner.leaf_model.rest_hostname), o.owner.leaf_model.rest_port)
        onos_basic_auth = HTTPBasicAuth(o.owner.leaf_model.rest_username,
                                        o.owner.leaf_model.rest_password)

        # activate app (bundled in onos)
        if not o.url or o.url is None:
            self.activate_app(o, onos_url, onos_basic_auth)
        # install an app from a remote source
        if o.url and o.url is not None:
            self.install_app(o, onos_url, onos_basic_auth)
示例#4
0
 def defer_sync(self, o, reason):
     # zdw, 2017-02-18 - is raising the exception here necessary? - seems like
     # it's just logging the same thing twice
     self.log.info("defer object",
                   object=str(o),
                   reason=reason,
                   **o.tologdict())
     raise DeferredException("defer object %s due to %s" % (str(o), reason))
示例#5
0
    def map_sync_inputs(self, controller_slice):
        if getattr(controller_slice, "force_fail", None):
            raise Exception("Forced failure")
        elif getattr(controller_slice, "force_defer", None):
            raise DeferredException("Forced defer")

        tenant_fields = {"endpoint": "endpoint", "name": "Flagrant Haircut"}

        return tenant_fields
示例#6
0
    def validate_onu(model_accessor, log, att_si):
        """
        This method validate an ONU against the whitelist and set the appropriate state.
        It's expected that the deferred exception is managed in the caller method,
        for example a model_policy or a sync_step.

        :param att_si: AttWorkflowDriverServiceInstance
        :return: [boolean, string]
        """

        oss_service = att_si.owner.leaf_model

        # See if there is a matching entry in the whitelist.
        matching_entries = model_accessor.AttWorkflowDriverWhiteListEntry.objects.filter(
            owner_id=oss_service.id, )
        matching_entries = [
            e for e in matching_entries
            if e.serial_number.lower() == att_si.serial_number.lower()
        ]

        if len(matching_entries) == 0:
            log.warn("ONU not found in whitelist",
                     object=str(att_si),
                     serial_number=att_si.serial_number,
                     **att_si.tologdict())
            return [False, "ONU not found in whitelist"]

        whitelisted = matching_entries[0]
        try:
            onu = model_accessor.ONUDevice.objects.get(
                serial_number=att_si.serial_number)
            pon_port = onu.pon_port
        except IndexError:
            raise DeferredException("ONU device %s is not know to XOS yet" %
                                    att_si.serial_number)

        if onu.admin_state == "ADMIN_DISABLED":
            return [False, "ONU has been manually disabled"]

        if pon_port.port_no != whitelisted.pon_port_id or att_si.of_dpid != whitelisted.device_id:
            log.warn("ONU disable as location don't match",
                     object=str(att_si),
                     serial_number=att_si.serial_number,
                     pon_port=pon_port.port_no,
                     whitelisted_pon_port=whitelisted.pon_port_id,
                     device_id=att_si.of_dpid,
                     whitelisted_device_id=whitelisted.device_id,
                     **att_si.tologdict())
            return [False, "ONU activated in wrong location"]

        return [True, "ONU has been validated"]
    def wait_for_tp(self, technology):
        """
        Check if a technology profile for this technology has been already pushed to ETCD,
        if not defer the OLT Provisioning.
        :param technology: string - the technology to check for a tech profile
        :return: True (or raises DeferredException)
        """
        try:
            tps = TechnologyProfile.objects.get(technology=technology,
                                                backend_code=1)
        except IndexError:
            raise DeferredException(
                "Waiting for a TechnologyProfile (technology=%s) to be synchronized"
                % technology)

        return True
示例#8
0
    def validate_onu(model_accessor, log, ntt_si):
        """
        This method validate an ONU against the whitelist and set the appropriate state.
        It's expected that the deferred exception is managed in the caller method,
        for example a model_policy or a sync_step.

        :param ntt_si: NttWorkflowDriverServiceInstance
        :return: [boolean, string]
        """
        tech_value = json.loads(model_accessor.TechnologyProfile.objects.get(profile_id=64).profile_value)
        if tech_value["profile_type"] == "EPON":
            tech = tech_value["epon_attribute"]["package_type"]
        else:
            tech = tech_value["profile_type"]
              
        oss_service = ntt_si.owner.leaf_model

        # See if there is a matching entry in the whitelist.
        matching_entries = model_accessor.NttWorkflowDriverWhiteListEntry.objects.filter(
            owner_id=oss_service.id,
        )
        
        matching_entries = [e for e in matching_entries if e.mac_address.lower() == ntt_si.mac_address.lower()]
        
        if len(matching_entries) == 0:
            log.warn("ONU not found in whitelist")
            return [False, "ONU not found in whitelist"]

        whitelisted = matching_entries[0]
        try:
            onu = model_accessor.ONUDevice.objects.get(serial_number=ntt_si.serial_number.split("-")[0])
            pon_port = onu.pon_port
        except IndexError:
            raise DeferredException("ONU device %s is not know to XOS yet" % ntt_si.serial_number)

        if onu.admin_state == "ADMIN_DISABLED":
            return [False, "ONU has been manually disabled"]

        if pon_port.port_no < whitelisted.pon_port_from or pon_port.port_no > whitelisted.pon_port_to:
            log.warn("PON port is not approved.")
            return [False, "PON port is not approved."]
        
        if tech == "B":
            if ntt_si.authentication_state == "DENIED":
                return [False, "IEEE802.1X authentication has not been denied."]
            elif ntt_si.authentication_state != "APPROVED":
                return [True, "IEEE802.1X authentication has not been done yet."]
        else:
            ntt_si.authentication_state = "APPROVED"

        log.debug("Adding subscriber with info",
            uni_port_id = ntt_si.uni_port_id,
            dp_id = ntt_si.of_dpid
        )
        
        time.sleep(180)

        onos_voltha_basic_auth = HTTPBasicAuth("karaf", "karaf")

        handle = "%s/%s" % (ntt_si.of_dpid, ntt_si.uni_port_id)
        # TODO store URL and PORT in the vOLT Service model
        full_url = "http://129.60.110.180:8181/onos/olt/oltapp/%s" % (handle)

        log.info("Sending request to onos-voltha", url=full_url)

        request = requests.post(full_url, auth=onos_voltha_basic_auth)

        if request.status_code != 200:
            raise Exception("Failed to add subscriber in onos-voltha: %s" % request.text)
        log.info("Added Subscriber in onos voltha", response=request.text)

        return [True, "ONU has been validated"]
 def defer_sync(self, o, reason):
     log.info("defer object", object=str(o), reason=reason, **o.tologdict())
     raise DeferredException("defer object %s due to %s" % (str(o), reason))