def validate(blueprint_path): logger = get_logger() logger.info(messages.VALIDATING_BLUEPRINT.format(blueprint_path.name)) try: parse_from_path(blueprint_path.name) except DSLParsingException as ex: msg = (messages.VALIDATING_BLUEPRINT_FAILED.format( blueprint_path.name, str(ex))) raise CloudifyCliError(msg) logger.info(messages.VALIDATING_BLUEPRINT_SUCCEEDED)
def validate(blueprint_path): logger = get_logger() logger.info(messages.VALIDATING_BLUEPRINT.format(blueprint_path.name)) try: resolver = utils.get_import_resolver() parse_from_path(dsl_file_path=blueprint_path.name, resolver=resolver) except DSLParsingException as ex: msg = (messages.VALIDATING_BLUEPRINT_FAILED.format( blueprint_path.name, str(ex))) raise CloudifyCliError(msg) logger.info(messages.VALIDATING_BLUEPRINT_SUCCEEDED)
def validate(blueprint_path): logger = get_logger() logger.info( messages.VALIDATING_BLUEPRINT.format(blueprint_path.name)) try: parse_from_path(blueprint_path.name) except DSLParsingException as ex: msg = (messages.VALIDATING_BLUEPRINT_FAILED .format(blueprint_path.name, str(ex))) raise CloudifyCliError(msg) logger.info(messages.VALIDATING_BLUEPRINT_SUCCEEDED)
def validate(blueprint_path): logger = get_logger() logger.info( messages.VALIDATING_BLUEPRINT.format(blueprint_path.name)) try: resolver = utils.get_import_resolver() parse_from_path(dsl_file_path=blueprint_path.name, resolver=resolver) except DSLParsingException as ex: msg = (messages.VALIDATING_BLUEPRINT_FAILED .format(blueprint_path.name, str(ex))) raise CloudifyCliError(msg) logger.info(messages.VALIDATING_BLUEPRINT_SUCCEEDED)
def validate_blueprint(blueprint_path, logger): """Validate a blueprint `BLUEPRINT_PATH` is the path of the blueprint to validate. """ logger.info('Validating blueprint: {0}'.format(blueprint_path)) try: resolver = config.get_import_resolver() validate_version = config.is_validate_definitions_version() parse_from_path(dsl_file_path=blueprint_path, resolver=resolver, validate_version=validate_version) except DSLParsingException as ex: raise CloudifyCliError('Failed to validate blueprint {0}'.format(ex)) logger.info('Blueprint validated successfully')
def validate(blueprint_path): logger = get_logger() logger.info( 'Validating blueprint: {0}'.format(blueprint_path.name)) try: resolver = utils.get_import_resolver() validate_version = utils.is_validate_definitions_version() parse_from_path(dsl_file_path=blueprint_path.name, resolver=resolver, validate_version=validate_version) except DSLParsingException as ex: raise CloudifyCliError('Failed to validate blueprint {0}'.format( str(ex))) logger.info('Blueprint validated successfully')
def prepare_inputs(self): """ Obtain blueprint inputs and report error on missing database inputs Blueprint can contain two different kinds of inputs: optional and mandatory. Blueprint inputs that contain "default" field are optional, all other inputs are mandatory. In order to properly respect user's overrides of default values, we try to load all inputs that are listed in blueprint from database. But when checking for proper set of inputs, we only make sure mandatory inputs are covered, since optional inputs have default value and deploy doesn't need them set explicitly. """ blueprint = self.content_blueprint blueprint_inputs = parser.parse_from_path(blueprint).get("inputs", {}) blueprint_keys = blueprint_inputs.keys() required_blueprint_keys = { k for k, v in blueprint_inputs.items() if "default" not in v } input_filter = dict(key__in=blueprint_keys) service_inputs = { i.key: i.value for i in Input.objects.filter(**input_filter) } service_keys = set(service_inputs.keys()) diff = required_blueprint_keys - service_keys if len(diff) > 0: raise Blueprint.InputsError(diff) return service_inputs
def validate_blueprint(blueprint_path, logger): """Validate a blueprint `BLUEPRINT_PATH` is the path of the blueprint to validate. """ logger.info('Validating blueprint: {0}'.format(blueprint_path)) try: resolver = config.get_import_resolver() validate_version = config.is_validate_definitions_version() parse_from_path( dsl_file_path=blueprint_path, resolver=resolver, validate_version=validate_version) except DSLParsingException as ex: raise CloudifyCliError('Failed to validate blueprint {0}'.format(ex)) logger.info('Blueprint validated successfully')
def validate(args): """ Validates a blueprint using the official dsl parser Example: validate(dict( path = '/path/to/blueprint' ) ) Attributes: args (dict): a dict of arguments Returns: None """ try: parser.parse_from_path(args.blueprint_path) except Exception as e: cli_logger.error(e)
def parse_dsl(dsl_location, resources_base_path, resolver=None, validate_version=True, additional_resources=()): return parser.parse_from_path( dsl_file_path=dsl_location, resources_base_path=resources_base_path, resolver=resolver, validate_version=validate_version, additional_resource_sources=additional_resources)
def validate_blueprint_on_security_breaches( self, bluerpint_name, blueprint_directory): logger.debug( "Entering BlueprintsId.validate_blueprint_" "on_security_breaches method.") logger.info("Staring validating checks for blueprint: {0}. " "Blueprint directory: {1}." .format(bluerpint_name, blueprint_directory)) blueprint_path = os.path.join(blueprint_directory, bluerpint_name) try: logger.info("Running basic blueprints validation.") self.validate_imports(blueprint_path) blueprint_plan = parser.parse_from_path(blueprint_path) logger.debug("Blueprint plan: %s" % str(blueprint_plan)) self.validate_operation_mappings(blueprint_plan) self.validate_builtin_workflows_are_not_used(blueprint_plan) self.validate_nodes_for_install_agent_flag(blueprint_plan) self.validation_groups_policies(blueprint_plan) self.validate_plugins(blueprint_plan) self.validate_plugins_to_install_property(blueprint_plan) self.validate_plugin_nodes_fabric_operations(blueprint_plan) self.validate_plugin_nodes_fabric_env(blueprint_plan) logger.info("Success on basic blueprints validation.") logger.debug( "Done. Exiting BlueprintsId.validate_blueprint_" "on_security_breaches method.") except (Exception, dsl_exceptions.DSLParsingException, dsl_exceptions.MissingRequiredInputError, dsl_exceptions.UnknownInputError, dsl_exceptions.FunctionEvaluationError, dsl_exceptions.DSLParsingLogicException, dsl_exceptions.DSLParsingFormatException) as e: logger.exception(str(e)) logger.debug( "Done. Exiting BlueprintsId.validate_blueprint_" "on_security_breaches method.") raise exceptions.CloudifyClientError( "{0}. Blueprint: {1}.".format( self.filter_validation_exception(e), bluerpint_name), status_code=403) logger.debug( "Done. Exiting BlueprintsId.validate_blueprint_" "on_security_breaches method.")
def create_requirements(blueprint_path): parsed_dsl = parse_from_path(dsl_file_path=blueprint_path) requirements = _plugins_to_requirements( blueprint_path=blueprint_path, plugins=parsed_dsl[dsl_constants.DEPLOYMENT_PLUGINS_TO_INSTALL]) for node in parsed_dsl['nodes']: requirements.update( _plugins_to_requirements(blueprint_path=blueprint_path, plugins=node['plugins'])) return requirements
def _parse_plan(blueprint_path, inputs, ignored_modules): if dsl_parser is None: raise ImportError('cloudify-dsl-parser must be installed to ' 'execute local workflows. ' '(e.g. "pip install cloudify-dsl-parser")') plan = dsl_tasks.prepare_deployment_plan( dsl_parser.parse_from_path(blueprint_path), inputs=inputs) nodes = [Node(node) for node in plan['nodes']] node_instances = [NodeInstance(instance) for instance in plan['node_instances']] _prepare_nodes_and_instances(nodes, node_instances, ignored_modules) return plan, nodes, node_instances
def create_requirements(blueprint_path): parsed_dsl = parse_from_path(dsl_file_path=blueprint_path) requirements = _plugins_to_requirements( blueprint_path=blueprint_path, plugins=parsed_dsl[dsl_constants.DEPLOYMENT_PLUGINS_TO_INSTALL]) for node in parsed_dsl['nodes']: requirements.update(_plugins_to_requirements( blueprint_path=blueprint_path, plugins=node['plugins'])) return requirements
def _parse_plan(blueprint_path, inputs, ignored_modules): if dsl_parser is None: raise ImportError('cloudify-dsl-parser must be installed to ' 'execute local workflows. ' '(e.g. "pip install cloudify-dsl-parser")') plan = dsl_tasks.prepare_deployment_plan( dsl_parser.parse_from_path(blueprint_path), inputs=inputs) nodes = [Node(node) for node in plan['nodes']] node_instances = [ NodeInstance(instance) for instance in plan['node_instances'] ] _prepare_nodes_and_instances(nodes, node_instances, ignored_modules) return plan, nodes, node_instances
def post(self, **kwargs): """ Receives an archive to stage. This archive must contain a main blueprint file, and specify its name in the application_file_name, defaults to 'blueprint.yaml' :param kwargs: :return: update response """ query_params = request.args main_blueprint_key = 'application_file_name' blueprint_archive_url_key = 'blueprint_archive_url' deployment_id = query_params['deployment_id'] blueprint_filename = \ query_params.get(main_blueprint_key, CONVENTION_APPLICATION_BLUEPRINT_FILE) temp_dir = tempfile.mkdtemp() try: archive_destination = \ os.path.join(temp_dir, "{0}-{1}" .format(deployment_id, blueprint_filename)) # Saving the archive locally utils.save_request_content_to_file(request, archive_destination, blueprint_archive_url_key, 'blueprint') # Unpacking the archive relative_app_dir = \ utils.extract_blueprint_archive_to_mgr(archive_destination, temp_dir) # retrieving and parsing the blueprint temp_app_path = os.path.join(temp_dir, relative_app_dir, blueprint_filename) blueprint = parse_from_path(temp_app_path) # create a staging object update = get_deployment_updates_manager(). \ stage_deployment_update(deployment_id, blueprint) finally: shutil.rmtree(temp_dir, ignore_errors=True) return update, 201
def _parse_plan(blueprint_path, inputs, ignored_modules, resolver, validate_version): if dsl_parser is None: raise ImportError('cloudify-dsl-parser must be installed to ' 'execute local workflows. ' '(e.g. "pip install cloudify-dsl-parser") [{0}]' .format(_import_error)) plan = dsl_tasks.prepare_deployment_plan( dsl_parser.parse_from_path( dsl_file_path=blueprint_path, resolver=resolver, validate_version=validate_version), inputs=inputs) nodes = [Node(node) for node in plan['nodes']] node_instances = [NodeInstance(instance) for instance in plan['node_instances']] _prepare_nodes_and_instances(nodes, node_instances, ignored_modules) return plan, nodes, node_instances
def create_blueprint(self, name, blueprint_path, provider_context=None, resolver=None, validate_version=True): plan = dsl_parser.parse_from_path(dsl_file_path=blueprint_path, resolver=resolver, validate_version=validate_version) blueprint_filename = os.path.basename(os.path.abspath(blueprint_path)) blueprint = { 'id': name, 'plan': plan, 'resources': os.path.dirname(os.path.abspath(blueprint_path)), 'blueprint_filename': blueprint_filename, 'blueprint_path': blueprint_path, 'created_at': datetime.utcnow(), 'provider_context': provider_context or {} } self.store_blueprint(name, blueprint)
def _validate_blueprint(self, blueprint_file): resolver = get_import_resolver() validate_version = is_validate_definitions_version() parse_from_path(dsl_file_path=blueprint_file, resolver=resolver, validate_version=validate_version)
def __init__(self, blueprint): self.blueprint = cfy_parser.parse_from_path(blueprint)
def validate(self, blueprint_path): from dsl_parser import parser return parser.parse_from_path(blueprint_path)
def validate(self, blueprint_path): return parser.parse_from_path(blueprint_path)
def parse_from_uri(self, uri): context = parse_from_path(uri) self._validate_parse_no_issues(context) return context.modeling.classic_deployment_plan
def parse_blueprint(self, blueprint_path, inputs=None): plan = parse_from_path(blueprint_path) self.logger.info('blueprint parsed successfully') deployment_plan = prepare_deployment_plan(plan=plan.copy(), inputs=inputs) return plan, deployment_plan