def register_vcenter(vcenter, username, password):
    """
    Function to fetch register Vmware Vcenter to cohesity cluster.

    CLI Examples:

    .. code-block:: bash

        salt "*" cohesity.register_vcenter vcenter=vcenter_name username=admin password=admin
    """
    try:
        cohesity_client = _get_client()
        existing_sources = cohesity_client.protection_sources.list_protection_sources_root_nodes(
            environment=env_enum.K_VMWARE)
        for source in existing_sources:
            if source.registration_info.access_info.endpoint == vcenter:
                return "Source with name {} is already registered".format(
                    vcenter)
        body = RegisterProtectionSourceParameters()
        body.endpoint = vcenter
        body.environment = env_enum.K_VMWARE
        body.username = username
        body.password = password
        body.vmware_type = "kVCenter"
        cohesity_client.protection_sources.create_register_protection_source(
            body)
        return "Successfully registered Vcenter {}".format(vcenter)
    except APIException as err:
        log.error(err)
        return str(err)
Example #2
0
 def register_vcenter(self):
     """
     Method to register vcenter.
     :return True, False.
     """
     req_body = RegisterProtectionSourceParameters()
     req_body.endpoint = VCENTER_IP
     req_body.username = VCENTER_USERNAME
     req_body.password = VCENTER_PASSWORD
     req_body.environment = EnvironmentEnum.K_VMWARE
     req_body.vmware_type = VmwareTypeEnum.KVCENTER
     source = self.cohesity_client.protection_sources
     source.create_register_protection_source(req_body)
     print("Successfully Registered the vCenter.")
def register_source(module, self):
    try:
        body = RegisterProtectionSourceParameters()
        body.endpoint = self['endpoint']
        body.environment = self['environment']
        body.force_register = module.params.get('force_register')
        body.physical_type = "kHost"
        body.host_type = "kLinux"
        response = cohesity_client.protection_sources.create_register_protection_source(
            body)
        return response
    except urllib_error.URLError as e:
        # => Capture and report any error messages.
        raise__cohesity_exception__handler(e.read(), module)
    except Exception as error:
        raise__cohesity_exception__handler(error, module)
Example #4
0
def register_vcenter(cohesity_client):
    """
    Register vCenter as protection source.
    :param cohesity_client (CohesityClient): Cohesity Management SDK
    Client Object.
    :return: None
    """
    req_body = RegisterProtectionSourceParameters()
    req_body.endpoint = VCENTER_IP
    req_body.username = VCENTER_USERNAME
    req_body.password = VCENTER_PASSWORD
    req_body.environment = EnvironmentEnum.K_VMWARE
    req_body.vmware_type = VmwareTypeEnum.KVCENTER
    try:
        source = cohesity_client.protection_sources
        return source.create_register_protection_source(
            req_body)['entity']['id']
    except Exception as ex:
        print("Error in registering vcenter %s" % ex.message)
    print("Successfully Registered the vCenter.")