def send_verification(notify_uri):
            notification = Notification(
                verificationRequest=True,
                creator=self.request.originator
            )

            send_notify_request = OneM2MRequest(OneM2MOperation.notify,
                                                notify_uri, None,
                                                MetaInformation(None),
                                                notification)
            return self.api.send_onem2m_request(send_notify_request)
Esempio n. 2
0
        def update_announce_to():
            # update_req_ind = UpdateRequestIndication(resource.path +
            #                                         '/announceTo', resource,
            #                                         fields=['announceTo'],
            #                                         do_announce=False)

            # self.api.handle_request_indication(update_req_ind)
            # TODO_oneM2M: Update the resource by sending the request
            cse_req = OneM2MRequest(OneM2MOperation.update, resource.path, str(self),
                                    MetaInformation(None), cn=resource,
                                    ty=resource)
Esempio n. 3
0
        def send_delete_annc(cse_uri):
            # * requestingEntity is set to the application;
            # req_ent from from outer scope

            # * issuer is set to its own CSE ID (the local CSE performing the
            # action);
            # rst: not needed probably

            # * targetID is set to the resource URI of the previously
            # announced-resource on the remote CSE. The local CSE received and
            # stored the URI of the announced resource after it was created.
            self.logger.debug("announcements %s" % self._announcements)
            annc_path = self._announcements[resource.path]['uris'][cse_uri]
            target_id = urljoin(cse_uri, '/onem2m/' + annc_path)

            cse_req = OneM2MRequest(OneM2MOperation.delete, target_id, None,
                                    MetaInformation(None))
            self.logger.debug('Deleting Announcement %s' % cse_req)
            return self.api.send_onem2m_request(cse_req)
Esempio n. 4
0
 def get_cse(cse):
     cse_req = OneM2MRequest(OneM2MOperation.retrieve, cse, None,
                             MetaInformation(None))
     return (self.api.handle_onem2m_request(cse_req)
             .then(lambda r: r.resource))
Esempio n. 5
0
        def send_create_annc(cse_uri, local_ar=None):
            annc = annc_model()
            # endpoint = self.api.get_endpoint('mid', urlparse(cse_uri).scheme)
            endpoint = self.config.get('endpoint', '')

            # * labels from the original resource;
            annc.labels = resource.labels

            # * accessRightID from the original resource;
            if local_ar:
                annc.accessRightID = urljoin(endpoint, urlparse(
                    resource.accessRightID).path)
            elif local_ar is None:
                annc.accessRightID = local_ar
            else:
                annc.accessRightID = resource.accessRightID

            # * link is set to the URI of the original resource;
            annc.link = urljoin(endpoint, resource.path)
            # annc.link = self._cse_base + resource.path

            # * requestingEntity is set to the application;
            # req_ent from from outer scope

            # * issuer is set to its own CSE ID (the local CSE performing the
            # action);
            # rst: not needed probably

            # * id of the resource shall be set to the id of the original
            # resource postfixed with Annc. I.e. if the original resource has id
            # "myApp", the announced resource shall have the id "myAppAnnc";
            annc.AE_ID = annc_id
            annc.name = annc_id

            # * expirationTime handling is to the discretion of the CSE
            # implementation. It is the responsibility of the local CSE to keep
            # the announced resource in sync with the lifetime of the original
            # resource, as long as the announcement is active. One strategy to
            # minimize signalling would be to request the same expiration from
            # the original resource. If this is accepted by the remote CSE, then
            # no explicit de-announce is needed in case of expiration of the
            # original resource;
            annc.expirationTime = resource.expirationTime

            # * targetID is set as follow.
            # RODO: inline
            def get_target_id():
                cse_path = cse_uri  # + '/cses/' + self.config['global']['cse_id']
                apps_path = self._cse_base  # + '/applications/'
                if resource.typename == 'AE':  # 'application':  # is appAnnc
                    return cse_path  # + '/applications/'
                else:
                    # TODO_oneM2M: Translate to onem2m
                    parent = sub(r'^locationC', 'c', resource.typename) + 's/'
                    if resource.path.find(apps_path) == 0:  # is under appAnnc
                        # todo: lookup appAnnc in self._announcements
                        return cse_path + '/applications/' + \
                               sub(apps_path, '', resource.path).split('/')[0] + \
                               'Annc/' + parent
                    else:  # is other Annc
                        return cse_path + '/' + parent

            target_id = get_target_id()
            # try:
            #    req_ent_mid = urljoin(endpoint, urlparse(req_ent).path)
            # except AttributeError:
            #    self.logger.exception("Could not midify")
            #    req_ent_mid = None
            req_ent_mid = None

            # create_annc_req_ind =\
            #    CreateRequestIndication(target_id, annc,
            #                            requestingEntity=req_ent_mid)
            #
            # return self.api.send_request_indication(create_annc_req_ind)
            cse_req = OneM2MRequest(OneM2MOperation.create, target_id, req_ent_mid,
                                    MetaInformation(None), cn=annc, ty=annc_id)
            self.logger.debug('Sending Announcement %s' % cse_req)
            return self.api.send_onem2m_request(cse_req)