def create_plan_from_templates(clients, name, tht_root, roles_file=None, generate_passwords=True, plan_env_file=None, networks_file=None, validate_stack=True): workflow_client = clients.workflow_engine swift_client = clients.tripleoclient.object_store print("Creating Swift container to store the plan") result = create_container(workflow_client, container=name) if result: # create_container returns 'None' on success and a string with # the error message when failing. raise exceptions.PlanCreationError( "Unable to create plan. {}".format(result)) print("Creating plan from template files in: {}".format(tht_root)) _upload_templates(swift_client, name, tht_root, utils.rel_or_abs_path(roles_file, tht_root), plan_env_file, networks_file) try: create_deployment_plan(clients, container=name, generate_passwords=generate_passwords, validate_stack=validate_stack) except exceptions.WorkflowServiceError: swiftutils.delete_container(swift_client, name) raise
def run(self, context): error_text = None # heat throws HTTPNotFound if the stack is not found try: stack = self.get_orchestration_client(context).stacks.get( self.container) except heatexceptions.HTTPNotFound: pass else: if stack is not None: raise exception.StackInUseError(name=self.container) try: swift = self.get_object_client(context) swiftutils.delete_container(swift, self.container) swiftutils.delete_container(swift, "%s-swift-rings" % self.container) except swiftexceptions.ClientException as ce: LOG.exception("Swift error deleting plan.") error_text = ce.msg except Exception as err: LOG.exception("Error deleting plan.") error_text = six.text_type(err) if error_text: return actions.Result(error=error_text)
def run(self): error_text = None # heat throws HTTPNotFound if the stack is not found try: stack = self.get_orchestration_client().stacks.get(self.container) except heatexceptions.HTTPNotFound: pass else: if stack is not None: raise exception.StackInUseError(name=self.container) try: swift = self.get_object_client() swiftutils.delete_container(swift, self.container) # if mistral environment exists, delete it too mistral = self.get_workflow_client() if self.container in [ env.name for env in mistral.environments.list() ]: # deletes environment mistral.environments.delete(self.container) except swiftexceptions.ClientException as ce: LOG.exception("Swift error deleting plan.") error_text = ce.msg except Exception as err: LOG.exception("Error deleting plan.") error_text = six.text_type(err) if error_text: return mistral_workflow_utils.Result(error=error_text)
def create_plan_from_templates(clients, name, tht_root, roles_file=None, generate_passwords=True, plan_env_file=None, networks_file=None, validate_stack=True, verbosity_level=0): swift_client = clients.tripleoclient.object_store print("Creating Swift container to store the plan") plan_utils.create_plan_container(swift_client, name) print("Creating plan from template files in: {}".format(tht_root)) _upload_templates(swift_client, name, tht_root, utils.rel_or_abs_path(roles_file, tht_root), plan_env_file, networks_file) try: create_deployment_plan(container=name, generate_passwords=generate_passwords, plan_env_file=plan_env_file, validate_stack=validate_stack, verbosity_level=verbosity_level) except exceptions.WorkflowServiceError: swiftutils.delete_container(swift_client, name) raise
def run(self, context): error_text = None # heat throws HTTPNotFound if the stack is not found try: stack = self.get_orchestration_client(context).stacks.get( self.container ) except heatexceptions.HTTPNotFound: pass else: if stack is not None: raise exception.StackInUseError(name=self.container) try: swift = self.get_object_client(context) swiftutils.delete_container(swift, self.container) except swiftexceptions.ClientException as ce: LOG.exception("Swift error deleting plan.") error_text = ce.msg except Exception as err: LOG.exception("Error deleting plan.") error_text = six.text_type(err) if error_text: return actions.Result(error=error_text)
def run(self, context): heat = self.get_orchestration_client(context) swift = self.get_object_client(context) # Since the config-download directory is now a git repo, first download # the existing config container if it exists so we can reuse the # existing git repo. try: swiftutils.download_container(swift, self.container_config, self.config_dir) # Delete the existing container before we re-upload, otherwise # files may not be fully overwritten. swiftutils.delete_container(swift, self.container_config) except swiftexceptions.ClientException as err: if err.http_status != 404: raise # Delete downloaded tarball as it will be recreated later and we don't # want to include the old tarball in the new tarball. old_tarball_path = os.path.join(self.config_dir, '%s.tar.gz' % self.container_config) if os.path.exists(old_tarball_path): os.unlink(old_tarball_path) config = ooo_config.Config(heat) message = ('Automatic commit by Mistral GetOvercloudConfig action.\n\n' 'User: {user}\n' 'Project: {project}'.format(user=context.user_name, project=context.project_name)) config_path = config.download_config(self.container, self.config_dir, self.config_type, preserve_config_dir=True, commit_message=message) with tempfile.NamedTemporaryFile() as tmp_tarball: tarball.create_tarball(config_path, tmp_tarball.name, excludes=['.tox', '*.pyc', '*.pyo']) tarball.tarball_extract_to_swift_container( self.get_object_client(context), tmp_tarball.name, self.container_config) # Also upload the tarball to the container for use by export later with open(tmp_tarball.name, 'rb') as t: swift.put_object(self.container_config, '%s.tar.gz' % self.container_config, t) if os.path.exists(config_path): shutil.rmtree(config_path)
def run(self, context): heat = self.get_orchestration_client(context) swift = self.get_object_client(context) # Since the config-download directory is now a git repo, first download # the existing config container if it exists so we can reuse the # existing git repo. try: swiftutils.download_container(swift, self.container_config, self.config_dir) # Delete the existing container before we re-upload, otherwise # files may not be fully overwritten. swiftutils.delete_container(swift, self.container_config) except swiftexceptions.ClientException as err: if err.http_status != 404: raise # Delete downloaded tarball as it will be recreated later and we don't # want to include the old tarball in the new tarball. old_tarball_path = os.path.join( self.config_dir, '%s.tar.gz' % self.container_config) if os.path.exists(old_tarball_path): os.unlink(old_tarball_path) config = ooo_config.Config(heat) message = ('Automatic commit by Mistral GetOvercloudConfig action.\n\n' 'User: {user}\n' 'Project: {project}'.format(user=context.user_name, project=context.project_name)) config_path = config.download_config(self.container, self.config_dir, self.config_type, preserve_config_dir=True, commit_message=message) with tempfile.NamedTemporaryFile() as tmp_tarball: tarball.create_tarball(config_path, tmp_tarball.name, excludes=['.tox', '*.pyc', '*.pyo']) tarball.tarball_extract_to_swift_container( self.get_object_client(context), tmp_tarball.name, self.container_config) # Also upload the tarball to the container for use by export later with open(tmp_tarball.name, 'rb') as t: swift.put_object(self.container_config, '%s.tar.gz' % self.container_config, t) if os.path.exists(config_path): shutil.rmtree(config_path)
def run(self, context): heat = self.get_orchestration_client(context) swift = self.get_object_client(context) # Since the config-download directory is now a git repo, first download # the existing config container if it exists so we can reuse the # existing git repo. try: swiftutils.download_container(swift, self.container_config, self.config_dir) # Delete the existing container before we re-upload, otherwise # files may not be fully overwritten. swiftutils.delete_container(swift, self.container_config) except swiftexceptions.ClientException as err: if err.http_status != 404: raise config = ooo_config.Config(heat) message = ('Automatic commit by Mistral GetOvercloudConfig action.\n\n' 'User: {user}\n' 'Project: {project}'.format(user=context.user_name, project=context.project_name)) config_path = config.download_config(self.container, self.config_dir, preserve_config_dir=True, commit_message=message) with tempfile.NamedTemporaryFile() as tmp_tarball: tarball.create_tarball(config_path, tmp_tarball.name, excludes=['.tox', '*.pyc', '*.pyo']) tarball.tarball_extract_to_swift_container( self.get_object_client(context), tmp_tarball.name, self.container_config) if os.path.exists(config_path): shutil.rmtree(config_path)