예제 #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
예제 #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
예제 #5
0
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
예제 #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