flaskext.xmlrpc.Fault

Here are the examples of the python api flaskext.xmlrpc.Fault taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

32 Examples 7

Example 1

Project: NIPAP Source File: xmlrpc.py
Function: remove_vrf
    @requires_auth
    def remove_vrf(self, args):
        """ Removes a VRF.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `vrf` [struct]
                A VRF spec.
        """
        try:
            self.nip.remove_vrf(args.get('auth'), args.get('vrf'))
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 2

Project: NIPAP Source File: xmlrpc.py
Function: remove_pool
    @requires_auth
    def remove_pool(self, args):
        """ Remove a pool.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `pool` [struct]
                Specifies what pool(s) to remove.
        """
        try:
            self.nip.remove_pool(args.get('auth'), args.get('pool'))
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 3

Project: NIPAP Source File: xmlrpc.py
Function: remove_prefix
    @requires_auth
    def remove_prefix(self, args):
        """ Remove a prefix.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `prefix` [struct]
                Attributes used to select what prefix to remove.
            * `recursive` [boolean]
                When set to 1, also remove child prefixes.
        """
        try:
            return self.nip.remove_prefix(args.get('auth'), args.get('prefix'), args.get('recursive'))
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 4

Project: NIPAP Source File: xmlrpc.py
    @requires_auth
    def find_free_prefix(self, args):
        """ Find a free prefix.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `args` [struct]
                Arguments for the find_free_prefix-function such as what prefix
                or pool to allocate from.
        """

        try:
            return self.nip.find_free_prefix(args.get('auth'), args.get('vrf'), args.get('args'))
        except NipapError as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 5

Project: NIPAP Source File: xmlrpc.py
Function: add_asn
    @requires_auth
    def add_asn(self, args):
        """ Add a new ASN.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `attr` [struct]
                ASN attributes.

            Returns the ASN.
        """

        try:
            return self.nip.add_asn(args.get('auth'), args.get('attr'))
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 6

Project: NIPAP Source File: xmlrpc.py
    @requires_auth
    def remove_asn(self, args):
        """ Removes an ASN.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `asn` [integer]
                An ASN.
        """

        try:
            self.nip.remove_asn(args.get('auth'), args.get('asn'))
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 7

Project: NIPAP Source File: xmlrpc.py
    @requires_auth
    def list_asn(self, args):
        """ List ASNs.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `asn` [struct]
                Specifies ASN attributes to match (optional).

            Returns a list of ASNs matching the ASN spec as a list of structs.
        """

        try:
            return self.nip.list_asn(args.get('auth'), args.get('asn') or {})
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 8

Project: NIPAP Source File: xmlrpc.py
    @requires_auth
    def edit_asn(self, args):
        """ Edit an ASN.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `asn` [integer]
                An integer specifying which ASN to edit.
            * `attr` [struct]
                ASN attributes.
        """

        try:
            return self.nip.edit_asn(args.get('auth'), args.get('asn'), args.get('attr'))
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 9

Project: NIPAP Source File: xmlrpc.py
Function: requires_auth
def requires_auth(f):
    """ Class decorator for XML-RPC functions that requires auth
    """
    @wraps(f)

    def decorated(self, *args, **kwargs):
        """
        """

        # Fetch auth options from args
        auth_options = {}
        nipap_args = {}

        # validate function arguments
        if len(args) == 1:
            nipap_args = args[0]
        else:
            self.logger.debug("Malformed request: got %d parameters" % len(args))
            raise Fault(1000, ("NIPAP API functions take exactly 1 argument (%d given)") % len(args))

        if type(nipap_args) != dict:
            self.logger.debug("Function argument is not struct")
            raise Fault(1000, ("Function argument must be XML-RPC struct/Python dict (Python %s given)." %
                type(nipap_args).__name__ ))

        # fetch auth options
        try:
            auth_options = nipap_args['auth']
            if type(auth_options) is not dict:
                raise ValueError()
        except (KeyError, ValueError):
            self.logger.debug("Missing/invalid authentication options in request.")
            raise Fault(1000, ("Missing/invalid authentication options in request."))

        # fetch authoritative source
        try:
            auth_source = auth_options['authoritative_source']
        except KeyError:
            self.logger.debug("Missing authoritative source in auth options.")
            raise Fault(1000, ("Missing authoritative source in auth options."))

        if not request.authorization:
            return authenticate()

        # init AuthFacory()
        af = AuthFactory()
        auth = af.get_auth(request.authorization.username,
                request.authorization.password, auth_source, auth_options or {})

        # authenticated?
        if not auth.authenticate():
            self.logger.debug("Incorrect username or password.")
            raise Fault(1510, ("Incorrect username or password."))

        # Replace auth options in API call arguments with auth object
        new_args = dict(args[0])
        new_args['auth'] = auth

        return f(self, *(new_args,), **kwargs)

    return decorated

Example 10

Project: NIPAP Source File: xmlrpc.py
Function: add_vrf
    @requires_auth
    def add_vrf(self, args):
        """ Add a new VRF.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `attr` [struct]
                VRF attributes.

            Returns the internal database ID for the VRF.
        """
        try:
            res = self.nip.add_vrf(args.get('auth'), args.get('attr'))

            # fugly cast from large numbers to string to deal with XML-RPC
            for val in ( 'num_prefixes_v4', 'num_prefixes_v6',
                'total_addresses_v4', 'total_addresses_v6',
                'used_addresses_v4', 'used_addresses_v6', 'free_addresses_v4',
                'free_addresses_v6'):
                res[val] = unicode(res[val])

            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 11

Project: NIPAP Source File: xmlrpc.py
Function: list_vrf
    @requires_auth
    def list_vrf(self, args):
        """ List VRFs.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `vrf` [struct]
                Specifies VRF attributes to match (optional).

            Returns a list of structs matching the VRF spec.
        """
        try:
            res = self.nip.list_vrf(args.get('auth'), args.get('vrf'))

            # fugly cast from large numbers to string to deal with XML-RPC
            for vrf in res:
                for val in ( 'num_prefixes_v4', 'num_prefixes_v6',
                    'total_addresses_v4', 'total_addresses_v6',
                    'used_addresses_v4', 'used_addresses_v6', 'free_addresses_v4',
                    'free_addresses_v6'):
                    vrf[val] = unicode(vrf[val])

            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 12

Project: NIPAP Source File: xmlrpc.py
Function: edit_vrf
    @requires_auth
    def edit_vrf(self, args):
        """ Edit a VRF.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `vrf` [struct]
                A VRF spec specifying which VRF(s) to edit.
            * `attr` [struct]
                VRF attributes.
        """
        try:
            res = self.nip.edit_vrf(args.get('auth'), args.get('vrf'), args.get('attr'))

            # fugly cast from large numbers to string to deal with XML-RPC
            for vrf in res:
                for val in ( 'num_prefixes_v4', 'num_prefixes_v6',
                    'total_addresses_v4', 'total_addresses_v6',
                    'used_addresses_v4', 'used_addresses_v6', 'free_addresses_v4',
                    'free_addresses_v6'):
                    vrf[val] = unicode(vrf[val])

            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 13

Project: NIPAP Source File: xmlrpc.py
    @requires_auth
    def search_vrf(self, args):
        """ Search for VRFs.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `query` [struct]
                A struct specifying the search query.
            * `search_options` [struct]
                Options for the search query, such as limiting the number
                of results returned.

            Returns a struct containing search result and the search options
            used.
        """
        try:
            res = self.nip.search_vrf(args.get('auth'), args.get('query'), args.get('search_options') or {})

            # fugly cast from large numbers to string to deal with XML-RPC
            for vrf in res['result']:
                for val in ( 'num_prefixes_v4', 'num_prefixes_v6',
                    'total_addresses_v4', 'total_addresses_v6',
                    'used_addresses_v4', 'used_addresses_v6', 'free_addresses_v4',
                    'free_addresses_v6'):
                    vrf[val] = unicode(vrf[val])

            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 14

Project: NIPAP Source File: xmlrpc.py
Function: smart_search_vrf
    @requires_auth
    def smart_search_vrf(self, args):
        """ Perform a smart search.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `query_string` [string]
                The search string.
            * `search_options` [struct]
                Options for the search query, such as limiting the number
                of results returned.

            Returns a struct containing search result, interpretation of the
            search string and the search options used.
        """
        try:
            res = self.nip.smart_search_vrf(args.get('auth'),
                    args.get('query_string'), args.get('search_options', {}),
                    args.get('extra_query'))

            # fugly cast from large numbers to string to deal with XML-RPC
            for vrf in res['result']:
                for val in ( 'num_prefixes_v4', 'num_prefixes_v6',
                    'total_addresses_v4', 'total_addresses_v6',
                    'used_addresses_v4', 'used_addresses_v6', 'free_addresses_v4',
                    'free_addresses_v6'):
                    vrf[val] = unicode(vrf[val])

            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 15

Project: NIPAP Source File: xmlrpc.py
Function: add_pool
    @requires_auth
    def add_pool(self, args):
        """ Add a pool.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `attr` [struct]
                Attributes which will be set on the new pool.

            Returns ID of created pool.
        """
        try:
            res = self.nip.add_pool(args.get('auth'), args.get('attr'))

            # fugly cast from large numbers to string to deal with XML-RPC
            for val in ( 'member_prefixes_v4', 'member_prefixes_v6',
                    'used_prefixes_v4', 'used_prefixes_v6', 'free_prefixes_v4',
                    'free_prefixes_v6', 'total_prefixes_v4',
                    'total_prefixes_v6', 'total_addresses_v4',
                    'total_addresses_v6', 'used_addresses_v4',
                    'used_addresses_v6', 'free_addresses_v4',
                    'free_addresses_v6'):
                if res[val] is not None:
                    res[val] = unicode(res[val])

            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 16

Project: NIPAP Source File: xmlrpc.py
Function: list_pool
    @requires_auth
    def list_pool(self, args):
        """ List pools.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `pool` [struct]
                Specifies pool attributes which will be matched.

            Returns a list of structs describing the matching pools.
        """
        try:
            res = self.nip.list_pool(args.get('auth'), args.get('pool'))

            # fugly cast from large numbers to string to deal with XML-RPC
            for pool in res:
                for val in ( 'member_prefixes_v4', 'member_prefixes_v6',
                        'used_prefixes_v4', 'used_prefixes_v6',
                        'free_prefixes_v4', 'free_prefixes_v6',
                        'total_prefixes_v4', 'total_prefixes_v6',
                        'total_addresses_v4', 'total_addresses_v6',
                        'used_addresses_v4', 'used_addresses_v6',
                        'free_addresses_v4', 'free_addresses_v6'):
                    if pool[val] is not None:
                        pool[val] = unicode(pool[val])

            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 17

Project: NIPAP Source File: xmlrpc.py
Function: edit_pool
    @requires_auth
    def edit_pool(self, args):
        """ Edit pool.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `pool` [struct]
                Specifies pool attributes to match.
            * `attr` [struct]
                Pool attributes to set.
        """
        try:
            res = self.nip.edit_pool(args.get('auth'), args.get('pool'), args.get('attr'))

            # fugly cast from large numbers to string to deal with XML-RPC
            for pool in res:
                for val in ( 'member_prefixes_v4', 'member_prefixes_v6',
                        'used_prefixes_v4', 'used_prefixes_v6', 'free_prefixes_v4',
                        'free_prefixes_v6', 'total_prefixes_v4',
                        'total_prefixes_v6', 'total_addresses_v4',
                        'total_addresses_v6', 'used_addresses_v4',
                        'used_addresses_v6', 'free_addresses_v4',
                        'free_addresses_v6'):
                    if pool[val] is not None:
                        pool[val] = unicode(pool[val])

            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 18

Project: NIPAP Source File: xmlrpc.py
    @requires_auth
    def search_pool(self, args):
        """ Search for pools.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `query` [struct]
                A struct specifying the search query.
            * `search_options` [struct]
                Options for the search query, such as limiting the number
                of results returned.

            Returns a struct containing search result and the search options
            used.
        """
        try:
            res = self.nip.search_pool(args.get('auth'), args.get('query'), args.get('search_options') or {})

            # fugly cast from large numbers to string to deal with XML-RPC
            for pool in res['result']:
                for val in ( 'member_prefixes_v4', 'member_prefixes_v6',
                        'used_prefixes_v4', 'used_prefixes_v6',
                        'free_prefixes_v4', 'free_prefixes_v6',
                        'total_prefixes_v4', 'total_prefixes_v6',
                        'total_addresses_v4', 'total_addresses_v6',
                        'used_addresses_v4', 'used_addresses_v6',
                        'free_addresses_v4', 'free_addresses_v6'):
                    if pool[val] is not None:
                        pool[val] = unicode(pool[val])

            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 19

Project: NIPAP Source File: xmlrpc.py
Function: smart_search_pool
    @requires_auth
    def smart_search_pool(self, args):
        """ Perform a smart search.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `query` [string]
                The search string.
            * `search_options` [struct]
                Options for the search query, such as limiting the number
                of results returned.

            Returns a struct containing search result, interpretation of the
            query string and the search options used.
        """
        try:
            res = self.nip.smart_search_pool(args.get('auth'),
                    args.get('query_string'), args.get('search_options') or {},
                    args.get('extra_query'))

            # fugly cast from large numbers to string to deal with XML-RPC
            for pool in res['result']:
                for val in ( 'member_prefixes_v4', 'member_prefixes_v6',
                        'used_prefixes_v4', 'used_prefixes_v6',
                        'free_prefixes_v4', 'free_prefixes_v6',
                        'total_prefixes_v4', 'total_prefixes_v6',
                        'total_addresses_v4', 'total_addresses_v6',
                        'used_addresses_v4', 'used_addresses_v6',
                        'free_addresses_v4', 'free_addresses_v6'):
                    if pool[val] is not None:
                        pool[val] = unicode(pool[val])

            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 20

Project: NIPAP Source File: xmlrpc.py
Function: add_prefix
    @requires_auth
    def add_prefix(self, args):
        """ Add a prefix.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `attr` [struct]
                Attributes to set on the new prefix.
            * `args` [srgs]
                Arguments for addition of prefix, such as what pool or prefix
                it should be allocated from.

            Returns ID of created prefix.
        """
        try:
            res = self.nip.add_prefix(args.get('auth'), args.get('attr'), args.get('args'))
            # mangle result
            res = _mangle_prefix(res)
            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 21

Project: NIPAP Source File: xmlrpc.py
Function: list_prefix
    @requires_auth
    def list_prefix(self, args):
        """ List prefixes.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `prefix` [struct]
                Prefix attributes to match.

            Returns a list of structs describing the matching prefixes.

            Certain values are casted from numbers to strings because XML-RPC
            simply cannot handle anything bigger than an integer.
        """
        try:
            res = self.nip.list_prefix(args.get('auth'), args.get('prefix') or {})
            # mangle result
            for prefix in res:
                prefix = _mangle_prefix(prefix)
            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 22

Project: NIPAP Source File: xmlrpc.py
Function: edit_prefix
    @requires_auth
    def edit_prefix(self, args):
        """ Edit prefix.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `prefix` [struct]
                Prefix attributes which describes what prefix(es) to edit.
            * `attr` [struct]
                Attribuets to set on the new prefix.
        """
        try:
            res = self.nip.edit_prefix(args.get('auth'), args.get('prefix'), args.get('attr'))
            # mangle result
            for prefix in res:
                prefix = _mangle_prefix(prefix)
            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 23

Project: NIPAP Source File: xmlrpc.py
Function: search_prefix
    @requires_auth
    def search_prefix(self, args):
        """ Search for prefixes.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `query` [struct]
                A struct specifying the search query.
            * `search_options` [struct]
                Options for the search query, such as limiting the number
                of results returned.

            Returns a struct containing the search result together with the
            search options used.

            Certain values are casted from numbers to strings because XML-RPC
            simply cannot handle anything bigger than an integer.
        """
        try:
            res = self.nip.search_prefix(args.get('auth'), args.get('query'), args.get('search_options') or {})
            # mangle result
            for prefix in res['result']:
                prefix = _mangle_prefix(prefix)
            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 24

Project: NIPAP Source File: xmlrpc.py
Function: smart_search_prefix
    @requires_auth
    def smart_search_prefix(self, args):
        """ Perform a smart search.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `query_string` [string]
                The search string.
            * `search_options` [struct]
                Options for the search query, such as limiting the number
                of results returned.
            * `extra_query` [struct]
                Extra search terms, will be AND:ed together with what is
                extracted from the query string.

            Returns a struct containing search result, interpretation of the
            query string and the search options used.

            Certain values are casted from numbers to strings because XML-RPC
            simply cannot handle anything bigger than an integer.
        """

        try:
            res = self.nip.smart_search_prefix(args.get('auth'),
                    args.get('query_string'), args.get('search_options') or {},
                    args.get('extra_query'))
            # mangle result
            for prefix in res['result']:
                prefix = _mangle_prefix(prefix)
            return res
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 25

Project: NIPAP Source File: xmlrpc.py
    @requires_auth
    def search_asn(self, args):
        """ Search ASNs.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `query` [struct]
                A struct specifying the search query.
            * `search_options` [struct]
                Options for the search query, such as limiting the number
                of results returned.

            Returns a struct containing search result and the search options
            used.
        """

        try:
            return self.nip.search_asn(args.get('auth'), args.get('query'), args.get('search_options') or {})
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 26

Project: NIPAP Source File: xmlrpc.py
    @requires_auth
    def smart_search_asn(self, args):
        """ Perform a smart search among ASNs.

            Valid keys in the `args`-struct:

            * `auth` [struct]
                Authentication options passed to the :class:`AuthFactory`.
            * `query_string` [string]
                The search string.
            * `search_options` [struct]
                Options for the search query, such as limiting the number
                of results returned.

            Returns a struct containing search result, interpretation of the
            search string and the search options used.
        """

        try:
            return self.nip.smart_search_asn(args.get('auth'),
                args.get('query_string'), args.get('search_options') or {},
                args.get('extra_query'))
        except (AuthError, NipapError) as exc:
            self.logger.debug(unicode(exc))
            raise Fault(exc.error_code, unicode(exc))

Example 27

Project: ocf Source File: gapi1.py
  def pub_ListResources (self, credentials, options):
    try:
      CredVerifier.checkValid(credentials, [])

      compressed = options.get("geni_compressed", False)
      urn = options.get("geni_slice_urn", None)

      if urn:
        CredVerifier.checkValid(credentials, "getsliceresources", urn)
        self.recordAction("listresources", credentials, urn)
        sliver_urn = GeniDB.getSliverURN(urn)
        if sliver_urn is None:
          raise Fault("ListResources", "Sliver for slice URN (%s) does not exist" % (urn))
        rspec = GeniDB.getManifest(sliver_urn)
      else:
        self.recordAction("listresources", credentials)
        rspec = foam.geni.lib.getAdvertisement()
      if compressed:
        zrspec = zlib.compress(rspec)
        rspec = base64.b64encode(zrspec)

      return rspec
    except ExpatError, e:
      self._log.error("Error parsing credential strings")
      e._foam_logged = True
      raise e
    except UnknownSlice, x:
      x.log(self._log, "Attempt to list resources on sliver for unknown slice %s" % (urn),
            logging.INFO)
      x._foam_logged = True
      raise x
    except xmlrpclib.Fault, x:
      # Something thrown via GCF, we'll presume it was something related to credentials
      self._log.info("GCF credential check failure.")
      self._log.debug(x, exc_info=True)
      x._foam_logged = True
      raise x
    except Exception, e:
      self._log.exception("Exception")
      raise e

Example 28

Project: ocf Source File: gapi1.py
  def pub_CreateSliver (self, slice_urn, credentials, rspec, users):
    user_info = {}
    try:
      if CredVerifier.checkValid(credentials, "createsliver"):
        self.recordAction("createsliver", credentials, slice_urn)
        try:
          cert = Certificate(request.environ['CLIENT_RAW_CERT'])
          user_info["urn"] = cert.getURN()
          user_info["email"] = cert.getEmailAddress()
          self._log.debug("Parsed user cert with URN (%(urn)s) and email (%(email)s)" % user_info)
        except Exception, e:
          self._log.exception("UNFILTERED EXCEPTION")
          user_info["urn"] = None
          user_info["email"] = None
        sliver = foam.geni.lib.createSliver(slice_urn, credentials, rspec, user_info)

        approve = foam.geni.approval.analyzeForApproval(sliver)
        style = ConfigDB.getConfigItemByKey("geni.approval.approve-on-creation").getValue()
        if style == foam.geni.approval.NEVER:
          approve = False
        elif style == foam.geni.approval.ALWAYS:
          approve = True
        if approve:
          pid = foam.task.approveSliver(sliver.getURN(), AUTO_SLIVER_PRIORITY)
          self._log.debug("task.py launched for approve-sliver (PID: %d)" % pid)

        data = GeniDB.getSliverData(sliver.getURN(), True)
        foam.task.emailCreateSliver(data)

        return GeniDB.getManifest(sliver.getURN())
      return
    except foam.geni.lib.RspecParseError, e:
      self._log.info(str(e))
      e._foam_logged = True
      raise e
    except foam.geni.lib.RspecValidationError, e:
      self._log.info(str(e))
      e._foam_logged = True
      raise e
    except foam.geni.lib.DuplicateSliver, ds:
      self._log.info("Attempt to create multiple slivers for slice [%s]" % (ds.slice_urn))
      ds._foam_logged = True
      raise ds
    except foam.geni.lib.UnknownComponentManagerID, ucm:
      raise Fault("UnknownComponentManager", "Component Manager ID specified in %s does not match this aggregate." % (ucm.cid))
    except (foam.geni.lib.UnmanagedComponent, UnknownNode), uc:
      self._log.info("Attempt to request unknown component %s" % (uc.cid))
      f = Fault("UnmanagedComponent", "DPID in component %s is unknown to this aggregate." % (uc.cid))
      f._foam_logged = True
      raise f
    except Exception, e:
      self._log.exception("Exception")
      raise e

Example 29

Project: ocf Source File: gapi1.py
  def pub_DeleteSliver (self, slice_urn, credentials):
    try:
      if CredVerifier.checkValid(credentials, "deletesliver", slice_urn):
        self.recordAction("deletesliver", credentials, slice_urn)
        if GeniDB.getSliverURN(slice_urn) is None:
          raise Fault("DeleteSliver", "Sliver for slice URN (%s) does not exist" % (slice_urn))

        sliver_urn = GeniDB.getSliverURN(slice_urn)
        data = GeniDB.getSliverData(sliver_urn, True)

        foam.geni.lib.deleteSliver(sliver_urn = sliver_urn)

        foam.task.emailGAPIDeleteSliver(data)

        return True
      return False
    except UnknownSlice, x:
      self._log.info("Attempt to delete unknown sliver for slice URN %s" % (slice_urn))
      x._foam_logged = True
      raise x
    except Exception, e:
      self._log.exception("Exception")
      raise e

Example 30

Project: ocf Source File: gapi1.py
  def pub_SliverStatus (self, slice_urn, credentials):
    try:
      if CredVerifier.checkValid(credentials, "sliverstatus", slice_urn):
        self.recordAction("sliverstatus", credentials, slice_urn)
        result = {}
        sliver_urn = GeniDB.getSliverURN(slice_urn)
        if not sliver_urn:
          raise Fault("SliverStatus", "Sliver for slice URN (%s) does not exist" % (slice_urn))
        sdata = GeniDB.getSliverData(sliver_urn, True)
        status = foam.geni.lib.getSliverStatus(sliver_urn)
        result["geni_urn"] = sliver_urn
        result["geni_status"] = status
        result["geni_resources"] = [{"geni_urn" : sliver_urn, "geni_status": status, "geni_error" : ""}]
        result["foam_status"] = sdata["status"]
        result["foam_expires"] = sdata["expiration"]
        result["foam_pend_reason"] = sdata["pend_reason"]
        return result
      return False
    except UnknownSlice, x:
      self._log.info("Attempt to get status on unknown sliver for slice %s" % (slice_urn))
      x._foam_logged = True
      raise x
    except Exception, e:
      self._log.exception("Exception")
      raise e

Example 31

Project: ocf Source File: legacyexpedientapi.py
  def priv_CreateSliver(self, slice_urn, credentials, rspec, users, force_approval=False, options=None):	
    #user_info = {}
    user_info = users
    try:
      #if CredVerifier.checkValid(credentials, "createsliver"):
      if True:
        self.recordAction("createsliver", credentials, slice_urn)
        try:
          #cert = Certificate(request.environ['CLIENT_RAW_CERT'])
          #user_info["urn"] = cert.getURN()
          #user_info["email"] = cert.getEmailAddress()
          self._log.debug("Parsed user cert with URN (%(urn)s) and email (%(email)s)" % users)
        except Exception, e:
          self._log.exception("UNFILTERED EXCEPTION")
          user_info["urn"] = None
          user_info["email"] = None
        from foam.app import admin_apih
        if not admin_apih.vlan_automation_on:
          sliver = foam.geni.lib.createSliver(slice_urn, credentials, rspec, user_info)
          style = ConfigDB.getConfigItemByKey("geni.approval.approve-on-creation").getValue()
          if style == foam.geni.approval.NEVER:
            approve = False
          elif style == foam.geni.approval.ALWAYS:
            approve = True
          else:
            approve = foam.geni.ofeliaapproval.of_analyzeForApproval(sliver)
          if approve or force_approval:
            pid = foam.task.approveSliver(sliver.getURN(), AUTO_SLIVER_PRIORITY)
            self._log.debug("task.py launched for approve-sliver (PID: %d)" % pid)	
        else:
          free_vlan_list = self.pub_get_offered_vlans(1)
          free_vlan = free_vlan_list[0]
          slice_id = slice_urn.split("+slice+")[1].split(":")[0].split("id_")[1].split("name_")[0]
          #filedir = './opt/ofelia/ofam/local/db'
          #filename = os.path.join(filedir, 'expedient_slices_info.json')
          #f = open(filename, 'r')
          #self.slice_info_dict = json.load(f)
          #f.close()
          if (slice_id == "") or (slice_id not in self.slice_info_dict): 
            self._log.exception("The slice id you specified is non-existent")
            raise Exception
          updated_slice_info_dict = self.slice_info_dict.copy()
          for sliv_pos, sliver in enumerate(self.slice_info_dict[slice_id]['switch_slivers']):
            for sfs_pos, sfs in enumerate(sliver['flowspace']):   
              updated_slice_info_dict[slice_id]['switch_slivers'][sliv_pos]['flowspace'][sfs_pos]['vlan_id_start'] = free_vlan
              updated_slice_info_dict[slice_id]['switch_slivers'][sliv_pos]['flowspace'][sfs_pos]['vlan_id_end'] = free_vlan
          all_efs = self.create_slice_fs(updated_slice_info_dict[slice_id]['switch_slivers'])
          new_slice_of_rspec = create_ofv3_rspec(slice_id, updated_slice_info_dict[slice_id]['project_name'], updated_slice_info_dict[slice_id]['project_desc'], \
                                      updated_slice_info_dict[slice_id]['slice_name'], updated_slice_info_dict[slice_id]['slice_desc'], \
                                      updated_slice_info_dict[slice_id]['controller_url'], updated_slice_info_dict[slice_id]['owner_email'], \
                                      updated_slice_info_dict[slice_id]['owner_password'], \
                                      updated_slice_info_dict[slice_id]['switch_slivers'], all_efs)
          self.slice_info_dict = updated_slice_info_dict.copy()
          sliver = foam.geni.lib.createSliver(slice_urn, credentials, new_slice_of_rspec, user_info)
          pid = foam.task.approveSliver(sliver.getURN(), AUTO_SLIVER_PRIORITY)
          self._log.debug("task.py launched for approve-sliver (PID: %d)" % pid)
        data = GeniDB.getSliverData(sliver.getURN(), True)
        foam.task.emailCreateSliver(data)
        return self.successResult(GeniDB.getManifest(sliver.getURN()))
      return
		
    except foam.geni.lib.RspecParseError, e:
      self._log.info(str(e))
      e._foam_logged = True
      raise e
    except foam.geni.lib.RspecValidationError, e:
      self._log.info(str(e))
      e._foam_logged = True
      raise e
    except foam.geni.lib.DuplicateSliver, ds:
      self._log.info("Attempt to create multiple slivers for slice [%s]" % (ds.slice_urn))
      ds._foam_logged = True
      raise ds
    except foam.geni.lib.UnknownComponentManagerID, ucm:
      raise Fault("UnknownComponentManager", "Component Manager ID specified in %s does not match this aggregate." % (ucm.cid))
    except (foam.geni.lib.UnmanagedComponent, UnknownNode), uc:
      self._log.info("Attempt to request unknown component %s" % (uc.cid))
      f = Fault("UnmanagedComponent", "DPID in component %s is unknown to this aggregate." % (uc.cid))
      f._foam_logged = True
      raise f
    except Exception, e:
      self._log.exception("Exception")
      raise e

Example 32

Project: ocf Source File: legacyexpedientapi.py
  def priv_DeleteSliver(self, slice_urn, credentials, options=None):
    try:
      #if CredVerifier.checkValid(credentials, "deletesliver", slice_urn):
      if True:
        self.recordAction("deletesliver", credentials, slice_urn)
        if GeniDB.getSliverURN(slice_urn) is None:
          raise Fault("DeleteSliver", "Sliver for slice URN (%s) does not exist" % (slice_urn))
          return self.errorResult(12, "") #not sure if this is needed
        sliver_urn = GeniDB.getSliverURN(slice_urn)
        data = GeniDB.getSliverData(sliver_urn, True)
        foam.geni.lib.deleteSliver(sliver_urn = sliver_urn)
        foam.task.emailGAPIDeleteSliver(data)
        return self.successResult(True)
      return self.successResult(False)
		
    except UnknownSlice, x:
      self._log.info("Attempt to delete unknown sliver for slice URN %s" % (slice_urn))
      x._foam_logged = True
      raise x 
    except Exception, e:
      self._log.exception("Exception")
      raise e