Example #1
0
    def take_action(self, parsed_args):
        self.log.debug('take_action(%s)', parsed_args)

        if parsed_args.parameter:
            parsed_params = parsed_args.parameter
        else:
            parsed_params = {}

        if parsed_args.template_type == "tosca":
            path = parsed_args.template_file
            a_file = os.path.isfile(path)
            a_url = UrlUtils.validate_url(path) if not a_file else False
            if a_file or a_url:
                tosca = ToscaTemplate(path, parsed_params, a_file)
                translator = TOSCATranslator(tosca, parsed_params)
                output = translator.translate()
            else:
                sys.stdout.write('Could not find template file.')
                raise SystemExit

        if parsed_args.output_file:
            with open(parsed_args.output_file, 'w+') as f:
                f.write(output)
        else:
            print(output)
Example #2
0
    def take_action(self, parsed_args):
        log.debug(_('Translating the template with input parameters'
                    '(%s).'), parsed_args)
        output = None

        if parsed_args.parameter:
            parsed_params = parsed_args.parameter
        else:
            parsed_params = {}

        if parsed_args.template_type == "tosca":
            path = parsed_args.template_file
            a_file = os.path.isfile(path)
            a_url = UrlUtils.validate_url(path) if not a_file else False
            if a_file or a_url:
                validate = parsed_args.validate_only
                if validate and validate.lower() == "true":
                    ToscaTemplate(path, parsed_params, a_file)
                else:
                    tosca = ToscaTemplate(path, parsed_params, a_file)
                    translator = TOSCATranslator(tosca, parsed_params)
                    output = translator.translate()
            else:
                msg = _('Could not find template file.')
                log.error(msg)
                sys.stdout.write(msg)
                raise SystemExit

        if output:
            if parsed_args.output_file:
                with open(parsed_args.output_file, 'w+') as f:
                    f.write(output)
            else:
                print(output)
Example #3
0
    def take_action(self, parsed_args):
        log.debug(_('Translating the template with input parameters'
                    '(%s).'), parsed_args)
        output = None

        if parsed_args.parameter:
            parsed_params = parsed_args.parameter
        else:
            parsed_params = {}

        if parsed_args.template_type == "tosca":
            path = parsed_args.template_file
            a_file = os.path.isfile(path)
            a_url = UrlUtils.validate_url(path) if not a_file else False
            if a_file or a_url:
                validate = parsed_args.validate_only
                if validate and validate.lower() == "true":
                    ToscaTemplate(path, parsed_params, a_file)
                else:
                    tosca = ToscaTemplate(path, parsed_params, a_file)
                    translator = TOSCATranslator(tosca, parsed_params)
                    output = translator.translate()
            else:
                msg = _('Could not find template file.')
                log.error(msg)
                sys.stdout.write(msg)
                raise SystemExit

        if output:
            if parsed_args.output_file:
                with open(parsed_args.output_file, 'w+') as f:
                    f.write(output)
            else:
                print(output)
Example #4
0
    def take_action(self, parsed_args):
        log.debug(_('Translating the template with input parameters'
                    '(%s).'), parsed_args)
        output = None

        session = self.app.cloud.get_session()
        flavors.SESSION = session
        images.SESSION = session

        if parsed_args.parameter:
            parsed_params = parsed_args.parameter
        else:
            parsed_params = {}

        if parsed_args.template_type == "tosca":
            path = parsed_args.template_file
            a_file = os.path.isfile(path)
            a_url = UrlUtils.validate_url(path) if not a_file else False
            if a_file or a_url:
                validate = parsed_args.validate_only
                if validate and validate.lower() == "true":
                    ToscaTemplate(path, parsed_params, a_file)
                    msg = (_('The input "%(path)s" successfully passed '
                             'validation.') % {
                                 'path': path
                             })
                    print(msg)
                else:
                    tosca = ToscaTemplate(path, parsed_params, a_file)
                    translator = TOSCATranslator(tosca, parsed_params)
                    output = translator.translate()
            else:
                msg = _('Could not find template file.\n')
                log.error(msg)
                sys.stdout.write(msg)
                raise SystemExit

        if output:
            if parsed_args.output_file:
                with open(parsed_args.output_file, 'w+') as f:
                    f.write(output)
            else:
                print(output)
Example #5
0
    def take_action(self, parsed_args):
        LOG.debug(_('Translating the template with input parameters'
                    '(%s).'), parsed_args)
        output = None

        session = self.app.cloud.get_session()
        flavors.SESSION = session
        images.SESSION = session

        if parsed_args.parameter:
            parsed_params = parsed_args.parameter
        else:
            parsed_params = {}

        if parsed_args.template_type == "tosca":
            path = parsed_args.template_file
            a_file = os.path.isfile(path)
            a_url = UrlUtils.validate_url(path) if not a_file else False
            if a_file or a_url:
                validate = parsed_args.validate_only
                if validate and validate.lower() == "true":
                    ToscaTemplate(path, parsed_params, a_file)
                    msg = (_('The input "%(path)s" successfully passed '
                             'validation.') % {'path': path})
                    print(msg)
                else:
                    tosca = ToscaTemplate(path, parsed_params, a_file)
                    translator = TOSCATranslator(tosca, parsed_params)
                    output = translator.translate()
            else:
                msg = _('Could not find template file.\n')
                LOG.error(msg)
                sys.stdout.write(msg)
                raise SystemExit

        if output:
            if parsed_args.output_file:
                with open(parsed_args.output_file, 'w+') as f:
                    f.write(output)
            else:
                print(output)