def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) if parsed_args.file_in.name.endswith('.json'): params = simplejson.load(parsed_args.file_in) elif parsed_args.file_in.name.endswith('.yaml'): params = yaml.safe_load(parsed_args.file_in) else: raise exceptions.InvalidConfiguration( _("Invalid file extension for %s, must be json or yaml") % parsed_args.file_in.name) if 'parameter_defaults' in params: params = params['parameter_defaults'] clients = self.app.client_manager workflow_client = clients.workflow_engine name = parsed_args.name parameters.update_parameters( workflow_client, container=name, parameters=params )
def _process_and_upload_environment(self, container_name, env, moved_files, tht_root): """Process the environment and upload to Swift The environment at this point should be the result of the merged custom user environments. We need to look at the paths in the environment and update any that changed when they were uploaded to swift. """ file_prefix = "file://" if env.get('resource_registry'): for name, path in env['resource_registry'].items(): if not isinstance(path, six.string_types): continue if path in moved_files: new_path = moved_files[path] env['resource_registry'][name] = new_path elif path.startswith(file_prefix): path = path[len(file_prefix):] if path.startswith(tht_root): path = path[len(tht_root):] # We want to make sure all the paths are relative. if path.startswith("/"): path = path[1:] env['resource_registry'][name] = path # Parameters are removed from the environment params = env.pop('parameter_defaults', None) contents = yaml.safe_dump(env, default_flow_style=False) # Until we have a well defined plan update workflow in tripleo-common # we need to manually add an environment in swift and for users # custom environments passed to the deploy command. # See bug: https://bugs.launchpad.net/tripleo/+bug/1623431 # Update plan env. swift_path = "user-environment.yaml" self.object_client.put_object(container_name, swift_path, contents) env = yaml.safe_load( self.object_client.get_object(container_name, constants.PLAN_ENVIRONMENT)[1]) user_env = {'path': swift_path} if user_env not in env['environments']: env['environments'].append(user_env) yaml_string = yaml.safe_dump(env, default_flow_style=False) self.object_client.put_object(container_name, constants.PLAN_ENVIRONMENT, yaml_string) # Parameters are sent to the update parameters action, this stores them # in the plan environment and means the UI can find them. if params: workflow_params.update_parameters(self.workflow_client, container=container_name, parameters=params)
def _process_and_upload_environment(self, container_name, swift_client, env, moved_files, tht_root, mistral): """Process the environment and upload to Swift The environment at this point should be the result of the merged custom user environments. We need to look at the paths in the environment and update any that changed when they were uploaded to swift. """ file_prefix = "file://" if 'resource_registry' in env: for name, path in env['resource_registry'].items(): if not isinstance(path, six.string_types): continue if path in moved_files: new_path = moved_files[path] env['resource_registry'][name] = new_path elif path.startswith(file_prefix): path = path[len(file_prefix):] if path.startswith(tht_root): path = path[len(tht_root):] # We want to make sure all the paths are relative. if path.startswith("/"): path = path[1:] env['resource_registry'][name] = path # Parameters are removed from the environment and sent to the update # parameters action, this stores them in the Mistral environment and # means the UI can find them. if 'parameter_defaults' in env: params = env.pop('parameter_defaults') workflow_params.update_parameters( mistral, container=container_name, parameters=params) contents = yaml.safe_dump(env) # Until we have a well defined plan update workflow in tripleo-common # we need to manually add an environment in swift and mistral for users # custom environments passed to the deploy command. # See bug: https://bugs.launchpad.net/tripleo/+bug/1623431 swift_path = "user-environment.yaml" swift_client.put_object(container_name, swift_path, contents) mistral_env = mistral.environments.get(container_name) user_env = {'path': swift_path} if user_env not in mistral_env.variables['environments']: mistral_env.variables['environments'].append(user_env) mistral.environments.update( name=container_name, variables=mistral_env.variables )