Code documentation

cvpConfigletUploader.action_add(configlet_def, parameters)[source]

Manage actions to ADD a configlet.

Create CVP connection and instantiate a CvpConfiglet object Then call appropriate method to start object creation If apply option is set to true, then, generated tasks are applied by CVP. Otherwise, user has to do it manually

Parameters option should at least contain following elements: - username - password - cvp (server IP or DNS hostname)

Parameters:
  • configlet_def (dict) – Data from JSON to describe configlet
  • parameters (dict) – Object with all information to create connection
cvpConfigletUploader.action_update(configlet_def, parameters)[source]

Manage actions to UPDATE and existing configlet.

Create CVP connection and instantiate a CvpConfiglet object Then call appropriate method to start object update And finally run tasks

Parameters option should at least contain following elements:
  • username
  • password
  • cvp (server IP or DNS hostname)
Parameters:
  • configlet_def (dict) – Data from JSON to describe configlet
  • parameters (dict) – Object with all information to create connection
cvpConfigletUploader.action_delete(configlet_def, parameters)[source]

Manage actions to DELTE a configlet.

Create CVP connection and instantiate a CvpConfiglet object Then call appropriate method to start object deletion

Parameters option should at least contain following elements:
  • username
  • password
  • cvp (server IP or DNS hostname)
Parameters:
  • configlet_def (dict) – Data from JSON to describe configlet
  • parameters (dict) – Object with all information to create connection
cvpConfigletUploader.action_create_change_control(parameters, data)[source]

Create a Change-Control.

Create a change-control on CVP based on a JSON definition. Current version supports following entries in JSON: - name: change-control name configured on CVP - type: change-control (Must be set with this vaue to engage CC) - country: Country required by CVP for CC - timezone: Timezone required by CVP to run changes

Expected inputs data JSON file:

[
    {
        "name": "Python_CC",
        "type": "change-control",
        "country": "France",
        "timezone": "Europe/Paris"
    }
]

Todo

Manage way to retrieve Template ID / As feature is not part of CVPRAC, snapid shall be part of the job definition. If not, then we configure it to None

Parameters:
  • configlet_def (dict) – Data from JSON to describe configlet
  • parameters (dict) – Object with all information to create connection

Inventory Class

class cvpConfigletUploader.CvpInventory(cvp_server)[source]

Bases: object

CVP Inventory Class.

Get complete inventory from CVP and expose some functions to get data. It is RO only and nothing is pushed to CVP with this object.

__init__(cvp_server)[source]

Class Constructor.

Instantiate an Inventory with a REST call to get device list

Parameters:cvp_server (cvprack.CvpClient()) – Your CVP Rack server
get_device_dict(name)[source]

Get information for a give device.

Parameters:name (str) – Hostname to lookup
Returns:Complete dictionnary sent by CVP
Return type:dict
get_devices()[source]

Give a dict of all devices.

Returns:dict
Return type:All devices attached to CVP inventory

Configlet Class

class cvpConfigletUploader.CvpConfiglet(cvp_server, configlet_file=None, configlet_name=None)[source]

Bases: object

Configlet class to provide generic method to manage CVP configlet.

Data Structure

Configlet structure is a name based dictionnary with following keys:

  • name: Name of configlet. This name is built from filename
  • file: Complete path of the local configlet file
  • content: Local Configlet content read from configlet['file']
  • key: Key ID defined by CVP to identify configlet.
    it is found by our instance during update, addition or deletion
  • devices: List of devices structure compliant
    with CvpApi.get_device_by_name() It can be found by using CvpInventory object.

List of attributes:

_cvp_server

cvprac.CvpClient() object to manage CVP connection

_devices_configlet

List of devices attached to configlet

_configlet

Dictionary with all configlet information: name, file, content, key, devices

_cvp_found

Boolean to get status of configlet on CVP: True if configlet is on server, False other cases

List of Available methods:

get_devices()[source]

Get list of devices for this specific configlet

update_configlet()[source]

Start update process for that configlet. Do not deploy content to devices

deploy_configlet()[source]

Start configlet creation process. Do not deploy content to devices

delete_configlet()[source]

Start configlet deletion process. Do not deploy content to devices

deploy()[source]

Deploy (add/update) change to a single device

deploy_bulk()[source]

Deploy (add/update) change to all devices

on_cvp()[source]

Inform about configlet available on CVP

Note

This class use call to cvprac to get and push data to CVP server.

__init__(cvp_server, configlet_file=None, configlet_name=None)[source]

Class Constructor.

Parameters:
  • cvp_server (CvpClient) – CvpClient object from cvprack. Gives methods to manage CVP API
  • configlet_file (str) – Path to configlet file.
_configlet_init()[source]

Create an empty dict for configlet.

_configlet_lookup()[source]

Check if a configlet is already present on CVP.

Check if CVP has already a configlet configured with the same name. If yes return True and report key under self._configlet[‘key’] If no, return False

Returns:Return True or False if configlet name is already configured on CVP
Return type:bool
_retireve_devices()[source]

Get list of devices attached to the configlet.

If configlet exists, then, retrieve a complete list of devices attached to it.

Returns:List of devices from CVP
Return type:list
_task_init()[source]

Create an empty dict for task.

_wait_task(task_id, timeout=10)[source]

Wait for Task execution.

As API call is asynchronous, task will run avec after receiving a status. This function implement a wait_for to get final status of a task As we have to protect against application timeout or task issue, a basic timeout has been implemented

Parameters:
  • task_id (str) – ID of the task provided by self._get_task_id()
  • timeout (int) – optional - Timeout to wait for before assuming task failed
  • Returns
  • --------
  • dict – Last status message collected from the server
add_device(device_hostnames)[source]

Remove device(s) from a configlet.

Remove device from configlet and create a task on CVP to remove configuration generated by configlet from device. For every hostname defined in devices_hostnames, a lookup is done to get a complete data set for that device and a call to remove device is sent.

Warning

This function never send a call to execute task. it is managed by logic out of that object

Arguments:
devices_hostnames {list} – List of devices hostname to remove from
the configlet.
delete_configlet()[source]

Delete a configlet from CVP.

To protect, function first check if configlet exists, if not, we stop and return to next action out of this function. Remove configlet from all devices where it is configured Then if configlet exist, remove configlet from CVP DB

Returns:True if able to remove configlet / False otherwise
Return type:bool
deploy(device, schedule_at=None, task_timeout=10)[source]

Deploy One configlet to One device.

This function manage a deployment this configlet to a given device already attached to the configlet.

Parameters:
  • device (dict) – dict representing a device
  • schedule_at (str) – Optional - scheduler to run deployment at a given time
  • task_timeout (int) – Optional - Timeout for task execution default is 10 seconds

Warning

schedule_at option is not yet implemented and shall not be used

Returns:message from server
Return type:dict
deploy_bulk(device_list=None, schedule_at=None, task_timeout=10)[source]

Run configlet deployment against all devices.

Run configlet deployment over all devices attached to this configlet. Every single deployment are managed by function self.deploy()

Parameters:
  • device_list (list) – List of devices if it is set to None, then, fallback is to use devices discover initially
  • at (str) – Optional scheduler to run deployment at a given time
  • task_timeout (int) – Optional - Timeout for task execution. Default is 10 seconds

Warning

schedule_at option is not yet implemented and shall not be used

Returns:A list of tasks executed for the deployment
Return type:list
deploy_configlet(device_hostnames)[source]

Create configlet on CVP with content from object.

Create a new configlet on CVP server and attached it to all devices you provide in your JSON file. Device attachement is managed with a CvpInventory call to get all information from CVP. It means you just have to provide existing hostname in your JSON

Each time a device is attached to configlet on CVP, it is also added in CvpConfiglet object for futur use

Parameters:devices_hostname (list) – List of hostname to attached to configlet
get_configlet_info()[source]

To share configlet information.

Returns:dictionnary with configlet information
Return type:dict
get_devices(refresh=False)[source]

To share list of devices attached to the configlet.

If list is empty or if refresh trigger is active, function will get a new list of device from self._retireve_devices() Otherwise, just send back list to the caller

Parameters:refresh (bool) – Update device list from CVP (Optional)
Returns:List of devices from CVP
Return type:list
name()[source]

Expose name of the configlet.

Returns:Name of configlet built by __init__
Return type:str
on_cvp()[source]

Expose flag about configlet configured on CVP.

Return True if configlet is configured on CVP and can be updated. If configlet is not present, then, False

Returns:True if configlet already configured on CVP, False otherwise
Return type:bool
remove_device(devices_hostnames)[source]

Remove device(s) from a configlet.

Remove device from configlet and create a task on CVP to remove configuration generated by configlet from device. For every hostname defined in devices_hostnames, a lookup is done to get a complete data set for that device and a call to remove device is sent.

Warning

This function never send a call to execute task. it is managed by logic out of that object

Arguments:
devices_hostnames {list} – List of devices hostname to remove from
the configlet.
update_configlet()[source]

Update configlet on CVP with content from object.

Check if configlet is configured on CVP server before pushing an update. If configlet is not there, then, stop method execution.

Returns:str
Return type:message from server with result

Change Control Class

class cvpConfigletUploader.CvpChangeControl(cvp_server, name='Automated_Change_Control')[source]

Bases: object

Change-control class to provide generic method for CVP CC mechanism.

Change Control structure is based on:
  • A name to identify change
  • A list of tasks already created on CVP and on pending state
  • An optional scheduling. If no schedule is defined,
    then task will be run 3 minutes after creatio of CC

List of Available methods:

add_task()[source]

Append a task to self._list_changes

get_tasks()[source]

Return list of of available tasks for this CC

get_list_changes()[source]

Return list of tasks attached to this CC

create()[source]

Create change-control on CVP server

Todo

  • Implement a way to get snapshot IDs based on name

Warning

  • Change Control execution is not running snapshot before and after
__init__(cvp_server, name='Automated_Change_Control')[source]

Class Constructor.

Build class content with followinactivities:
  • save cvp_server information
  • save name for CC
  • instanciate list for tasks
  • Collect tasks available from CVP
Parameters:
  • cvp_server (CvpClient) – CVP Server information
  • name (str) – Optional - Name of the Change Control. Default is Automated_Change_Control
_build_change_dictionnary(order_mode='linear')[source]

Build ordered list to schedule changes.

CVP Change Control expect a list with an order to run tasks. By default, all tasks are executed at the same time. But using order_mode set to incremental every task will be scheduled sequentially in this change-control

Parameters:order_mode (str) – Optional - Method to build task list. Shall be linear or incremental.

Note

Only linear has been tested.

_retrieve_tasks()[source]

Extract tasks from CVP Server.

Connect to CVP server and collect tasks in pending state These tasks are saved in self._available structure dedicated to pending tasks.

add_task(task)[source]

Add a tasks to available list.

This task attach this new tasks to the pending tasks list.

Parameters:task (str) – TaskID from CVP server
create(mode='linear', country='France', tz='Europe/Paris', schedule=False, schedule_at='', snap_template='1708dd89-ff4b-4d1e-b09e-ee490b3e27f0', change_type='Custom', stop_on_error='true')[source]

Create a change-control.

Parameters:
  • mode (str) – Optional - method to order tasks (default : linear)
  • country (str) – Optional - Country requested by CVP API (default:France)
  • tz (str) – Optional - Timezone required by CVP (default: Europe/Paris)
  • schedule (bool) – Optional - Enable CC scheduling (default: False)
  • schedule_at (str) – Optional - Time to execute CC if scheduled
  • snap_template (str) – Optional - Snapshot template ID to run before / after tasks
  • change_type (str) – Optional - CVP definition for CC Might be Custom or Rollback. (default: Custom)
  • stop_on_error (str) – Optional - boolean string to stop CVP on errors
Returns:

CVP creation result (None if error occurs)

Return type:

dict

get_list_changes(mode='linear')[source]

Return list of tasks and their execution order.

Parameters:mode (str) – Information about tasks scheduling. Shall be linear or incremental.

Note

Only linear has been tested.

Returns:List of changes and their order
Return type:list
get_tasks(refresh=False)[source]

Provide list of all available tasks.

Return list of all tasks getting from CVP and/or attached with add_task method.

Parameters:refresh (bool) – Optional - Make a call to CVP to get latest list of tasks
Returns:List of available tasks found in this CC
Return type:list