Example #1
0
    def node_attributes(self, params):
        """Download node attributes for specified node:
            fuel node --node-id 1 --attributes --download [--dir download-dir]

        Upload node attributes for specified node
            fuel node --node-id 1 --attributes --upload [--dir upload-dir]

        """
        node = self._get_one_node(params)
        if params.upload:
            data = node.read_attribute('attributes',
                                       params.dir,
                                       serializer=self.serializer)
            node.update_node_attributes(data)
            self.serializer.print_to_output(
                {}, "Attributes for node {0} were uploaded.".format(node.id))
        elif params.download:
            attributes = node.get_node_attributes()
            file_path = node.write_attribute('attributes',
                                             attributes,
                                             params.dir,
                                             serializer=self.serializer)
            self.serializer.print_to_output(
                {}, "Attributes for node {0} were written to {1}".format(
                    node.id, file_path))

        else:
            raise error.ArgumentException(
                "--upload or --download action should be specified.")
Example #2
0
    def check_file(self, file_path):
        """Checks if file exists

        :param str file_path: path to the file
        :raises: error.ArgumentException if file does not exist
        """
        if not utils.file_exists(file_path):
            raise error.ArgumentException(
                'File "{0}" does not exists'.format(file_path))
Example #3
0
    def _get_one_node(params):
        """Ensures that only one node was passed in the command and returns it.

        :raises ArgumentException: When more than 1 node provided.
        """
        if len(params.node) > 1:
            raise error.ArgumentException(
                "You should select only one node to change.")

        return Node(params.node[0])
Example #4
0
    def parse_name_version(self, param):
        """Takes the string and returns name and version

        :param str param: string with name and version
        :raises: error.ArgumentException if version is not specified
        """
        attrs = param.split('==')

        if len(attrs) != 2:
            raise error.ArgumentException(
                'Syntax: fuel plugins <action> fuel_plugin==1.0.0')

        return attrs
Example #5
0
    def delete(self, params):
        """Remove some nodes from environment:
                fuel --env 1 node remove --node 2,3

           Remove nodes no matter to which environment they were assigned:
                fuel node remove --node 2,3,6,7

           Remove all nodes from some environment:
                fuel --env 1 node remove --all
        """
        if params.env:
            env = Environment(params.env)
            if params.node:
                env.unassign(params.node)
                self.serializer.print_to_output(
                    {},
                    "Nodes with ids {0} were removed "
                    "from environment with id {1}."
                    .format(params.node, params.env))
            else:
                if params.all:
                    env.unassign_all()
                else:
                    raise error.ArgumentException(
                        "You have to select which nodes to remove "
                        "with --node-id. Try --all for removing all nodes."
                    )
                self.serializer.print_to_output(
                    {},
                    "All nodes from environment with id {0} were removed."
                    .format(params.env))
        else:
            nodes = map(Node, params.node)
            for env_id, _nodes in groupby(nodes, attrgetter("env_id")):
                list_of_nodes = [n.id for n in _nodes]
                if env_id:
                    Environment(env_id).unassign(list_of_nodes)
                    self.serializer.print_to_output(
                        {},
                        "Nodes with ids {0} were removed "
                        "from environment with id {1}."
                        .format(list_of_nodes, env_id)
                    )
                else:
                    self.serializer.print_to_output(
                        {},
                        "Nodes with ids {0} aren't added to "
                        "any environment.".format(list_of_nodes)
                    )
Example #6
0
    def render(self, params):
        """Render graph in PNG format

        fuel graph --render graph.gv
        fuel graph --render graph.gv --dir ./output/dir/

        To apply transitive reduction filter on rendered graph:

        fuel graph --render graph.gv --tred
        fuel graph --render graph.gv --dir ./output/dir/ --tred

        Read graph from stdin
        some_process | fuel graph --render -
        """
        if params.render == '-':
            dot_data = sys.stdin.read()
            out_filename = 'graph.gv'
        elif not os.path.exists(params.render):
            raise error.ArgumentException("Input file does not exist")
        else:
            out_filename = os.path.basename(params.render)
            with open(params.render, 'r') as f:
                dot_data = f.read()

        target_dir = self.full_path_directory(
            self.default_directory(params.dir), '')
        target_file = os.path.join(
            target_dir,
            '{0}.png'.format(out_filename),
        )

        if not os.access(os.path.dirname(target_file), os.W_OK):
            raise error.ActionException(
                'Path {0} is not writable'.format(target_file))
        render_graph(dot_data, target_file, params.tred)
        print('Graph saved in "{0}"'.format(target_file))
Example #7
0
 def wrapped_f(self, params):
     if method(getattr(params, _arg) for _arg in args):
         return f(self, params)
     else:
         raise error.ArgumentException("{0} required!".format(
             quote_and_join("--" + arg for arg in args)))