Beispiel #1
0
    def run(self, args, **kwargs):
        schema = self.app.client.managers['ConfigSchema'].get_by_ref_or_id(args.name, **kwargs)

        if not schema:
            raise resource.ResourceNotFoundError("%s doesn't have config schema defined" %
                                                 self.resource.get_display_name())

        config = interactive.InteractiveForm(schema.attributes).initiate_dialog()

        message = '---\nDo you want to preview the config in an editor before saving?'
        description = 'Secrets would be shown in plain text.'
        preview_dialog = interactive.Question(message, {'default': 'y', 'description': description})
        if preview_dialog.read() == 'y':
            contents = yaml.safe_dump(config, indent=4, default_flow_style=False)
            modified = editor.edit(contents=contents)
            config = yaml.safe_load(modified)

        message = '---\nDo you want me to save it?'
        save_dialog = interactive.Question(message, {'default': 'y'})
        if save_dialog.read() == 'n':
            raise OperationFailureException('Interrupted')

        result = self.app.client.managers['Config'].update(Config(pack=args.name, values=config))

        return result
Beispiel #2
0
    def run(self, args, **kwargs):
        schema = self.app.client.managers["ConfigSchema"].get_by_ref_or_id(
            args.name, **kwargs)

        if not schema:
            msg = "%s \"%s\" doesn't exist or doesn't have a config schema defined."
            raise resource.ResourceNotFoundError(
                msg % (self.resource.get_display_name(), args.name))

        config = interactive.InteractiveForm(
            schema.attributes).initiate_dialog()

        message = "---\nDo you want to preview the config in an editor before saving?"
        description = "Secrets will be shown in plain text."
        preview_dialog = interactive.Question(message, {
            "default": "y",
            "description": description
        })
        if preview_dialog.read() == "y":
            try:
                contents = yaml.safe_dump(config,
                                          indent=4,
                                          default_flow_style=False)
                modified = editor.edit(contents=contents)
                config = yaml.safe_load(modified)
            except editor.EditorError as e:
                print(six.text_type(e))

        message = "---\nDo you want me to save it?"
        save_dialog = interactive.Question(message, {"default": "y"})
        if save_dialog.read() == "n":
            raise OperationFailureException("Interrupted")

        config_item = Config(pack=args.name, values=config)
        result = self.app.client.managers["Config"].update(
            config_item, **kwargs)

        return result