onapsdk.utils package

Submodules

onapsdk.utils.configuration module

Configuration package.

onapsdk.utils.configuration.components_needing_distribution()

Return the list of components needing distribution.

Return type:

List[str]

onapsdk.utils.headers_creator module

Header creator package.

onapsdk.utils.headers_creator.headers_aai_creator(base_header)

Create the right headers for AAI creator type.

Parameters:

base_header (Dict[str, str]) – the base header to use

Returns:

the needed headers

Return type:

Dict[str, str]

onapsdk.utils.headers_creator.headers_clamp_creator(base_header)

Create the right headers for CLAMP generic type.

base_header (Dict[str, str]): the base header to use data (str): payload data used to create an md5 content header

Returns:

the needed headers

Return type:

Dict[str, str]

onapsdk.utils.headers_creator.headers_msb_creator(base_header)

Create the right headers for MSB.

Parameters:

base_header (Dict[str, str]) – the base header to use

Returns:

the needed headers

Return type:

Dict[str, str]

onapsdk.utils.headers_creator.headers_sdc_artifact_upload(base_header, data)

Create the right headers for sdc artifact upload.

Parameters:
  • base_header (Dict[str, str]) – the base header to use

  • data (str) – payload data used to create an md5 content header

Returns:

the needed headers

Return type:

Dict[str, str]

onapsdk.utils.headers_creator.headers_sdc_creator(base_header, user='cs0008', authorization=None)

Create the right headers for SDC creator type.

Parameters:
  • base_header (Dict[str, str]) – the base header to use

  • user (str, optional) – the user to use. Default to cs0008

  • authorization (str, optional) – the basic auth to use. Default to “classic” one

Returns:

the needed headers

Return type:

Dict[str, str]

onapsdk.utils.headers_creator.headers_sdc_generic(base_header, user, authorization=None)

Create the right headers for SDC generic type.

Parameters:
  • base_header (Dict[str, str]) – the base header to use

  • user (str) – the user to use.

  • authorization (str, optional) – the basic auth to use. Default to “classic” one

Returns:

the needed headers

Return type:

Dict[str, str]

onapsdk.utils.headers_creator.headers_sdc_governor(base_header, user='gv0001', authorization=None)

Create the right headers for SDC governor type.

Parameters:
  • base_header (Dict[str, str]) – the base header to use

  • user (str, optional) – the user to use. Default to gv0001

  • authorization (str, optional) – the basic auth to use. Default to “classic” one

Returns:

the needed headers

Return type:

Dict[str, str]

onapsdk.utils.headers_creator.headers_sdc_operator(base_header, user='op0001', authorization=None)

Create the right headers for SDC operator type.

Parameters:
  • base_header (Dict[str, str]) – the base header to use

  • user (str, optional) – the user to use. Default to op0001

  • authorization (str, optional) – the basic auth to use. Default to “classic” one

Returns:

the needed headers

Return type:

Dict[str, str]

onapsdk.utils.headers_creator.headers_sdc_tester(base_header, user='jm0007', authorization=None)

Create the right headers for SDC tester type.

Parameters:
  • base_header (Dict[str, str]) – the base header to use

  • user (str, optional) – the user to use. Default to jm0007

  • authorization (str, optional) – the basic auth to use. Default to “classic” one

Returns:

the needed headers

Return type:

Dict[str, str]

onapsdk.utils.headers_creator.headers_sdnc_creator(base_header)

Create the right headers for SDNC.

Parameters:

base_header (Dict[str, str]) – the base header to use

Returns:

the needed headers

Return type:

Dict[str, str]

onapsdk.utils.headers_creator.headers_so_catelog_db_creator(base_header)

Create the right headers for SO creator type.

Parameters:

base_header (Dict[str, str]) – the base header to use

Returns:

the needed headers

Return type:

Dict[str, str]

onapsdk.utils.headers_creator.headers_so_creator(base_header)

Create the right headers for SO creator type.

Parameters:

base_header (Dict[str, str]) – the base header to use

Returns:

the needed headers

Return type:

Dict[str, str]

onapsdk.utils.jinja module

Jinja module.

onapsdk.utils.jinja.jinja_env()

Create Jinja environment.

jinja_env allow to fetch simply jinja templates where they are. by default jinja engine will look for templates in templates directory of the package. So to load a template, you just have to do:

Example: >>> template = jinja_env().get_template(‘vendor_create.json.j2’) >>> data = template.render(name=”vendor”)

See also

SdcElement.create() for real use

Returns:

the Jinja environment to use

Return type:

Environment

onapsdk.utils.mixins module

Mixins module.

class onapsdk.utils.mixins.WaitForFinishMixin

Bases: ABC

Wait for finish mixin.

Mixin with wait_for_finish method and two properties:
  • completed,

  • finished.

Can be used to wait for result of asynchronous tasks.

WAIT_FOR_SLEEP_TIME = 10
abstract property completed: bool

Store an information if object task is completed or not.

Returns:

True if object task is completed, False otherwise.

Return type:

bool

abstract property finished: bool

Store an information if object task is finished or not.

Returns:

True if object task is finished, False otherwise.

Return type:

bool

wait_for_finish(timeout=None)

Wait until object task is finished.

It uses time.sleep with WAIT_FOR_SLEEP_TIME value as a parameter to

wait unitl request is finished (object’s finished property is equal to True).

It runs another process to control time of the function. If process timed out

TimeoutError is going to be raised.

Parameters:

timeout (float, optional) – positive number, wait at most timeout seconds

Raises:

TimeoutError – Raised when function timed out

Returns:

True if object’s task is successfully completed, False otherwise

Return type:

bool

onapsdk.utils.tosca_file_handler module

Utils class.

onapsdk.utils.tosca_file_handler.get_modules_list_from_tosca_file(model)

Get the list of modules from tosca file.

Modules are stored on topology_template.groups TOSCA file section.

Parameters:

model (str) – the model retrieved from the tosca file at Vnf instantiation.

Returns:

a list of modules

Return type:

dict

onapsdk.utils.tosca_file_handler.get_parameter_from_yaml(parameter, config_file)

Get the value of a given parameter in file.yaml.

Parameter must be given in string format with dots Example: general.openstack.image_name

Parameters:
  • parameter (str) –

  • config_file (str) – configuration yaml file formtatted as string

Raises:

ParameterError – parameter not defined

Returns:

the value of the parameter

onapsdk.utils.tosca_file_handler.get_vf_list_from_tosca_file(model)

Get the list of Vfs of a VNF based on the tosca file.

Parameters:

model (str) – the model retrieved from the tosca file at Vnf instantiation

Returns:

a list of Vfs

Return type:

list

onapsdk.utils.tosca_file_handler.random_string_generator(size=6, chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')

Get a random String for VNF.

Parameters:
  • size (int) – the number of alphanumerical chars for CI

  • chars (str) – alphanumerical characters (ASCII uppercase and digits)

Returns:

a sequence of random characters

Return type:

str

Module contents

ONAP SDK utils package.

onapsdk.utils.get_zulu_time_isoformat()

Get zulu time in accepted by ONAP modules format.

Returns:

Actual Zulu time.

Return type:

str

onapsdk.utils.load_json_file(path_to_json_file)

Return json as string from selected file.

Parameters:

path_to_json_file (str) – (str) path to file with json

Return type:

str

Returns:

File content as string (str)