예제 #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
예제 #2
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
예제 #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
예제 #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