onapsdk package

Subpackages

Submodules

onapsdk.constants module

Constant package.

onapsdk.exceptions module

ONAP Exception module.

exception onapsdk.exceptions.APIError

Bases: onapsdk.exceptions.RequestError

API error occured.

exception onapsdk.exceptions.ConnectionFailed

Bases: onapsdk.exceptions.RequestError

Unable to connect.

exception onapsdk.exceptions.FileError

Bases: onapsdk.exceptions.ValidationError

Reading in a file failed.

exception onapsdk.exceptions.InvalidResponse

Bases: onapsdk.exceptions.RequestError

Unable to decode response.

exception onapsdk.exceptions.ModuleError

Bases: onapsdk.exceptions.SDKException

Unable to import module.

exception onapsdk.exceptions.NoGuiError

Bases: onapsdk.exceptions.SDKException

No GUI available for this component.

exception onapsdk.exceptions.ParameterError

Bases: onapsdk.exceptions.SDKException

Parameter does not satisfy requirements.

exception onapsdk.exceptions.RelationshipNotFound

Bases: onapsdk.exceptions.ResourceNotFound

Required relationship is missing.

exception onapsdk.exceptions.RequestError

Bases: onapsdk.exceptions.SDKException

Request error occured.

exception onapsdk.exceptions.ResourceNotFound

Bases: onapsdk.exceptions.APIError

Requested resource does not exist.

exception onapsdk.exceptions.SDKException

Bases: Exception

Generic exception for ONAP SDK.

exception onapsdk.exceptions.SettingsError

Bases: onapsdk.exceptions.SDKException

Some settings are wrong.

exception onapsdk.exceptions.StatusError

Bases: onapsdk.exceptions.SDKException

Invalid status.

exception onapsdk.exceptions.ValidationError

Bases: onapsdk.exceptions.SDKException

Data validation failed.

onapsdk.onap_service module

ONAP Service module.

class onapsdk.onap_service.OnapService

Bases: abc.ABC

Mother Class of all ONAP services.

An important attribute when inheriting from this class is _jinja_env. it allows to fetch simply jinja templates where they are. by default jinja engine will look for templates in templates directory of the package. See in Examples to see how to use.

server

nickname of the server we send the request. Used in logs strings. For example, ‘SDC’ is the nickame for SDC server.

Type

str

headers

the headers dictionnary to use.

Type

Dict[str, str]

proxy

the proxy configuration if needed.

Type

Dict[str, str]

permanent_headers

optional dictionary of headers which could be set by the user and which are always added into sended request. Unlike the headers, which could be overrided on send_message call these headers are constant.

Type

Optional[Dict[str, str]]

class PermanentHeadersCollection(ph_dict=<factory>, ph_call=<factory>)

Bases: object

Collection to store permanent headers.

ph_call: List[Callable]
ph_dict: Dict[str, Any]
classmethod get_guis()

Return the list of GUI and its status.

headers: Dict[str, str] = {'Accept': 'application/json', 'Content-Type': 'application/json'}
permanent_headers: onapsdk.onap_service.OnapService.PermanentHeadersCollection = OnapService.PermanentHeadersCollection(ph_dict={}, ph_call=[])
proxy: Dict[str, str] = None
classmethod send_message(method, action, url, **kwargs)

Send a message to an ONAP service.

Parameters
  • method (str) – which method to use (GET, POST, PUT, PATCH, …)

  • action (str) – what action are we doing, used in logs strings.

  • url (str) – the url to use

  • exception (Exception, optional) – if an error occurs, raise the exception given instead of RequestError

  • **kwargs – Arbitrary keyword arguments. any arguments used by requests can be used here.

Raises
  • RequestError – if other exceptions weren’t caught or didn’t raise, or if there was an ambiguous exception by a request

  • ResourceNotFound – 404 returned

  • APIError – returned an error code within 400 and 599, except 404

  • ConnectionFailed – connection can’t be established

Return type

Optional[Response]

Returns

the request response if OK

classmethod send_message_json(method, action, url, **kwargs)

Send a message to an ONAP service and parse the response as JSON.

Parameters
  • method (str) – which method to use (GET, POST, PUT, PATCH, …)

  • action (str) – what action are we doing, used in logs strings.

  • url (str) – the url to use

  • exception (Exception, optional) – if an error occurs, raise the exception given

  • **kwargs – Arbitrary keyword arguments. any arguments used by requests can be used here.

Raises
  • InvalidResponse – if JSON coudn’t be decoded

  • RequestError – if other exceptions weren’t caught or didn’t raise

  • APIError/ResourceNotFound – send_message() got an HTTP error code

  • ConnectionFailed – connection can’t be established

  • RequestError – send_message() raised an ambiguous exception

Return type

Dict[Any, Any]

Returns

the response body in dict format if OK

server: str = None
static set_header(header=None)

Set the header which will be always send on request.

The header can be:
  • dictionary - will be used same dictionary for each request

  • callable - a method which is going to be called every time on request creation. Could be useful if you need to connect with ONAP through some API gateway and you need to take care about authentication. The callable shouldn’t require any parameters

  • None - reset headers

Parameters

header (Optional[Union[Dict[str, Any], Callable]]) – header to set. Defaults to None

Return type

None

static set_proxy(proxy)

Set the proxy for Onap Services rest calls.

Parameters

proxy (Dict[str, str]) – the proxy configuration

Examples

>>> OnapService.set_proxy({
...     'http': 'socks5h://127.0.0.1:8082',
...     'https': 'socks5h://127.0.0.1:8082'})
Return type

None

onapsdk.version module

Version module.

Module contents

ONAP SDK master package.