def create_repository(self, envconf, build_doc, index_meta): aws_key = envconf.get("cloud", {}).get("access_key") aws_secret = envconf.get("cloud", {}).get("secret_key") repo_name, repo_conf = self.get_repository_config( envconf["repository"], build_doc, index_meta) self.logger.info("Repository config: %s" % repo_conf) settings = repo_conf["settings"] repo_type = repo_conf["type"] es_idxr = self.get_es_idxr(envconf) try: es_idxr.get_repository(repo_name) except ESIndexerException: # need to create that repo if repo_type == "s3": acl = repo_conf.get("acl", None) # let aws.create_bucket default it # first make sure bucket exists aws.create_bucket(name=settings["bucket"], region=settings["region"], aws_key=aws_key, aws_secret=aws_secret, acl=acl, ignore_already_exists=True) settings = {"type": repo_type, "settings": settings} self.logger.info("Create repository named '%s': %s" % (repo_name, pformat(settings))) es_idxr.create_repository(repo_name, settings=settings) return repo_name, repo_conf
def pre_snapshot(self, task_env): """ Ensure the destination repository is ready. Create the bucket and repository if necessary. """ cloud = self.env_config.get("cloud", {}) repository = self.env_config.get("repository", {}) try: # check if already created task_env.indexer.get_repository(repository["name"]) except ESIndexerException: # first make sure bucket exists aws.create_bucket( name=repository["settings"]["bucket"], region=repository["settings"]["region"], aws_key=cloud.get("access_key"), aws_secret=cloud.get("secret_key"), acl=repository.get("acl", None), # let aws.create_bucket default it ignore_already_exists=True) logging.info("Create repository: %s" % pformat(repository)) task_env.indexer.create_repository(repository["name"], repository["settings"]) return "repo_ready"