Exemple #1
0
    def sync_record(self, o):
        log.info("sync'ing enodeb", object=str(o), **o.tologdict())

        onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)

        enodeb_url = "http://%s:%s/onos/progran/enodeb/" % (onos['url'],
                                                            onos['port'])
        data = self.get_progran_enodeb_field(o)
        log.debug("Sync'ing enodeb with data", request_data=data)

        if o.previously_sync == False:
            log.debug("Sending POST", url=enodeb_url, data=json.dumps(data))
            r = requests.post(enodeb_url,
                              data=json.dumps(data),
                              auth=HTTPBasicAuth(onos['username'],
                                                 onos['password']))
        else:
            data = {"EnodeB": data}
            log.debug("Sending PUT", url=enodeb_url, data=json.dumps(data))
            r = requests.put(enodeb_url,
                             data=json.dumps(data),
                             auth=HTTPBasicAuth(onos['username'],
                                                onos['password']))

        ProgranHelpers.get_progran_rest_errors(r)
        log.info("Enodeb synchronized", response=r.json())

        o.previously_sync = True
        o.save()
Exemple #2
0
    def sync_record(self, o):
        onos = ProgranHelpers.get_progran_onos_info()

        log.info("sync'ing profile", object=str(o), **o.tologdict())

        profile_url = "http://%s:%s/onos/progran/profile/" % (onos['url'],
                                                              onos['port'])
        data = self.get_progran_profile_field(o)
        log.debug("Sync'ing profile with data", request_data=data)

        if o.previously_sync == False:
            log.debug("Sending POST", url=profile_url, data=json.dumps(data))
            r = requests.post(profile_url,
                              data=json.dumps(data),
                              auth=HTTPBasicAuth(onos['username'],
                                                 onos['password']))
        else:
            log.debug("Sending PUT", url=profile_url, data=json.dumps(data))
            r = requests.put(profile_url,
                             data=json.dumps(data),
                             auth=HTTPBasicAuth(onos['username'],
                                                onos['password']))

        ProgranHelpers.get_progran_rest_errors(r)
        log.info("Profile synchronized", response=r.json())

        if o.enodeb_id:
            log.info("adding profile %s to enodeb %s" % (o.id, o.enodeb.enbId),
                     object=str(o),
                     **o.tologdict())
            enodeb_url = "http://%s:%s/onos/progran/enodeb/%s/profile" % (
                onos['url'], onos['port'], o.enodeb.enbId)
            data = {"ProfileArray": [o.name]}
            log.debug("Adding enodeb to profile with data", request_data=data)
            r = requests.post(enodeb_url,
                              data=json.dumps(data),
                              auth=HTTPBasicAuth(onos['username'],
                                                 onos['password']))
            ProgranHelpers.get_progran_rest_errors(r)
            o.active_enodeb_id = o.enodeb_id  # storing the value to know when it will be deleted
            log.info("EnodeB synchronized", response=r.json())
        elif o.active_enodeb_id:
            enb_id = ENodeB.objects.get(id=o.active_enodeb_id).enbId
            log.info("removing profile %s from enodeb %s" %
                     (o.name, o.active_enodeb_id),
                     object=str(o),
                     **o.tologdict())
            enodeb_url = "http://%s:%s/onos/progran/enodeb/%s/profile/%s" % (
                onos['url'], onos['port'], enb_id, o.name)
            r = requests.delete(enodeb_url,
                                auth=HTTPBasicAuth(onos['username'],
                                                   onos['password']))
            ProgranHelpers.get_progran_rest_errors(r)
            o.active_enodeb_id = 0  # removing the value because it has been deleted
            log.info("EnodeB synchronized", response=r.json())

        o.previously_sync = True
        o.no_sync = True
        o.save()
Exemple #3
0
    def sync_record(self, o):
        log.info("sync'ing imsi", object=str(o), **o.tologdict())
        onos = ProgranHelpers.get_progran_onos_info()
        imsi_url = "http://%s:%s/onos/progran/imsi/" % (onos['url'], onos['port'])
        data = self.get_progran_imsi_field(o)
        r = requests.post(imsi_url, data=json.dumps(data), auth=HTTPBasicAuth(onos['username'], onos['password']))

        ProgranHelpers.get_progran_rest_errors(r)
        log.info("Profile synchronized", response=r.json())
Exemple #4
0
 def delete_record(self, o):
     log.info("deleting imsi", object=str(o), **o.tologdict())
     onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)
     profile_url = "http://%s:%s/onos/progran/imsi/%s" % (
         onos['url'], onos['port'], o.imsi_number)
     r = requests.delete(profile_url,
                         auth=HTTPBasicAuth(onos['username'],
                                            onos['password']))
     log.info("IMSI synchronized", response=r.json())
Exemple #5
0
 def delete_record(self, o):
     log.info("deleting enodeb", object=str(o), **o.tologdict())
     onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)
     enode_url = "http://%s:%s/onos/progran/enodeb/%s" % (
         onos['url'], onos['port'], o.enbId)
     r = requests.delete(enode_url,
                         auth=HTTPBasicAuth(onos['username'],
                                            onos['password']))
     ProgranHelpers.get_progran_rest_errors(r)
     log.info("enodeb deleted", response=r.json())
Exemple #6
0
    def delete_record(self, o):

        if o.provider_service_instance.leaf_model_name == "ProgranServiceInstance" and o.subscriber_service_instance.leaf_model_name ==  "MCordSubscriberInstance":
            log.info("deleting link", object=str(o), **o.tologdict())

            onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)

            profile_name = o.provider_service_instance.name
            imsi_number =  o.subscriber_service_instance.leaf_model.imsi_number

            url = "http://%s:%s/onos/progran/profile/%s/%s" % (onos['url'], onos['port'], profile_name, imsi_number)

            r = requests.delete(url, auth=HTTPBasicAuth(onos['username'], onos['password']))
            ProgranHelpers.get_progran_rest_errors(r)
Exemple #7
0
    def sync_record(self, o):

        if o.provider_service_instance.leaf_model_name == "ProgranServiceInstance" and o.subscriber_service_instance.leaf_model_name ==  "MCordSubscriberInstance":
            log.info("sync'ing link", object=str(o), **o.tologdict())

            onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)

            profile_name = o.provider_service_instance.name
            imsi_number =  o.subscriber_service_instance.leaf_model.imsi_number

            data = {
                "IMSIRuleArray": [
                    imsi_number
                ]
            }

            url = "http://%s:%s/onos/progran/profile/%s/imsi" % (onos['url'], onos['port'], profile_name)

            r = requests.post(url, data=json.dumps(data), auth=HTTPBasicAuth(onos['username'], onos['password']))
            ProgranHelpers.get_progran_rest_errors(r)
Exemple #8
0
    def call(self, failed=[], deletion=False):
        """
        Read profile from progran and save them in xos
        """

        if deletion == False:
            # NOTE we won't it to run only after the delete has completed
            return

        log.debug("Reading profiles from progran")
        onos = ProgranHelpers.get_progran_onos_info()
        profile_url = "http://%s:%s/onos/progran/profile/" % (onos['url'],
                                                              onos['port'])
        r = requests.get(profile_url,
                         auth=HTTPBasicAuth(onos['username'],
                                            onos['password']))
        res = r.json()['ProfileArray']

        # remove default profiles
        res = [p for p in res if "Default" not in p['Name']]
        pnames = [p['Name'] for p in res]
        log.debug("Received Profiles: ", profiles=pnames)

        field_mapping = {'Name': 'name', 'Start': 'start', 'End': 'end'}

        field_transformations = {
            'Start': ProgranHelpers.date_to_time,
            'End': ProgranHelpers.date_to_time
        }

        handover_mapping = {
            'A5Hysteresis': 'HysteresisA5',
            'A3Hysteresis': 'HysteresisA3'
        }

        updated_profiles = []

        for p in res:

            # checking for profiles
            try:
                si = ProgranServiceInstance.objects.get(name=p['Name'])
                log.debug("Profile %s already exists, updating it" % p['Name'])

            except IndexError:
                si = ProgranServiceInstance()

                si.created_by = "Progran"

                log.debug("Profile %s is new, creating it" % p['Name'])

            if not si.is_new:
                # update IMSI association
                xos_imsis_for_profile = [
                    i.subscriber_service_instance.leaf_model
                    for i in si.provided_links.all()
                ]
                progran_imsis_for_profile = p['IMSIRuleArray']

                log.debug("List of imsis for profile %s in XOS" % p["Name"],
                          imsis=xos_imsis_for_profile)
                log.debug("List of imsis for profile %s in ONOS" % p["Name"],
                          imsis=progran_imsis_for_profile)

                for i in xos_imsis_for_profile:
                    if not i.imsi_number in progran_imsis_for_profile:
                        log.debug("Removing Imsi %s from profile %s" %
                                  (i.imsi_number, p['Name']))

                        imsi_link = ServiceInstanceLink.objects.get(
                            subscriber_service_instance_id=i.id)

                        # NOTE: this model has already been removed from the backend, no need to synchronize
                        imsi_link.backend_need_delete = False
                        imsi_link.no_sync = True
                        imsi_link.save(
                        )  # we need to save it to avoid a synchronization loop

                        imsi_link.delete()
                    else:
                        # remove from imsi list coming from progran everything we already know about
                        progran_imsis_for_profile.remove(i.imsi_number)

                for i in progran_imsis_for_profile:
                    log.debug("Adding Imsi %s to profile %s" % (i, p['Name']))
                    imsi = MCordSubscriberInstance.objects.get(imsi_number=i)
                    imsi_to_profile = ServiceInstanceLink(
                        provider_service_instance=si,
                        subscriber_service_instance=imsi)
                    imsi_to_profile.save()

            # if the model has not been synchronized yet, skip it
            if not si.is_new and si.no_sync is False:
                log.debug("Skipping profile %s as not synchronized" %
                          p['Name'])
                # NOTE add it to the removed profiles to avoid deletion (this is ugly, I know)
                updated_profiles.append(si.name)
                continue

            si = ProgranHelpers.update_fields(si, p, field_mapping,
                                              field_transformations)

            # checking for handovers
            handover_dict = p['Handover']
            handover_dict = ProgranHelpers.convert_keys(
                handover_dict, handover_mapping)
            del p['Handover']

            if si.handover_id:
                handover = si.handover
                log.debug("handover already exists, updating it",
                          handover=handover_dict)
            else:
                handover = Handover()
                handover = ProgranHelpers.update_fields(
                    handover, handover_dict)
                log.debug("handover is new, creating it",
                          handover=handover_dict)
                handover.created_by = "Progran"

            handover = ProgranHelpers.update_fields(handover, handover_dict)
            handover.save()

            # Assigning handover to profile
            si.handover = handover

            si.backend_status = "OK"
            si.backend_code = 1

            si.no_sync = True
            si.previously_sync = True

            if p["MMECfg"]:
                si.mmeip = str(p["MMECfg"]["IPAddr"])
                si.mmeport = str(p["MMECfg"]["Port"])

            si.enacted = time.mktime(datetime.datetime.now().timetuple())

            si.save()

            updated_profiles.append(si.name)

        existing_profiles = [
            p.name for p in ProgranServiceInstance.objects.all()
            if not p.is_new
        ]
        deleted_profiles = ProgranHelpers.list_diff(existing_profiles,
                                                    updated_profiles)

        if len(deleted_profiles) > 0:
            for p in deleted_profiles:
                si = ProgranServiceInstance.objects.get(name=p)
                if si.created_by == 'XOS' and si.previously_sync == False:
                    # don't delete if the profile has been created by XOS and it hasn't been sync'ed yet
                    continue
                # TODO delete also the associated Handover
                log.debug(
                    "Profiles %s have been removed in progran, removing it from XOS"
                    % str(p))
                si.delete()
Exemple #9
0
    def call(self, failed=[], deletion=False):
        """
        Read profile from progran and save them in xos
        """

        if deletion == False:
            # NOTE we won't it to run only after the delete has completed
            return

        log.debug("Reading IMSI from progran")
        onos = ProgranHelpers.get_progran_onos_info(self.model_accessor)
        imsi_url = "http://%s:%s/onos/progran/imsi/" % (onos['url'],
                                                        onos['port'])
        r = requests.get(imsi_url,
                         auth=HTTPBasicAuth(onos['username'],
                                            onos['password']))
        res = r.json()['ImsiArray']

        log.debug("Received IMSIs: ", imsis=res)

        field_mapping = {'IMSI': 'imsi_number', 'UeStatus': 'ue_status'}

        field_transformations = {
            'UeStatus': ProgranHelpers.int_to_string,
        }

        updated_imsi = []

        for i in res:
            try:
                si = MCordSubscriberInstance.objects.get(imsi_number=i['IMSI'])
                log.debug("IMSI %s already exists, updating it" % i['IMSI'])
            except IndexError:
                si = MCordSubscriberInstance()

                si.no_sync = True
                si.backend_code = 1
                si.backend_status = "OK"
                si.created_by = "Progran"

                log.debug("IMSI %s is new, creating it" % i['IMSI'])

            si = ProgranHelpers.update_fields(si, i, field_mapping,
                                              field_transformations)

            si.save()

            updated_imsi.append(si.imsi_number)

        existing_imsi = [
            p.imsi_number for p in MCordSubscriberInstance.objects.all()
            if not p.is_new
        ]
        deleted_imsi = ProgranHelpers.list_diff(existing_imsi, updated_imsi)

        if len(deleted_imsi) > 0:
            log.debug(
                "Profiles %s have been removed in progran, removing them from XOS"
                % str(deleted_imsi))
            for p in deleted_imsi:
                si = MCordSubscriberInstance.objects.get(imsi_number=p)
                # if si.created_by == 'XOS' and si.previously_sync == False:
                # don't delete if the imsi has been created by XOS and it hasn't been sync'ed yet
                # continue
                si.delete()