Cisco Intersight Python rest模块
intersight-rest的Python项目详细描述
光间休息
思科已经发布了新的intersight平台,用于从基于saas的接口管理ucs服务器和hyperflex超连接基础设施。在高安全标准下,形成和签署对intersight的restful api调用可能是一个挑战,因此编写这个包是为了为您完成所有这些工作。您需要提供的只是从intersight接口生成的公钥/私钥,以及您想要瞄准的api端点。也可以为get请求添加查询参数,为post/patch选项添加正文。
概述:
intersight_call(**options);
Option | Format | Value |
---|---|---|
http_method | <String> | HTTP Verb [ GET | POST | PATCH | DELETE ] |
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 |
name | <String> | Name of Object to be Modified (See Notes) |
proxy | <String> | Proxy Server Address [ proto://<address>:<port> ] |
1name将被忽略,如果设置了moid。
2name区分大小写。
有关Intersight的更多信息,请访问:https://intersight.com
restful api和文档的详细信息:https://intersight.com/apidocs
pip安装:
$ pip install intersight-rest
用法:
# Import "intersight_rest" Packageimportintersight_restasisREST# Import JSON Packageimportjson# Load Public/Private KeysisREST.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/apidocsresource_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" Object --## 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" Object --## PATCH EXAMPLE#-- Assemble PATCH Body --#patch_body={"NtpServers":["10.10.10.10"]}#-- Option #1: PATCH by Object MOID --##-- Set Object MOID to be Modified --#patch_moid="6b1727fa686c873463b8163e"#-- Set PATCH Options --#options={"http_method":"patch","resource_path":resource_path,"body":patch_body,"moid":patch_moid}#-- Option #2: PATCH by Object NAME --##-- Set Object NAME to be Modified --#patch_name="Test-NTP"#-- Set PATCH Options --#options={"http_method":"patch","resource_path":resource_path,"body":patch_body,"name":patch_name}#-- 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" Object --## DELETE EXAMPLE#-- Option #1: DELETE by Object MOID --##-- Set Object MOID to be Deleted --#delete_moid="6b1727fa686c873463b8163e"#-- Set DELETE Options --#options={"http_method":"delete","moid":delete_moid}#-- Option #2: DELETE by Object Name --##-- Set Object NAME to be Deleted --#delete_name="Test-NTP"#-- Set DELETE Options --#options={"http_method":"delete","name":delete_name}#-- Send DELETE Request --#results=isREST.intersight_call(**options)print("Status Code: "+str(results.status_code))#-- NOTE: intersight_call Returns a "requests.Response" Object --#
有关更多详细信息,请参见包源…
*版权所有(c)2018 Cisco和/或其附属公司。