Cisco Intersight Python REST Module
Project description
intersight-rest
Cisco has released their new Intersight platform for managing UCS Server and Hyperflex Hyperconverged infrastructure from a SaaS based interface. With high security standards, forming and signing the RESTful API calls to Intersight can be a challenge, so this package was written to do all of that work for you. All you need to provide is your Public/Private keys generated from the Intersight interface, as well at the API endpoint you'd like to target. Optionally you can add in query parameters for GET requests, and a body for POST/PATCH opterations.
Overview:
intersight_call(**options);
Option | Format | Value |
---|---|---|
resource_path | <String> | Resource Path from https://intersight.com/apidocs |
query_params | <Dict> | Query Parameters from Resource Path GET |
body | <Dict> | Body Parameters from Resource Path POST |
moid | <String> | MOID of Object to be Modified |
More information about Intersight is available at: https://intersight.com
Details on the RESTful API and documentation: https://intersight.com/apidocs
NPM Installation:
$ pip install intersight-rest
Usage:
# Import "intersight_rest" Package
import intersight_rest as isREST
# Import JSON Package
import json
# Load Public/Private Keys
isREST.set_private_key(open("./keys/private_key.pem", "r") .read())
isREST.set_public_key(open("./keys/public_key.txt", "r") .read())
# Select Resource Path from https://www.intersight.com/apidocs
resource_path = '/ntp/Policies'
# GET EXAMPLE
#-- Set GET Options --#
options = {
"http_method": "get",
"resource_path": resource_path,
"query_params": query_params
}
#-- Send GET Request --#
results = isREST.intersight_call(**options)
print("Status Code: " + str(results.status_code))
print(json.dumps(results.json(), indent=4))
#-- NOTE: intersight_call Returns a "requests.Response" Type --#
# GET "query_params" Examples
#-- Example query_params returning the top 1 result(s) --#
query_params = {
"$top": 1
}
#-- Example query_params showing filter by "Name" key --#
query_params = {
"$filter": "Name eq 'Test-NTP'"
}
#-- Example query_params showing filter by "Description" key --#
query_params = {
"$filter": "Description eq 'pool.ntp.org'"
}
#-- Example query_params showing advanced Tag filder by key & value --#
query_params = {
"$filter": "Tags/any(t: t/Key eq 'loc' and t/Value eq 'California')"
}
# POST EXAMPLE
#-- Assemble POST Body --#
post_body = {
"Name": "Test-NTP",
"Description": "Test NTP Policy",
"NtpServers": ["8.8.8.8"]
}
#-- Set POST Options --#
options = {
"http_method": "post",
"resource_path": resource_path,
"body": post_body
}
#-- Send POST Request --#
results = isREST.intersight_call(**options)
print("Status Code: " + str(results.status_code))
print(json.dumps(results.json(), indent=4))
#-- NOTE: intersight_call Returns a "requests.Response" Type --#
# PATCH EXAMPLE
#-- Set Object MOID to be Modified --#
patch_moid = "6b1727fa686c873463b8163e"
#-- Assemble PATCH Body --#
patch_body = {
"NtpServers": ["10.10.10.10"]
}
#-- Set PATCH Options --#
options = {
"http_method": "patch",
"resource_path": resource_path,
"body": patch_body,
"moid": patch_moid
}
#-- Send PATCH Request --#
results = isREST.intersight_call(**options)
print("Status Code: " + str(results.status_code))
print(json.dumps(results.json(), indent=4))
#-- NOTE: intersight_call Returns a "requests.Response" Type --#
# DELETE EXAMPLE
#-- Set Object MOID to be Modified --#
delete_moid = "6b1727fa686c873463b8163e"
#-- Set DELETE Options --#
options = {
"http_method": "delete",
"moid": delete_moid
}
#-- Send DELETE Request --#
results = isREST.intersight_call(**options)
print("Status Code: " + str(results.status_code))
#-- NOTE: intersight_call Returns a "requests.Response" Type --#
See package source for more details...
*Copyright (c) 2018 Cisco and/or its affiliates.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for intersight_rest-1.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04f50b4f44b85e1140d07a42cd16d815167c3ad4b2cb70ca27045956c42553b7 |
|
MD5 | 1f55f1749b05dd83d4bc435e5d3d52fa |
|
BLAKE2b-256 | 4baea707b34da74f953b3537fafdb4fe977fb746ce0951077ae3728436824686 |