-
Notifications
You must be signed in to change notification settings - Fork 2
/
sample_script.py
40 lines (30 loc) · 1.3 KB
/
sample_script.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Copyright 2019 Cohesity Inc.
#
# Python example to use Cohesity App Python SDK along with Cohesity
# Management SDK. This sample script get's app settings , gets management
# access token and passes it to Cohesity Management client to extract cluster
# name.
# Usage: python sample_script.py
import os
from cohesity_app_sdk.app_client import AppClient
from cohesity_management_sdk.cohesity_client import CohesityClient
# Get the Environment variables from App Container.
app_auth_token = os.getenv('APP_AUTHENTICATION_TOKEN')
app_endpoint_ip = os.getenv('APPS_API_ENDPOINT_IP')
app_endpoint_port = os.getenv('APPS_API_ENDPOINT_PORT')
# Initialize the client.
app_cli = AppClient(app_auth_token, app_endpoint_ip, app_endpoint_port)
app_cli.config.disable_logging()
# Get the settings information.
settings = app_cli.settings
print(settings.get_app_settings())
# Get the management access token.
token = app_cli.token_management
mgmt_auth_token = token.create_management_access_token()
# Initialize the Cohesity Client.
cluster_ip = os.getenv('HOST_IP')
cohesity_client = CohesityClient(cluster_vip=cluster_ip, auth_token=mgmt_auth_token)
cohesity_client.config.skip_ssl_verification = True
# Print Cluster name.
cluster_info = cohesity_client.cluster.get_basic_cluster_info()
print("Cluster Name : %s" % cluster_info.name)