5
0
mirror of git://git.proxmox.com/git/pve-common.git synced 2024-12-24 01:33:48 +03:00
Commit Graph

828 Commits

Author SHA1 Message Date
Dietmar Maurer
cde31da01a cli: print_text_table: allow to limit output width
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-29 14:39:48 +02:00
Dietmar Maurer
84142f1d20 cli: data_to_text: pass property info
So that we can display defaults, render boolean nicely, or call arbitrary render
functions ...

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-29 14:39:48 +02:00
Dietmar Maurer
b521204225 PVE::JSONSchema::register_renderer - allow to register renderers by name
We want to use those renderer to format CLI output nicely.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-29 14:39:48 +02:00
Dietmar Maurer
2a174d2ab0 cli: print_api_result: use print_api_list to print objects
In order to draw the new asciiart border ...

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-29 14:39:48 +02:00
Dietmar Maurer
793ad69ba5 cli: print_text_table: allow to draw ascii art borders
format can now be:

plain => what we had with 'text' before
text => print with borders (default)
json

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-29 14:39:48 +02:00
Thomas Lamprecht
4c99c559f3 trivial: fixup: no double semicolons
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-29 12:40:07 +02:00
Thomas Lamprecht
aea06195b7 foolowup: improve/add comments and spacing
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-29 11:58:05 +02:00
Stoiko Ivanov
e97f807c38 fix #1819: fork_worker: ensure sync'ed workers control terminal
Use setpgid + tcsetpgrp instead of setsid if $sync (invocation via
cli), thus keeping /dev/tty - ssh-copy-id/ssh need it to read the
password, and putting the child in the forground. Further, ignore
SIGTTOU in child process (otherwise it gets stopped upon tcsetpgrp)

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-29 11:36:01 +02:00
Dietmar Maurer
f53ad23ac9 PVE/CLIFormatter.pm - new class to generate/format CLI output
Moved code from CLIHandler.pm into this file.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-28 09:44:43 +02:00
Thomas Lamprecht
b2285cf8eb bump version to 5.0-35 2018-06-27 15:34:14 +02:00
Thomas Lamprecht
194ed9bbbd d/control: break pve-manager < 5.2-5 and pmg-api < 5.0-74 2018-06-27 15:34:14 +02:00
Thomas Lamprecht
968bcf45be rest/cli: rename param mapping related variable to shorter versions
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-27 13:02:53 +02:00
Dominik Csapak
4842b65105 remove read_password_func from cli handler
we have a param_mapping now, with which we can impement that

e.g. instead of using:

sub read_password {
    # read password
}

we can do:

sub param_mapping {
    my ($name) = @_;

    my $password_map = ['password', sub{
	# read password
    }, '<password', 1];

    my $mapping = {
	'apicall1' => [$password_map],
	'apicall2' => [$password_map],
	...
    };

    return $mapping->{$name};
}

this has the advantage that we can use different subs for different
api calls (e.g. pveum passwd vs pveum ticket)

if a CLIHandler implemenation still has a read_password sub and no
param_mapping, we generate one for them with read_password as the
sub for the standard mapping 'pve-password'

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-06-27 12:37:20 +02:00
Dietmar Maurer
3c3d1e07c8 cli: print_text_table: another fix for poperties without schema
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-27 12:35:55 +02:00
Thomas Lamprecht
ead1edfffd cli: print_text_table: die if no property info not needed anymore
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-27 11:49:52 +02:00
Dietmar Maurer
ffe4449cd5 cli: print_text_table: fix for poperties without schema
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-27 11:46:29 +02:00
Thomas Lamprecht
8379465981 cli: print_text_table: followup code cleanup
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-27 11:28:40 +02:00
Thomas Lamprecht
9ac6416ec8 cli: print_text_table: default to autosort on
we more often want to sort by the leftmost valid column than not.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-27 11:23:31 +02:00
Thomas Lamprecht
fa7d20bf9f cli: print_api_result: simplify props_to_print code
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-27 11:00:55 +02:00
Dietmar Maurer
8dd3280b55 PVE::CLIHandler::print_text_table - cleanup, directly use json schema data
This way we can access all type information and can use that to sort
numeric columns correctly.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-27 11:00:29 +02:00
Dietmar Maurer
505786f6a4 PVE::CLIHandler::print_text_table - add option $sort_key
Now, we do not change the ordering by default.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-27 11:00:23 +02:00
Stoiko Ivanov
16f2033235 PVE::CLIHandler::data_to_text: return '' for undef
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2018-06-27 11:00:19 +02:00
Dietmar Maurer
c1e843677d PVE::CLIHandler::print_api_result - add $props_to_print parameter
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-27 11:00:12 +02:00
Stoiko Ivanov
db5b22d16a PVE::CLIHandler::print_api_list: update comment
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2018-06-25 12:09:59 +02:00
Stoiko Ivanov
9b8f2f8f6e PVE::CLIHandler::print_api_list - use all occuring properties
print_api_list falls back to the union of all properties occuring in data, if
none are provided explicitly, and the API method contains no returns property.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2018-06-25 12:09:42 +02:00
Stoiko Ivanov
e05f7cdd0c PVE::CLIHandler::print_text_table - fix sorting
Sort only if at least one column contains no undefined values.
Sort according to the left-most such column.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2018-06-25 12:09:14 +02:00
Dietmar Maurer
ec3cbded33 cleanup: rename $returninfo to $result_schema 2018-06-22 07:37:09 +02:00
Dietmar Maurer
2edb0abbb9 PVE::CLIHandler::print_api_list - improve format check
We can only print lists of objects.
2018-06-22 07:32:33 +02:00
Dietmar Maurer
8587474c36 PVE::CLIHandler::print_api_list - reorder arguments
Move optional argument to the end.
2018-06-22 07:14:04 +02:00
Dietmar Maurer
eb04f1e26c PVE::CLIHandler::print_api_list - allow to pass empty $props_to_print 2018-06-22 07:12:42 +02:00
Dietmar Maurer
340c98629c PVE::CLIHandler - new helper print_api_result
Allow to print complex object/array by simply converting them to JSON.

Note: Our API almost always return simply values.
2018-06-22 07:05:23 +02:00
Thomas Lamprecht
ba49de85b9 cli: print table: remove only-once-used default variable 2018-06-20 14:12:18 +02:00
Stoiko Ivanov
eb3dae233f cli: print_text_table: ensure default is not undefined
Default to printing '', if no default is provided for a column.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2018-06-20 14:01:31 +02:00
Wolfgang Bumiller
f6c4a56381 INotify: write network: don't duplicate bridge-vids
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-06-20 10:27:08 +02:00
Alexandre Derumier
b7c4f37851 Inotify : write network config : remove allow- ovs with ifupdown2 2018-06-20 10:11:48 +02:00
Alexandre Derumier
95d0e63377 Inotify : write network config : add bridge-vids
default is 2-4094 if user don't have specified.

mandatory for ifupdown2 and compatible with
current promox ifupdown bridgevlanport script
2018-06-20 10:11:48 +02:00
Alexandre Derumier
1accc6da65 Inotify : write network config : use modern syntax for options
-replace options with '_'  with '-'
-use 'bond-slaves' instead 'slaves'
2018-06-20 10:11:48 +02:00
Alexandre Derumier
1b1fb9f70c Inotify : read network config : allow alternative options names 2018-06-20 10:11:48 +02:00
Thomas Lamprecht
37f010e7c6 fixup: don't standard mapping code in mid of cmd helpers
as it teared code which belongs together apart

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-19 12:33:26 +02:00
Dominik Csapak
0da61ab3c3 CLIHandler: add standard mapping for password parameter
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-06-19 11:56:00 +02:00
Dominik Csapak
57d5edee2f CLIHandler: add standard_mappings
so we can reuse often used parameter mappings

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-06-19 11:56:00 +02:00
Dominik Csapak
a1c7eddaf1 add the possibility to use a hash for parameter mapping
instead of writing:
['name', sub {...}, 'description', 1]

one can now use:
{
    name => 'name',
    func => sub { ... },
    desc => 'desc',
    interactive => 1,
}

which makes it more obvious what is what
(and allows later patches to easily override some things)

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-06-19 11:56:00 +02:00
Thomas Lamprecht
305fc1e12a print_api_list: we only handle API results of type 'array'
...for now at least

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-18 12:35:04 +02:00
Thomas Lamprecht
85b9def289 improve and fix some whitespace errors
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-18 12:34:58 +02:00
Thomas Lamprecht
acd6f38373 reword print_text_table and print_api_list documentation
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-18 12:34:55 +02:00
Stoiko Ivanov
a604bf2214 add print_api_list, adapt handle_cmd
print_api_list takes an array of columns to print, the data, and the returns
definitions of the API, and prints the data by using print_text_table.

handle_cmd and handle_simple_cmd call the output sub with the returns definitons.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2018-06-18 11:24:03 +02:00
Stoiko Ivanov
8042c2cc62 add print_text_table, print_entry to CLIHandler
These two function could serve as a generic output sub for various CLI
utilities
 * print_text_table prints an array of objects in a tabular fashion,
   the formating is passed as an array containg hashes with titles, maximal
   lengths and default values. This way we can stay extensible, by adding other
   keys to the formatting options
 * print_entry prints out a single entry, handling array-refs as properties

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2018-06-18 11:24:03 +02:00
Stoiko Ivanov
f8d4eff923 add print_width property to JSONSchema definition
used to define the maximal width of the respective column in the CLI

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2018-06-18 11:24:03 +02:00
Thomas Lamprecht
a73f417f10 buildsys: depend on check target instead of manual calling it
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-18 08:57:25 +02:00
Thomas Lamprecht
82ad3144ff buildsys: refactor distclean and clean target
remove the cleanup of the not produced ${PACKAGE}-*.tar.gz file.
This is here since the import from SVN, but is not needed since quite
a time.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-18 08:57:25 +02:00