示例#1
0
    def Provision(self, urns, credentials, options):
        geni_best_effort = self._option(options, "geni_best_effort", ret=True)
        geni_users = self._option(options, "geni_users", ret=[])

        # Expiration in credentials
        expiration = geni_creds.get_cred_exp(logger, credentials[0]["geni_value"])
        # Expiration in slice
        slice_resources = db_sync_manager.get_slices(urns[0])
        # Convert expiration date in slice credential to expected datetime format
        try:
            # Expiration in slice (from Allocate reservation)
            expiration = slice_resources["slivers"]["geni_expires"]
            expiration = dates.rfc3339_to_datetime(expiration)
            expiration = dates.datetime_to_rfc3339(expiration)
        except:
            pass
        if "geni_end_time" in options:
            expiration = max(expiration, dates.rfc3339_to_datetime(options["geni_end_time"]))

        # TODO check the end_time against the duration of the credential
        try:
            self._checkRSpecVersion(options["geni_rspec_version"])
            r_rspec, r_sliver_list = self._delegate.provision(
                urns, self.requestCertificate(), credentials, geni_best_effort,
                expiration, geni_users)

            result = {"geni_rspec": r_rspec,
                      "geni_slivers": self._convertExpiresDate(r_sliver_list)}

        except Exception as e:
            return self._errorReturn(e)

        return self._successReturn(result)
示例#2
0
    def Allocate(self, slice_urn, credentials, rspec, options):
        """Delegates the call and unwraps the needed parameter.
        Also converts the incoming timestamp to python and the outgoing
        to geni compliant date format."""
        self.__validate_credentials(credentials)

        logger.debug("Allocate urn=%s, options=%s" % (slice_urn, options,))
        geni_end_time = None
        if "geni_end_time" in options:
            geni_end_time = dates.rfc3339_to_datetime(options["geni_end_time"])

        # TODO check the end_time against the duration of the credential
        try:
            # delegate
            # omni does not send this option
            # self._checkRSpecVersion(options["geni_rspec_version"])
            r_rspec, r_sliver_list = self._delegate.allocate(
                slice_urn, self.requestCertificate(),
                credentials, rspec, geni_end_time)

            # change datetimes to strings
            result = {"geni_rspec": r_rspec,
                      "geni_slivers": self._convertExpiresDate(r_sliver_list)}

        except Exception as e:
            return self._errorReturn(e)

        return self._successReturn(result)
示例#3
0
    def Allocate(self, slice_urn, credentials, rspec, options):
        """Delegates the call and unwraps the needed parameter.
        Also converts the incoming timestamp to python and the outgoing
        to geni compliant date format."""
        geni_end_time = None
        if "geni_end_time" in options:
            geni_end_time = dates.rfc3339_to_datetime(options["geni_end_time"])

        # TODO check the end_time against the duration of the credential
        try:
            # delegate
            # omni does not send this option
            # self._checkRSpecVersion(options["geni_rspec_version"])
            r_rspec, r_sliver_list = self._delegate.allocate(
                slice_urn, self.requestCertificate(),
                credentials, rspec, geni_end_time)

            # change datetime"s to strings
            result = {"geni_rspec": r_rspec,
                      "geni_slivers": self._convertExpiresDate(r_sliver_list)}

        except Exception as e:
            return self._errorReturn(e)

        return self._successReturn(result)
示例#4
0
    def Provision(self, urns, credentials, options):
        self.__validate_credentials(credentials)

        logger.debug("Provision urns=%s, options=%s" % (
            urns,
            options,
        ))
        geni_best_effort = self._option(options, "geni_best_effort")
        geni_users = options.get("geni_users", [])
        geni_end_time = None
        if "geni_end_time" in options:
            geni_end_time = dates.rfc3339_to_datetime(options["geni_end_time"])

        # TODO check the end_time against the duration of the credential
        try:
            self._checkRSpecVersion(options["geni_rspec_version"])
            r_rspec, r_sliver_list = self._delegate.provision(
                urns, self.requestCertificate(), credentials, geni_best_effort,
                geni_end_time, geni_users)

            result = {
                "geni_rspec": r_rspec,
                "geni_slivers": self._convertExpiresDate(r_sliver_list)
            }

        except Exception as e:
            return self._errorReturn(e)

        return self._successReturn(result)
示例#5
0
    def delete(self, urns, client_cert, credentials, best_effort):
        """
        Deletes the requested resources, identified each by an URN.
        When best_effort is enabled, deletion will be attempted on every
        resource.

        @param urns list of URNs with the identifiers of the resources to
            be treated
        @param client_cert client certificate (X509)
        @param credentials client credential(s), provided by the ClearingHouse
            and generated after the certificates
        @param best_effort flag to describe the behaviour upon a failure
                * best_effort = True : as much operations as possible are
                                       performed upon an error condition
                * best_effort = False : the set of operations will be stopped
                                        if an error occurs
        @return ro_slivers structure containing information of slivers (URN,
            expiration date, etc)
        """
        ro_slivers = []
        logger.info("best_effort=%s" % (best_effort,))

        route = db_sync_manager.get_slice_routing_keys(urns)
        logger.debug("Route=%s" % (route,))

        for r, v in route.iteritems():
            peer = db_sync_manager.get_configured_peer_by_routing_key(r)
            logger.debug("peer=%s" % (peer,))
            if peer.get("type") in self._allowed_peers.values():
                slivers = CommonUtils.manage_delete(
                    peer, v, credentials, best_effort)

                logger.debug("slivers=%s" % (slivers,))
                ro_slivers.extend(slivers)

        db_urns = []
        for s in ro_slivers:
            s["geni_expires"] = dates.rfc3339_to_datetime(s["geni_expires"])
            db_urns.append(s.get("geni_sliver_urn"))
        logger.debug("RO-Slivers(%d)=%s, DB-URNs(%d)=%s" %
                     (len(ro_slivers), ro_slivers, len(db_urns), db_urns))

        # update MS to stop slice-monitoring collection
        slice_urn = db_sync_manager.get_slice_urn(urns)

        if slice_urn:
            try:
                # MS needs to be sent the whole slice data in order to
                # delete it
                slice_monitor = SliceMonitoring()
                slice_monitor.delete_slice_topology(slice_urn)
            except Exception as e:
                logger.warning("Delegate could not send slice monitoring" +
                               " information upon Delete. Details: %s", (e,))
            db_sync_manager.delete_slice_sdn(slice_urn)

        db_sync_manager.delete_slice_urns(db_urns)
        self.__schedule_tnres_update(
            tn_resource_refresh, 1, "oneshot_tn_resource_refresh")
        return ro_slivers
示例#6
0
    def Provision(self, urns, credentials, options):
        self.__validate_credentials(list(credentials))
        # Append speaks-for cred
        credentials = credentials + self.__speaks_for_cred

        logger.debug("Provision urns=%s, options=%s" % (urns, options,))
        geni_best_effort = self._option(options, "geni_best_effort")
        geni_users = options.get("geni_users", [])
        geni_end_time = None
        if "geni_end_time" in options:
            geni_end_time = dates.rfc3339_to_datetime(options["geni_end_time"])

        # TODO check the end_time against the duration of the credential
        try:
            self._checkRSpecVersion(options["geni_rspec_version"])
            r_rspec, r_sliver_list = self._delegate.provision(
                urns, self.requestCertificate(), credentials, geni_best_effort,
                geni_end_time, geni_users)

            result = {"geni_rspec": r_rspec,
                      "geni_slivers": self._convertExpiresDate(r_sliver_list)}

        except Exception as e:
            return self._errorReturn(e)

        return self._successReturn(result)
示例#7
0
    def delete(self, urns, client_cert, credentials, best_effort):
        """
        Deletes the requested resources, identified each by an URN.
        When best_effort is enabled, deletion will be attempted on every
        resource.

        @param urns list of URNs with the identifiers of the resources to
            be treated
        @param client_cert client certificate (X509)
        @param credentials client credential(s), provided by the ClearingHouse
            and generated after the certificates
        @param best_effort flag to describe the behaviour upon a failure
                * best_effort = True : as much operations as possible are
                                       performed upon an error condition
                * best_effort = False : the set of operations will be stopped
                                        if an error occurs
        @return ro_slivers structure containing information of slivers (URN,
            expiration date, etc)
        """
        ro_slivers = []
        logger.info("best_effort=%s" % (best_effort, ))

        route = db_sync_manager.get_slice_routing_keys(urns)
        logger.debug("Route=%s" % (route, ))

        for r, v in route.iteritems():
            peer = db_sync_manager.get_configured_peer_by_routing_key(r)
            logger.debug("peer=%s" % (peer, ))
            if peer.get("type") in self._allowed_peers.values():
                slivers = CommonUtils.manage_delete(peer, v, credentials,
                                                    best_effort)

                logger.debug("slivers=%s" % (slivers, ))
                ro_slivers.extend(slivers)

        db_urns = []
        for s in ro_slivers:
            s["geni_expires"] = dates.rfc3339_to_datetime(s["geni_expires"])
            db_urns.append(s.get("geni_sliver_urn"))
        logger.debug("RO-Slivers(%d)=%s, DB-URNs(%d)=%s" %
                     (len(ro_slivers), ro_slivers, len(db_urns), db_urns))

        # update MS to stop slice-monitoring collection
        slice_urn = db_sync_manager.get_slice_urn(urns)

        if slice_urn:
            try:
                # MS needs to be sent the whole slice data in order to
                # delete it
                slice_monitor = SliceMonitoring()
                slice_monitor.delete_slice_topology(slice_urn)
            except Exception as e:
                logger.warning(
                    "Delegate could not send slice monitoring" +
                    " information upon Delete. Details: %s", (e, ))
            db_sync_manager.delete_slice_sdn(slice_urn)

        db_sync_manager.delete_slice_urns(db_urns)
        return ro_slivers
示例#8
0
    def Renew(self, urns, credentials, expiration_time_str, options):
        geni_best_effort = self._option(options, "geni_best_effort", ret=True)
        expiration_time = dates.rfc3339_to_datetime(expiration_time_str)
        try:
            # delegate
            result = self._delegate.renew(urns, self.requestCertificate(),
                                          credentials, expiration_time,
                                          geni_best_effort)
            # Change datetimes to strings (send result[1], aka slivers)
            result = self._convertExpiresDate(result[1])

        except Exception as e:
            return self._errorReturn(e)

        return self._successReturn(result)
示例#9
0
    def convert_sliver_dates_to_datetime(geni_slivers, geni_expires_value=None):
        """
        Given the GENI slivers structure, converts every 'geni_expires'
        field inside (in rfc3339) format to a datetime object. This is the
        expected output by CLI clients (e.g. OMNI).

        @param geni_slivers slivers structure, generated in delegate
        @param geni_expires_value valid rfc3339 date
        @return geni_slivers slivers structure, with date format modified
        """
        for s in geni_slivers:
            # The 'geni_expires_value' has precedence over the current value
            geni_expires = geni_expires_value or s["geni_expires"]
            if geni_expires is not None:
                s["geni_expires"] = dates.rfc3339_to_datetime(geni_expires)
        logger.debug("RO-Slivers(%d)=%s" % (len(geni_slivers), geni_slivers))
        return geni_slivers
示例#10
0
    def Renew(self, urns, credentials, expiration_time_str, options):
        self.__validate_credentials(credentials)

        logger.debug("Renew urns=%s, options=%s" % (urns, options,))
        geni_best_effort = self._option(options, "geni_best_effort")
        expiration_time = dates.rfc3339_to_datetime(expiration_time_str)
        try:
            # delegate
            result = self._delegate.renew(urns, self.requestCertificate(),
                                          credentials, expiration_time,
                                          geni_best_effort)
            # change datetimes to strings
            result = self._convertExpiresDate(result)

        except Exception as e:
            return self._errorReturn(e)

        return self._successReturn(result)
示例#11
0
    def convert_sliver_dates_to_datetime(geni_slivers,
                                         geni_expires_value=None):
        """
        Given the GENI slivers structure, converts every 'geni_expires'
        field inside (in rfc3339) format to a datetime object. This is the
        expected output by CLI clients (e.g. OMNI).

        @param geni_slivers slivers structure, generated in delegate
        @param geni_expires_value valid rfc3339 date
        @return geni_slivers slivers structure, with date format modified
        """
        for s in geni_slivers:
            # The 'geni_expires_value' has precedence over the current value
            geni_expires = geni_expires_value or s["geni_expires"]
            if geni_expires is not None:
                s["geni_expires"] = dates.rfc3339_to_datetime(geni_expires)
        logger.debug("RO-Slivers(%d)=%s" % (len(geni_slivers), geni_slivers))
        return geni_slivers
示例#12
0
    def Renew(self, urns, credentials, expiration_time_str, options):
        self.__validate_credentials(credentials)

        logger.debug("Renew urns=%s, options=%s" % (
            urns,
            options,
        ))
        geni_best_effort = self._option(options, "geni_best_effort")
        expiration_time = dates.rfc3339_to_datetime(expiration_time_str)
        try:
            # delegate
            result = self._delegate.renew(urns, self.requestCertificate(),
                                          credentials, expiration_time,
                                          geni_best_effort)
            # change datetimes to strings
            result = self._convertExpiresDate(result)

        except Exception as e:
            return self._errorReturn(e)

        return self._successReturn(result)