APIC-EM Base Connection¶
-
class
ApicEmBase
(url, username=None, password=None, api_base_path='/api/v1', verify_ssl=True, DEBUG=False)¶ Bases:
nuaal.connections.api.RestBase.RestBase
Object providing access to Cisco’s APIC-EM REST-API.
Parameters: - url – URL of the APIC-EM, such as ‘https://sandboxapicem.cisco.com’
- username – Username for authentication
- password – Password for authentication
- api_base_path – Base path for version-1 API
- verify_ssl – Enable/disable verification of SSL Certificate
- DEBUG – Enable/disable debugging output
Function for obtaining authorization “Service Ticket” from the APIC-EM. This function is called when HTTP Status Code 401 (Unauthorized) is returned.
Returns: None
-
_load_credentials
()¶ Function for loading credentials information stored in data/apicem_credentials.json file.
Returns: None
-
_store_credentials
()¶ Function for storing credentials information in data/apicem_credentials.json file. This function is called after successfully obtaining Service Ticket
Returns: None
-
check_file
(fileId=None, namespace=None, file_name=None)¶ Function for checking whether given file (based on it’s name or ID) exists on the APIC-EM. Can be used for checking configuration or template files.
Parameters: - fileId (str) – ID string of the file in APIC-EM’s database
- namespace (str) – APIC-EM’s namespace, under which the file should be located
- file_name (str) – Name of the file
Return str: FileID
-
delete
(path, params=None)¶ Parameters: - path (str) – Path of API resource
- params (dict) – Dictionary of parameters for request
Returns: Dictionary representation of response
-
delete_file
(fileId=None, namespace=None, filename=None)¶ Function for deleting file from APIC-EM’s database based on it’s ID
Parameters: - fileId (str) – ID string of the file in APIC-EM’s database
- namespace (str) – APIC-EM’s namespace, under which the file should be located
- filename (str) – Name of the file
Return bool:
-
get
(path, params=None)¶ Function providing HTTP GET method for retrieving data from APIC-EM API.
Parameters: - path – Path of API resource, such as “/network-device”. Each path must begin with “/” forward-slash character
- params – Dictionary of parameters for request, such as {“deviceId”: “<ID of device in APIC-EM database>”}
Returns: Dictionary representation of response content under “response” key, eg. <request_response_object>show_ip_route.json()[“response”] or
None
-
post
(path, data=None, files=None, params=None)¶ Function providing HTTP POST method for sending data to APIC-EM API.
Parameters: - path (str) – Path of API resource, such as “/ticket”. Each path must begin with “/” forward-slash character
- data (json) – JSON string data payload
- files (dict) – Dictionary with files to upload
- params – Dictionary of parameters for request, such as {“deviceId”: “<ID of device in APIC-EM database>”}
Returns: Dictionary representation of response content under “response” key, eg. <request_response_object>show_ip_route.json()[“response”] or
None
-
put
(path, data=None, files=None, params=None)¶ Function providing HTTP PUT method for sending data to APIC-EM API.
Parameters: - path (str) – Path of API resource
- data (json) – JSON string data payload
- files (dict) – Dictionary with files to upload
- params (dict) – Dictionary of parameters for request, such as {“deviceId”: “<ID of device in APIC-EM database>”}
Returns: Dictionary representation of response content under “response” key, eg. <request_response_object>show_ip_route.json()[“response”] or
None
-
task_handler
(taskId, timeout=2, max_retries=2)¶ Function for handling Task results, based on taskId. This function periodically queries APIC-EM for the results of given task until task is either completed or timeout is reached. Maximum time this function waits for result is (timeout * max_retries) seconds.
Parameters: - taskId (str) – ID of the task, returned by the APIC-EM after starting task.
- timeout (int) – Number of seconds to wait after each unsuccessful request
- max_retries (int) – Maximum number of requests.
Return str: ID of the result
-
upload_file
(namespace, file_path)¶ Function for uploading file to APIC-EM’s database.
Parameters: - namespace (str) – APIC-EM’s namespace, under which the file should be uploaded
- file_path (str) – Path to the file on local machine
Return str: FileID of the uploaded file