from config import CLUSTER_VIP, CLUSTER_PASSWORD, CLUSTER_USERNAME, VM_CONFIG, JOB from cohesity_management_sdk.samples.vmware.util import connect_vcenter, register_vcenter, \ vcenter_exists, get_vm_ids, is_task_successful, get_obj from cohesity_management_sdk.cohesity_client import CohesityClient from cohesity_management_sdk.exceptions.api_exception import APIException from cohesity_management_sdk.models.protection_job_request import \ ProtectionJobRequest from cohesity_management_sdk.models.protection_run_parameters import \ ProtectionRunParameters from cohesity_management_sdk.models.run_status_enum import RunStatusEnum from cohesity_management_sdk.models.run_type_2_enum import RunType2Enum from pyVmomi import vim cohesity_client = CohesityClient(CLUSTER_VIP, CLUSTER_USERNAME, CLUSTER_PASSWORD) vcenter_client = connect_vcenter() #### VMWARE Methods #### def get_vms(vmfolder): """ Test method ot get VMs from Cohesity :param vmfolder: :return: """ vms = vmfolder.childEntity for vm in vms: print("VM name: %s" % vm.name) return
from cohesity_management_sdk.cohesity_client import CohesityClient from cohesity_management_sdk.models.protection_job_request_body import ProtectionJobRequestBody from cohesity_management_sdk.models.environment_enum import EnvironmentEnum from cohesity_management_sdk.exceptions.api_exception import APIException from cohesity_management_sdk.models.run_protection_job_param import RunProtectionJobParam import configparser import json import requests parser = configparser.ConfigParser() parser.read('config.ini') cohesity_client = CohesityClient(cluster_vip=parser.get('cohesity', 'cluster_vip'), username=parser.get('cohesity', 'username'), password=parser.get('cohesity', 'password'), domain= parser.get('cohesity', 'domain')) def register_nas_source(nas_source): url = 'https://%s/irisservices/api/v1/backupsources' % \ cohesity_client.config.cluster_vip cohesity_client.auth.authorize() bearer_token = cohesity_client.config.auth_token.access_token data = { "entity": { "type": 11, "genericNasEntity": { "protocol": 1, "type": 1, "path": nas_source
# 1. Get all tenant IDs across cluster. # 2. Get all Agent IDs per tenants. # 2. Get all Agents unassigned to tenants. # 3. Upgrade the agents per tenant. # Usage: python upgrade_agents.py # Fill in the cluster credentials below: from cohesity_management_sdk.cohesity_client import CohesityClient from cohesity_management_sdk.exceptions.api_exception import APIException from cohesity_management_sdk.models.environment_enum import EnvironmentEnum from cohesity_management_sdk.models.upgrade_physical_server_agents import \ UpgradePhysicalServerAgents try: cohesity_client = CohesityClient(cluster_vip=CLUSTER_VIP, username=CLUSTER_USERNAME, password=CLUSTER_PASSWORD, domain=CLUSTER_DOMAIN) except APIException as ex: print("Unable to initialze the client due to : %s " % ex.context) SystemExit CLUSTER_USERNAME = '******' CLUSTER_PASSWORD = '******' CLUSTER_VIP = 'prod-cluster.cohesity.com' DOMAIN = 'LOCAL' AGENT_PARALLEL_UPGRADES = 10 def get_tenants(): """
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_IP') # 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)
args = parser.parse_args() file_location = args.file_location file_name = args.file_name # Fetch the Cluster credentials from config file. configparser = configparser.ConfigParser() configparser.read('config.ini') try: cluster_vip = configparser.get('export_cluster_config', 'cluster_ip') username = configparser.get('export_cluster_config', 'username') password = configparser.get('export_cluster_config', 'password') domain = configparser.get('export_cluster_config', 'domain') cohesity_client = CohesityClient(cluster_vip=cluster_vip, username=username, password=password, domain=domain) # Make a function call to validate the credentials. cohesity_client.principals.get_user_privileges() except APIException as err: print("Authentication error occurred, error details: %s" % err) exit(1) except Exception as err: print("Authentication error occurred, error details: %s" % err) exit(1) logger.setLevel(logging.INFO) logger.info("Exporting resources from cluster '%s'" % (configparser.get('export_cluster_config', 'cluster_ip')))
def main(): cohesity_client = CohesityClient(cluster_vip=CLUSTER_VIP, username=CLUSTER_USERNAME, password=CLUSTER_PASSWORD) vcenter_object = AddVCenter(cohesity_client) vcenter_object.register_vcenter()