def configure_ssh_credentials(ssh_config): """ Create SSH credentials based on the specified configuration @param config: parsed SSH configuration @rtype: SshCredentials @return: ssh credentials """ credentials = SshCredentials() # read and set required ssh username from config credentials.username = ssh_config.get_string('username') # read and set optional password from config config_value = ssh_config.get_string('password', '') if config_value: credentials.password = config_value # read and set optional ssh private key from config config_value = ssh_config.get_string('privateKey', '') if config_value: with open(config_value) as f: credentials.privateKey = f.read() # read and set optional ssh private key passphrase from config config_value = ssh_config.get_string('passphrase', '') if config_value: credentials.passphrase = config_value # set ssh port from config credentials.port = 22 config_value = ssh_config.get_string('port', '') if config_value: credentials.port = int(config_value) return credentials
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): """ 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): """ 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