Created
November 21, 2018 18:13
-
-
Save gowatana/3a42a3f0a10ae6d393b8625f040c0b8f to your computer and use it in GitHub Desktop.
Nutanix REST API v2 で Protection Domain の Snapshotを作成してみる。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import json | |
import requests | |
import time | |
args = sys.argv | |
conf_file = args[1] | |
pd_name = args[2] | |
seconds_to_wait_snapshot_report = 5 | |
def main(): | |
with open(conf_file, "r") as file: | |
conf = file.read() | |
conf = json.loads(conf) | |
prism_addr = conf["prism_address"] | |
prism_user = conf["user_name"] | |
prism_pass = conf["password"] | |
base_url = 'https://' + prism_addr + ':9440/PrismGateway/services/rest/v2.0/' | |
insecure_warn = requests.packages.urllib3.exceptions.InsecureRequestWarning | |
requests.packages.urllib3.disable_warnings(insecure_warn) | |
s = requests.Session() | |
s.auth = (prism_user, prism_pass) | |
s.headers.update({'Content-Type': 'application/json; charset=utf-8'}) | |
# Create PD Snapshot. | |
url = base_url + 'protection_domains/' + pd_name + '/oob_schedules' | |
oob_schedule = s.post(url, data='{}', verify=False).json() | |
#print(json.dumps(oob_schedule, indent=2)) | |
oob_schedule_id = oob_schedule['schedule_id'] | |
# Show PD Snapshot. | |
time.sleep(seconds_to_wait_snapshot_report) | |
url = base_url + 'protection_domains/' + pd_name + '/dr_snapshots/?oob_schedule_ids=' + str(oob_schedule_id) | |
dr_snapshot = s.get(url, verify=False).json() | |
print(json.dumps(dr_snapshot, indent=2)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
下記の投稿むけ。
Nutanix REST API v2 で Protection Domain の Snapshot を作成してみる。(Python)
http://blog.ntnx.jp/entry/2018/11/22/080555