Esempio n. 1
0
    def setup_commands(self, parser):
        # Controller commands
        subcmds = [
            Commands.Subcommands.SetProperty,
            Commands.Subcommands.ListProperties,
            Commands.Subcommands.Shutdown,
            Commands.Subcommands.DrbdOptions
        ]

        con_parser = parser.add_parser(
            Commands.CONTROLLER,
            aliases=["c"],
            formatter_class=argparse.RawTextHelpFormatter,
            description="Controller subcommands")

        con_subp = con_parser.add_subparsers(
            title="Controller commands",
            metavar="",
            description=Commands.Subcommands.generate_desc(subcmds)
        )

        # Controller - get props
        c_ctrl_props = con_subp.add_parser(
            Commands.Subcommands.ListProperties.LONG,
            aliases=[Commands.Subcommands.ListProperties.SHORT],
            description='Print current controller config properties.')
        c_ctrl_props.add_argument('-p', '--pastable', action="store_true", help='Generate pastable output')
        c_ctrl_props.set_defaults(func=self.cmd_print_controller_props)

        #  controller - set props
        c_set_ctrl_props = con_subp.add_parser(
            Commands.Subcommands.SetProperty.LONG,
            aliases=[Commands.Subcommands.SetProperty.SHORT],
            description='Set a controller config property.')
        Commands.add_parser_keyvalue(c_set_ctrl_props, "controller")
        c_set_ctrl_props.set_defaults(func=self.set_props)

        c_drbd_opts = con_subp.add_parser(
            Commands.Subcommands.DrbdOptions.LONG,
            aliases=[Commands.Subcommands.DrbdOptions.SHORT],
            description="Set common drbd options."
        )
        DrbdOptions.add_arguments(c_drbd_opts, DrbdOptions.drbd_options()['options'].keys())
        c_drbd_opts.set_defaults(func=self.cmd_controller_drbd_opts)

        # Controller - shutdown
        c_shutdown = con_subp.add_parser(
            Commands.Subcommands.Shutdown.LONG,
            aliases=[Commands.Subcommands.Shutdown.SHORT],
            description='Shutdown the linstor controller'
        )
        c_shutdown.set_defaults(func=self.cmd_shutdown)

        self.check_subcommands(con_subp, subcmds)
Esempio n. 2
0
    def setup_commands(self, parser):
        """

        :param argparse.ArgumentParser parser:
        :return:
        """

        subcmds = [
            Commands.Subcommands.Create, Commands.Subcommands.List,
            Commands.Subcommands.ListVolumes, Commands.Subcommands.Delete,
            Commands.Subcommands.SetProperty,
            Commands.Subcommands.ListProperties,
            Commands.Subcommands.DrbdPeerDeviceOptions
        ]

        # Resource subcommands
        res_parser = parser.add_parser(
            Commands.RESOURCE,
            aliases=["r"],
            formatter_class=argparse.RawTextHelpFormatter,
            description="Resouce subcommands")
        res_subp = res_parser.add_subparsers(
            title="resource commands",
            metavar="",
            description=Commands.Subcommands.generate_desc(subcmds))

        # new-resource
        p_new_res = res_subp.add_parser(
            Commands.Subcommands.Create.LONG,
            aliases=[Commands.Subcommands.Create.SHORT],
            description='Deploys a resource definition to a node.')
        p_new_res.add_argument('--storage-pool',
                               '-s',
                               type=namecheck(STORPOOL_NAME),
                               help="Storage pool name to use."
                               ).completer = self.storage_pool_dfn_completer
        p_new_res.add_argument('--diskless',
                               '-d',
                               action="store_true",
                               help='Should the resource be diskless')
        p_new_res.add_argument(
            '--async',
            action='store_true',
            help='Do not wait for deployment on satellites before returning')
        p_new_res.add_argument(
            '--auto-place',
            type=int,
            metavar="REPLICA_COUNT",
            help='Auto place a resource to a specified number of nodes')
        p_new_res.add_argument(
            '--do-not-place-with',
            type=namecheck(RES_NAME),
            nargs='+',
            metavar="RESOURCE_NAME",
            help=
            'Try to avoid nodes that already have a given resource deployed.'
        ).completer = self.resource_completer
        p_new_res.add_argument(
            '--do-not-place-with-regex',
            type=str,
            metavar="RESOURCE_REGEX",
            help='Try to avoid nodes that already have a resource ' +
            'deployed whos name is matching the given regular expression.')
        p_new_res.add_argument(
            '--replicas-on-same',
            nargs='+',
            default=[],
            metavar="AUX_NODE_PROPERTY",
            help=
            'Tries to place resources on nodes with the same given auxiliary node property values.'
        )
        p_new_res.add_argument(
            '--replicas-on-different',
            nargs='+',
            default=[],
            metavar="AUX_NODE_PROPERTY",
            help=
            'Tries to place resources on nodes with a different value for the given auxiliary node property.'
        )
        p_new_res.add_argument(
            '--diskless-on-remaining',
            action="store_true",
            help='Will add a diskless resource on all non replica nodes.')
        p_new_res.add_argument('node_name',
                               type=namecheck(NODE_NAME),
                               nargs='*',
                               help='Name of the node to deploy the resource'
                               ).completer = self.node_completer
        p_new_res.add_argument('resource_definition_name',
                               type=namecheck(RES_NAME),
                               help='Name of the resource definition'
                               ).completer = self.resource_dfn_completer
        p_new_res.set_defaults(func=self.create)

        # remove-resource
        p_rm_res = res_subp.add_parser(
            Commands.Subcommands.Delete.LONG,
            aliases=[Commands.Subcommands.Delete.SHORT],
            description='Removes a resource. '
            'The resource is undeployed from the node '
            "and the resource entry is marked for removal from linstor's data "
            'tables. After the node has undeployed the resource, the resource '
            "entry is removed from linstor's data tables.")
        p_rm_res.add_argument(
            '-q',
            '--quiet',
            action="store_true",
            help=
            'Unless this option is used, linstor will issue a safety question '
            'that must be answered with yes, otherwise the operation is canceled.'
        )
        p_rm_res.add_argument(
            '--async',
            action='store_true',
            help='Do not wait for deployment on satellites before returning')
        p_rm_res.add_argument(
            'node_name', nargs="+",
            help='Name of the node').completer = self.node_completer
        p_rm_res.add_argument('name', help='Name of the resource to delete'
                              ).completer = self.resource_completer
        p_rm_res.set_defaults(func=self.delete)

        resgroupby = [x.name for x in ResourceCommands._resource_headers]
        res_group_completer = Commands.show_group_completer(
            resgroupby, "groupby")

        p_lreses = res_subp.add_parser(
            Commands.Subcommands.List.LONG,
            aliases=[Commands.Subcommands.List.SHORT],
            description='Prints a list of all resource definitions known to '
            'linstor. By default, the list is printed as a human readable table.'
        )
        p_lreses.add_argument('-p',
                              '--pastable',
                              action="store_true",
                              help='Generate pastable output')
        p_lreses.add_argument(
            '-g', '--groupby', nargs='+',
            choices=resgroupby).completer = res_group_completer
        p_lreses.add_argument('-r',
                              '--resources',
                              nargs='+',
                              type=namecheck(RES_NAME),
                              help='Filter by list of resources'
                              ).completer = self.resource_completer
        p_lreses.add_argument(
            '-n',
            '--nodes',
            nargs='+',
            type=namecheck(NODE_NAME),
            help='Filter by list of nodes').completer = self.node_completer
        p_lreses.set_defaults(func=self.list)

        # list volumes
        p_lvlms = res_subp.add_parser(
            Commands.Subcommands.ListVolumes.LONG,
            aliases=[Commands.Subcommands.ListVolumes.SHORT],
            description='Prints a list of all volumes.')
        p_lvlms.add_argument('-p',
                             '--pastable',
                             action="store_true",
                             help='Generate pastable output')
        p_lvlms.add_argument(
            '-n',
            '--nodes',
            nargs='+',
            type=namecheck(NODE_NAME),
            help='Filter by list of nodes').completer = self.node_completer
        p_lvlms.add_argument('-s',
                             '--storpools',
                             nargs='+',
                             type=namecheck(STORPOOL_NAME),
                             help='Filter by list of storage pools'
                             ).completer = self.storage_pool_completer
        p_lvlms.add_argument('-r',
                             '--resources',
                             nargs='+',
                             type=namecheck(RES_NAME),
                             help='Filter by list of resources'
                             ).completer = self.resource_completer
        p_lvlms.set_defaults(func=self.list_volumes)

        # show properties
        p_sp = res_subp.add_parser(
            Commands.Subcommands.ListProperties.LONG,
            aliases=[Commands.Subcommands.ListProperties.SHORT],
            description="Prints all properties of the given resource.")
        p_sp.add_argument('-p',
                          '--pastable',
                          action="store_true",
                          help='Generate pastable output')
        p_sp.add_argument('node_name',
                          help="Node name where the resource is deployed."
                          ).completer = self.node_completer
        p_sp.add_argument(
            'resource_name',
            help="Resource name").completer = self.resource_completer
        p_sp.set_defaults(func=self.print_props)

        # set properties
        p_setprop = res_subp.add_parser(
            Commands.Subcommands.SetProperty.LONG,
            aliases=[Commands.Subcommands.SetProperty.SHORT],
            description=
            'Sets properties for the given resource on the given node.')
        p_setprop.add_argument('node_name',
                               type=namecheck(NODE_NAME),
                               help='Node name where resource is deployed.'
                               ).completer = self.node_completer
        p_setprop.add_argument(
            'name', type=namecheck(RES_NAME),
            help='Name of the resource').completer = self.resource_completer
        Commands.add_parser_keyvalue(p_setprop, "resource")
        p_setprop.set_defaults(func=self.set_props)

        # drbd peer device options
        p_drbd_peer_opts = res_subp.add_parser(
            Commands.Subcommands.DrbdPeerDeviceOptions.LONG,
            aliases=[Commands.Subcommands.DrbdPeerDeviceOptions.SHORT],
            description="Set drbd peer-device options.")
        p_drbd_peer_opts.add_argument('node_a',
                                      type=namecheck(NODE_NAME),
                                      help="1. Node in the node connection"
                                      ).completer = self.node_completer
        p_drbd_peer_opts.add_argument('node_b',
                                      type=namecheck(NODE_NAME),
                                      help="1. Node in the node connection"
                                      ).completer = self.node_completer
        p_drbd_peer_opts.add_argument(
            'resource_name', type=namecheck(RES_NAME),
            help="Resource name").completer = self.resource_completer

        DrbdOptions.add_arguments(p_drbd_peer_opts, [
            x for x in DrbdOptions.drbd_options()['options'] if DrbdOptions.
            drbd_options()['options'][x]['category'] == 'peer-device-options'
        ])
        p_drbd_peer_opts.set_defaults(func=self.drbd_peer_opts)

        self.check_subcommands(res_subp, subcmds)
Esempio n. 3
0
    def setup_commands(self, parser):
        # volume definition subcommands
        subcmds = [
            Commands.Subcommands.Create, Commands.Subcommands.List,
            Commands.Subcommands.Delete, Commands.Subcommands.SetSize,
            Commands.Subcommands.SetProperty,
            Commands.Subcommands.ListProperties,
            Commands.Subcommands.DrbdOptions
        ]

        vol_def_parser = parser.add_parser(
            Commands.VOLUME_DEF,
            aliases=["vd"],
            formatter_class=argparse.RawTextHelpFormatter,
            description="Volume definition subcommands")

        vol_def_subp = vol_def_parser.add_subparsers(
            title="Volume definition commands",
            metavar="",
            description=Commands.Subcommands.generate_desc(subcmds))

        p_new_vol = vol_def_subp.add_parser(
            Commands.Subcommands.Create.LONG,
            aliases=[Commands.Subcommands.Create.SHORT],
            description='Defines a volume with a capacity of size for use with '
            'linstore. If the resource resname exists already, a new volume is '
            'added to that resource, otherwise the resource is created automatically '
            'with default settings. Unless minornr is specified, a minor number for '
            "the volume's DRBD block device is assigned automatically by the "
            'linstor server.')
        p_new_vol.add_argument('--storage-pool',
                               '-s',
                               type=namecheck(STORPOOL_NAME),
                               help="Storage pool name to use."
                               ).completer = self.storage_pool_dfn_completer
        p_new_vol.add_argument('-n', '--vlmnr', type=int)
        p_new_vol.add_argument('-m', '--minor', type=int)
        p_new_vol.add_argument(
            '--encrypt',
            action="store_true",
            help="Encrypt created volumes using cryptsetup.")
        p_new_vol.add_argument('resource_name',
                               type=namecheck(RES_NAME),
                               help='Name of an existing resource'
                               ).completer = self.resource_dfn_completer
        p_new_vol.add_argument(
            'size', help=VolumeDefinitionCommands.VOLUME_SIZE_HELP
        ).completer = VolumeDefinitionCommands.size_completer
        p_new_vol.set_defaults(func=self.create)

        # remove-volume definition
        p_rm_vol = vol_def_subp.add_parser(
            Commands.Subcommands.Delete.LONG,
            aliases=[Commands.Subcommands.Delete.SHORT],
            description=
            'Removes a volume definition from the linstor cluster, and removes '
            'the volume definition from the resource definition. The volume is '
            'undeployed from all nodes and the volume entry is marked for removal '
            "from the resource definition in linstor's data tables. After all "
            'nodes have undeployed the volume, the volume entry is removed from '
            'the resource definition.')
        p_rm_vol.add_argument(
            '-q',
            '--quiet',
            action="store_true",
            help=
            'Unless this option is used, linstor will issue a safety question '
            'that must be answered with yes, otherwise the operation is canceled.'
        )
        p_rm_vol.add_argument('resource_name',
                              help='Resource name of the volume definition'
                              ).completer = self.resource_dfn_completer
        p_rm_vol.add_argument('volume_nr',
                              type=int,
                              help="Volume number to delete.")
        p_rm_vol.set_defaults(func=self.delete)

        # list volume definitions
        vlm_dfn_groupby = [x.name for x in self._vlm_dfn_headers]
        vlm_dfn_group_completer = Commands.show_group_completer(
            vlm_dfn_groupby, "groupby")

        p_lvols = vol_def_subp.add_parser(
            Commands.Subcommands.List.LONG,
            aliases=[Commands.Subcommands.List.SHORT],
            description=
            ' Prints a list of all volume definitions known to linstor. '
            'By default, the list is printed as a human readable table.')
        p_lvols.add_argument('-p',
                             '--pastable',
                             action="store_true",
                             help='Generate pastable output')
        p_lvols.add_argument(
            '-g', '--groupby', nargs='+',
            choices=vlm_dfn_groupby).completer = vlm_dfn_group_completer
        p_lvols.add_argument('-R',
                             '--resources',
                             nargs='+',
                             type=namecheck(RES_NAME),
                             help='Filter by list of resources'
                             ).completer = self.resource_dfn_completer
        p_lvols.set_defaults(func=self.list)

        # show properties
        p_sp = vol_def_subp.add_parser(
            Commands.Subcommands.ListProperties.LONG,
            aliases=[Commands.Subcommands.ListProperties.SHORT],
            description="Prints all properties of the given volume definition."
        )
        p_sp.add_argument('-p',
                          '--pastable',
                          action="store_true",
                          help='Generate pastable output')
        p_sp.add_argument(
            'resource_name',
            help="Resource name").completer = self.resource_dfn_completer
        p_sp.add_argument('volume_nr', type=int, help="Volume number")
        p_sp.set_defaults(func=self.print_props)

        # set properties
        p_setprop = vol_def_subp.add_parser(
            Commands.Subcommands.SetProperty.LONG,
            aliases=[Commands.Subcommands.SetProperty.SHORT],
            description='Sets properties for the given volume definition.')
        p_setprop.add_argument(
            'resource_name',
            help="Resource name").completer = self.resource_dfn_completer
        p_setprop.add_argument('volume_nr', type=int, help="Volume number")
        Commands.add_parser_keyvalue(p_setprop, "volume-definition")
        p_setprop.set_defaults(func=self.set_props)

        p_drbd_opts = vol_def_subp.add_parser(
            Commands.Subcommands.DrbdOptions.LONG,
            aliases=[Commands.Subcommands.DrbdOptions.SHORT],
            description="Set drbd volume options.")
        p_drbd_opts.add_argument(
            'resource_name', type=namecheck(RES_NAME),
            help="Resource name").completer = self.resource_dfn_completer
        p_drbd_opts.add_argument('volume_nr', type=int, help="Volume number")
        DrbdOptions.add_arguments(p_drbd_opts, [
            x for x in DrbdOptions.drbd_options()['options']
            if x in DrbdOptions.drbd_options()['filters']['volume']
        ])
        p_drbd_opts.set_defaults(func=self.set_drbd_opts)

        # set size
        p_set_size = vol_def_subp.add_parser(
            Commands.Subcommands.SetSize.LONG,
            aliases=[Commands.Subcommands.SetSize.SHORT],
            description='Change the size of a volume. '
            'Decreasing the size is only supported when the resource definition does not have any '
            'resources. '
            'Increasing the size is supported even when the resource definition has resources. '
            'Filesystems present on the volumes will not be resized.')
        p_set_size.add_argument('resource_name',
                                type=namecheck(RES_NAME),
                                help='Name of an existing resource'
                                ).completer = self.resource_dfn_completer
        p_set_size.add_argument('volume_nr', type=int, help="Volume number")
        p_set_size.add_argument(
            'size', help=VolumeDefinitionCommands.VOLUME_SIZE_HELP
        ).completer = VolumeDefinitionCommands.size_completer
        p_set_size.set_defaults(func=self.set_volume_size)

        self.check_subcommands(vol_def_subp, subcmds)
Esempio n. 4
0
    def setup_commands(self, parser):
        subcmds = [
            Commands.Subcommands.Create,
            Commands.Subcommands.List,
            Commands.Subcommands.Delete,
            Commands.Subcommands.SetProperty,
            Commands.Subcommands.ListProperties,
            Commands.Subcommands.DrbdOptions
        ]

        # Resource subcommands
        res_def_parser = parser.add_parser(
            Commands.RESOURCE_DEF,
            aliases=["rd"],
            formatter_class=argparse.RawTextHelpFormatter,
            description="Resource definition subcommands")

        res_def_subp = res_def_parser.add_subparsers(
            title="resource definition subcommands",
            metavar="",
            description=Commands.Subcommands.generate_desc(subcmds)
        )

        p_new_res_dfn = res_def_subp.add_parser(
            Commands.Subcommands.Create.LONG,
            aliases=[Commands.Subcommands.Create.SHORT],
            description='Defines a Linstor resource definition for use with linstor.')
        p_new_res_dfn.add_argument('-p', '--port', type=rangecheck(1, 65535))
        # p_new_res_dfn.add_argument('-s', '--secret', type=str)
        p_new_res_dfn.add_argument('name', type=namecheck(RES_NAME), help='Name of the new resource definition')
        p_new_res_dfn.set_defaults(func=self.create)

        # remove-resource definition
        # TODO description
        p_rm_res_dfn = res_def_subp.add_parser(
            Commands.Subcommands.Delete.LONG,
            aliases=[Commands.Subcommands.Delete.SHORT],
            description=" Removes a resource definition "
            "from the linstor cluster. The resource is undeployed from all nodes "
            "and the resource entry is marked for removal from linstor's data "
            "tables. After all nodes have undeployed the resource, the resource "
            "entry is removed from linstor's data tables.")
        p_rm_res_dfn.add_argument('-q', '--quiet', action="store_true",
                                  help='Unless this option is used, linstor will issue a safety question '
                                  'that must be answered with yes, otherwise the operation is canceled.')
        p_rm_res_dfn.add_argument(
            'name',
            nargs="+",
            help='Name of the resource to delete').completer = self.resource_dfn_completer
        p_rm_res_dfn.set_defaults(func=self.delete)

        rsc_dfn_groupby = [x.name for x in self._rsc_dfn_headers]
        rsc_dfn_group_completer = Commands.show_group_completer(rsc_dfn_groupby, "groupby")

        p_lrscdfs = res_def_subp.add_parser(
            Commands.Subcommands.List.LONG,
            aliases=[Commands.Subcommands.List.SHORT],
            description='Prints a list of all resource definitions known to '
            'linstor. By default, the list is printed as a human readable table.')
        p_lrscdfs.add_argument('-p', '--pastable', action="store_true", help='Generate pastable output')
        p_lrscdfs.add_argument('-g', '--groupby', nargs='+',
                               choices=rsc_dfn_groupby).completer = rsc_dfn_group_completer
        p_lrscdfs.add_argument('-R', '--resources', nargs='+', type=namecheck(RES_NAME),
                               help='Filter by list of resources').completer = self.resource_dfn_completer
        p_lrscdfs.set_defaults(func=self.list)

        # show properties
        p_sp = res_def_subp.add_parser(
            Commands.Subcommands.ListProperties.LONG,
            aliases=[Commands.Subcommands.ListProperties.SHORT],
            description="Prints all properties of the given resource definitions.")
        p_sp.add_argument('-p', '--pastable', action="store_true", help='Generate pastable output')
        p_sp.add_argument(
            'resource_name',
            help="Resource definition for which to print the properties"
        ).completer = self.resource_dfn_completer
        p_sp.set_defaults(func=self.print_props)

        # set properties
        p_setprop = res_def_subp.add_parser(
            Commands.Subcommands.SetProperty.LONG,
            aliases=[Commands.Subcommands.SetProperty.SHORT],
            description='Sets properties for the given resource definition.')
        p_setprop.add_argument('name', type=namecheck(RES_NAME), help='Name of the resource definition')
        Commands.add_parser_keyvalue(p_setprop, 'resource-definition')
        p_setprop.set_defaults(func=self.set_props)

        # drbd options
        p_drbd_opts = res_def_subp.add_parser(
            Commands.Subcommands.DrbdOptions.LONG,
            aliases=[Commands.Subcommands.DrbdOptions.SHORT],
            description="Set drbd resource options."
        )
        p_drbd_opts.add_argument(
            'resource_name',
            type=namecheck(RES_NAME),
            help="Resource name"
        ).completer = self.resource_dfn_completer
        DrbdOptions.add_arguments(
            p_drbd_opts,
            [x for x in DrbdOptions.drbd_options()['options'] if x in DrbdOptions.drbd_options()['filters']['resource']]
        )
        p_drbd_opts.set_defaults(func=self.set_drbd_opts)

        self.check_subcommands(res_def_subp, subcmds)