Esempio n. 1
0
def configure_provider(merged_provider_config, provider_type, cloud_provider_metadata):
    """
    Create instance provider configuration based on the specified configuration

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

    @rtype:                         InstanceProviderConfig
    @return:                        instance provider configuration
    """

    provider = InstanceProviderConfig()
    provider.type = provider_type
    if debug:
        print "merged_provider_config: %s" % merged_provider_config
    provider.config = {}

    provider.config.update(get_configuration_property_values(merged_provider_config, cloud_provider_metadata.credentialsProperties))
    provider.config.update(get_configuration_property_values(merged_provider_config, cloud_provider_metadata.configurationProperties))
    for resource_provider_metadata in cloud_provider_metadata.resourceProviders:
        provider.config.update(get_configuration_property_values(merged_provider_config, resource_provider_metadata.configurationProperties))

    if debug:
        print "provider.config: %s" % provider.config
        print "Unknown keys: %s" % (merged_provider_config.viewkeys() - provider.config.viewkeys())

    return provider
Esempio n. 2
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
Esempio n. 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(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