Warning: this code is provided on a best effort basis and is not in any way officially supported or sanctioned by Cohesity. The code is intentionally kept simple to retain value as example code. The code in this repository is provided as-is and the author accepts no liability for damages resulting from its use.
This is a function library for APIs that use basic authentication. This is not for the Cohesity API but is useful when connecting to external APIs. This has been tested with various APIs including Isilon and GPFS.
Use the following command to download the module:
curl -O https://raw.githubusercontent.com/cohesity/community-automation-samples/main/python/basic_api/basic_api.pybasic_api.py requires the requests python module. To install it, do one of the following:
sudo yum install python-requestsor
sudo easy_install requestsfrom basic_api import *
bapiauth(endpoint=myendpoint, username=username, password=password)Although there is a password parameter, it is not recommended to use it. Instead, the fist time you attempt to authenticate to an API, you will be prompted for your password. The password will be stored in <user's home folder>/.basic-api. The stored password will then be used automatically so that scripts can run unattended.
Once authenticated, you can make API calls. For example:
nodes = bapi('get', '/scalemgmt/v2/nodes?fields=:all:')Some APIs store dates in Unix Epoch Microseconds. That's the number of microseconds since midnight on Jan 1, 1970. Several conversion functions have been included to handle these dates.
api('get','protectionJobs')[0]['creationTimeUsecs']
1533978038503713
usecsToDate(1533978038503713)
'2018-08-11 05:00:38'
dateToUsecs('2018-08-11 05:00:38')
1533978038000000
timeAgo('24','hours')
1534410755000000