Beispiel #1
0
    def create_environment(self, provider_type, cloud_provider_metadata):
        """
        Create a new environment with data from the HOCON configuration file

        @param provider_type:           configured provider type
        @param cloud_provider_metadata: cloud provider metadata for the specified provider type

        @rtype:                         str
        @return:                        name of the created environment
        """

        # Define SSH credentials for this environment

        ssh_config = self.config.get_config('ssh')
        credentials = self.configure_ssh_credentials(ssh_config)

        # Define provider

        provider_config = self.config.get_config('provider')
        merged_provider_config = self.merge_configs(
            [ssh_config, provider_config])
        provider = self.configure_provider(merged_provider_config,
                                           provider_type,
                                           cloud_provider_metadata)

        # Create a new environment object using the credentials and provider

        env = Environment()
        env.name = self.config.get_string('environmentName', "%s Environment" %\
                                          self.config.get_string('name'))
        env.credentials = credentials
        env.provider = provider

        # Post this information to Cloudera Director (to be validated and stored)

        api = EnvironmentsApi(self.client)
        try:
            api.create(env)

        except HTTPError as e:
            # read() reads from a stream, once data is read from the stream,
            # it becomes empty
            err_body = e.read()
            auth_err_msg = self.check_auth_error(err_body)

            if auth_err_msg:
                self.log_error("Director returned %s: %s" % (e, err_body))
                raise AuthException(auth_err_msg)
            elif e.code == 302:
                self.log_warn(
                    "an environment with the same name already exists")
            else:
                self.log_error(err_body)
                raise

        self.log_info("Environments: %s" % api.list())
        return env.name
def create_environment(client, config, provider_type, cloud_provider_metadata):
    """
    Create a new environment with data from the HOCON configuration file

    @param client:                  authenticated API client
    @param config:                  parsed configuration
    @param provider_type:           configured provider type
    @param cloud_provider_metadata: cloud provider metadata for the specified provider type

    @rtype:                         str
    @return:                        name of the created environment
    """

    # Define SSH credentials for this environment

    ssh_config = config.get_config('ssh')
    credentials = configure_ssh_credentials(ssh_config)

    # Define provider

    provider_config = config.get_config('provider')
    merged_provider_config = merge_configs([ssh_config, provider_config])
    provider = configure_provider(merged_provider_config, provider_type,
                                  cloud_provider_metadata)

    # Create a new environment object using the credentials and provider

    env = Environment()
    env.name = config.get_string('environmentName',
                                 "%s Environment" % config.get_string('name'))
    env.credentials = credentials
    env.provider = provider

    # Post this information to Cloudera Director (to be validated and stored)

    api = EnvironmentsApi(client)
    try:
        api.create(env)

    except HTTPError as e:
        if e.code == 302:
            print "Warning: an environment with the same name already exists"
        else:
            raise e

    print "Environments: %s" % api.list()
    return env.name
Beispiel #3
0
def create_environment(client, config):
    """
    Create a new environment with data from the configuration file

    @param client: authenticated API client
    @param config: parsed configuration file
    """

    # Start by defining your credentials for this environment

    credentials = SshCredentials()
    credentials.username = config.get("ssh", "username")
    credentials.privateKey = file(config.get("ssh", "privateKey")).read()
    credentials.port = 22

    # Retrieve your cloud provider credentials

    provider = InstanceProviderConfig()
    provider.type = config.get("provider", "type")
    provider.config = {
        "accessKeyId": config.get("provider", "accessKeyId"),
        "secretAccessKey": config.get("provider", "secretAccessKey"),
        "region": config.get("provider", "region"),
    }

    # Create a new environment object using the credentials and provider

    env = Environment()
    env.name = "%s Environment" % config.get("cluster", "name")
    env.credentials = credentials
    env.provider = provider

    # Post this information to Cloudera Director (to be validated and stored)

    api = EnvironmentsApi(client)
    try:
        api.create(env)

    except HTTPError as e:
        if e.code == 302:
            print "Warning: an environment with the same name already exists"
        else:
            raise e

    print "Environments: %s" % api.list()
    return env.name
Beispiel #4
0
def create_environment(client, config):
    """
    Create a new environment with data from the configuration file

    @param client: authenticated API client
    @param config: parsed configuration file
    """

    # Start by defining your credentials for this environment

    credentials = SshCredentials()
    credentials.username = config.get("ssh", "username")
    credentials.privateKey = file(config.get("ssh", "privateKey")).read()
    credentials.port = 22

    # Retrieve your cloud provider credentials

    provider = InstanceProviderConfig()
    provider.type = config.get("provider", "type")
    provider.config = {
        'accessKeyId': config.get("provider", "accessKeyId"),
        'secretAccessKey': config.get("provider", "secretAccessKey"),
        'region': config.get("provider", "region")
    }

    # Create a new environment object using the credentials and provider

    env = Environment()
    env.name = "%s Environment" % config.get("cluster", "name")
    env.credentials = credentials
    env.provider = provider

    # Post this information to Cloudera Director (to be validated and stored)

    api = EnvironmentsApi(client)
    try:
        api.create(env)

    except HTTPError as e:
        if e.code == 302:
            print 'Warning: an environment with the same name already exists'
        else:
            raise e

    print "Environments: %s" % api.list()
    return env.name
def create_environment(client, config, provider_type, cloud_provider_metadata):
    """
    Create a new environment with data from the HOCON configuration file

    @param client:                  authenticated API client
    @param config:                  parsed configuration
    @param provider_type:           configured provider type
    @param cloud_provider_metadata: cloud provider metadata for the specified provider type

    @rtype:                         str
    @return:                        name of the created environment
    """

    # Define SSH credentials for this environment

    ssh_config = config.get_config('ssh')
    credentials = configure_ssh_credentials(ssh_config)

    # Define provider

    provider_config = config.get_config('provider')
    merged_provider_config = merge_configs([ssh_config, provider_config])
    provider = configure_provider(merged_provider_config, provider_type, cloud_provider_metadata)

    # Create a new environment object using the credentials and provider

    env = Environment()
    env.name = config.get_string('environmentName', "%s Environment" % config.get_string('name'))
    env.credentials = credentials
    env.provider = provider

    # Post this information to Cloudera Director (to be validated and stored)

    api = EnvironmentsApi(client)
    try:
        api.create(env)

    except HTTPError as e:
        if e.code == 302:
            print "Warning: an environment with the same name already exists"
        else:
            raise e

    print "Environments: %s" % api.list()
    return env.name
Beispiel #6
0
def create_environment(client, config):
    """
    Create a new environment with data from the configuration file

    @param client: authenticated API client
    @param config: parsed configuration file
    """

    # Start by defining your credentials for this environment

    credentials = SshCredentials(username=config.get("ssh", "username"),
                                 port=22,
                                 private_key=file(
                                     config.get("ssh", "privateKey")).read())

    # Retrieve your AWS credentials

    provider_config = {
        'accessKeyId': config.get("provider", "accessKeyId"),
        'secretAccessKey': config.get("provider", "secretAccessKey"),
        'region': config.get("provider", "region")
    }
    provider = InstanceProviderConfig(type=config.get("provider", "type"),
                                      config=provider_config)

    # Create a new environment object using the credentials and provider

    env = Environment(name="%s Environment" % config.get("cluster", "name"),
                      credentials=credentials,
                      provider=provider)

    # Post this information to Cloudera Altus Director (to be validated and stored)

    api = EnvironmentsApi(client)
    try:
        api.create(env)

    except ApiException as exc:
        if exc.status == 409:
            print 'Warning: an environment with the same name already exists'
        else:
            raise exc

    print "Environments: %s" % api.list()
    return env.name
Beispiel #7
0
def main(arguments):

    # Get all command line arguments

    cloudera_director_server = arguments[0]
    admin_username = arguments[1]
    credentials_file_path = arguments[2]
    admin_password = open(credentials_file_path, 'r').read()
    num_lookback_dates = arguments[3]

    # Optional arguments for transient clusters
    cluster_name = ''
    if ((len(arguments)) > 4):
        cluster_name = arguments[4]

    # Setup a Cloudera Director Client
    client = ApiClient(cloudera_director_server)
    AuthenticationApi(client).login(
        Login(username=admin_username, password=admin_password))

    # Get all Environments
    environments = EnvironmentsApi(client).list()
    if not environments:
        sys.exit(1)

    # Get start and end time of the query
    local_tz = timezone('US/Eastern')
    from_time = datetime.now() - timedelta(hours=8)
    from_time = from_time.replace(tzinfo=local_tz)
    to_time = datetime.now().replace(tzinfo=local_tz)

    # Iterate through all environments to get all deployments
    for environment in environments:
        deployments = DeploymentsApi(client).list(environment)
        if not deployments:
            continue

        # Iterate through all deployments to get all clusters
        for deployment in deployments:
            clusters = ClustersApi(client).list(environment, deployment)
            if not clusters:
                continue

            # Iterate through all clusters to run queries
            for cluster in clusters:
                #Filter only the cluster if cluster name passed as argument
                if (cluster_name != '' and cluster_name != cluster):
                    continue

                print(
                    "Get the usage of cluster [%s] in deployment [%s] in environment [%s] from [%s] to [%s] "
                    % (cluster, deployment, environment, from_time, to_time))
                runQuery(client, environment, deployment, cluster, from_time,
                         to_time)
def _verify_azure_update_environment(ip, password):
    address = "http://%s:7189" % ip
    print(address)
    client = ApiClient(address)
    AuthenticationApi(client).login(Login(username="******", password=password))
    environments_api = EnvironmentsApi(client)
    list_env = environments_api.list()
    print("env list ->" + str(list_env))
    if list_env:
        for environments in list_env:
            environment_information = environments_api.getRedacted(environments)
            if environment_information.provider.type == 'azure':
                print("Azure Environment: " + environments)
                b = {"subscriptionId":
                         environment_information.provider.config['subscriptionId'],
                     "tenantId":
                         environment_information.provider.config['tenantId']
                     }
                c = {
                     "clientId": CLIENT_ID,
                     "clientSecret": CLIENT_SECRET
                     }
                d = dict(b,**c)
                assert CLIENT_ID == \
                       environment_information.provider.config['clientId']
                print(json.dumps(d))
                environments_api.updateProviderCredentials(environments, (d))