5
0
mirror of git://git.proxmox.com/git/pve-common.git synced 2024-12-22 21:33:47 +03:00
Commit Graph

882 Commits

Author SHA1 Message Date
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
Thomas Lamprecht
dbaa6e520a buildsys: introduce BUILDDIR variable
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-18 08:57:25 +02:00
Thomas Lamprecht
f943f4d13e buildsys: remove useless variable definitions
the used ones are in src/Makefile, so remove those left over, else
one could get confused why there on two places and why changes here
had no effect.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-18 08:57:25 +02:00
Thomas Lamprecht
008c3bb2d4 bump version to 5.0-34 2018-06-15 12:06:42 +02:00
Thomas Lamprecht
8461a4875a d/control: record that we now break qemu-server << 5.0-29
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-15 12:06:42 +02:00
Thomas Lamprecht
eae436871c rename splitted out systemd module to 'Systemd'
see:
https://www.freedesktop.org/wiki/Software/systemd/#spelling

We keep the initial upercase 'S' as it's standard for perl module
and perl critic complains otherwise.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-15 12:06:42 +02:00
Wolfgang Bumiller
f024a872c4 add PVE::SystemD module
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-06-15 11:33:17 +02:00
Wolfgang Bumiller
5a94ed9d9e Perl::Cricit fixups
- fix variable declared in conditional statement
- add newlines to die/warn statements

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-06-14 11:41:41 +02:00
Thomas Lamprecht
a76b691d13 bump version to 5.0-33 2018-06-14 09:26:12 +02:00
Dietmar Maurer
2c48a66569 fix regex quoting in $print_bash_completion
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-14 09:09:10 +02:00
Wolfgang Bumiller
ea5a508493 cli: use exists() for alias check
should be faster

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-06-14 09:02:47 +02:00
Thomas Lamprecht
131f316b5c cli: only show subcommand specific usage if command incomplete
before:
$ pveum acl
ERROR: incomplete command 'pveum acl'
USAGE: pveum <COMMAND> [ARGS] [OPTIONS]
       pveum acl delete <path> --roles <string> [OPTIONS]
       pveum acl modify <path> --roles <string> [OPTIONS]

       pveum group add <groupid> [OPTIONS]
       pveum group delete <groupid>
       pveum group modify <groupid> [OPTIONS]

       pveum role add <roleid> [OPTIONS]
       pveum role delete <roleid>
       pveum role modify <roleid> --privs <string> [OPTIONS]

       pveum user add <userid> [OPTIONS]
       pveum user delete <userid>
       pveum user modify <userid> [OPTIONS]

       pveum passwd <userid>
       pveum ticket <username> [OPTIONS]

       pveum help [<extra-args>] [OPTIONS]

after:
$ pveum acl
ERROR: incomplete command 'pveum acl'
USAGE: pveum <COMMAND> [ARGS] [OPTIONS]
       pveum acl delete <path> --roles <string> [OPTIONS]
       pveum acl modify <path> --roles <string> [OPTIONS]

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-14 08:58:54 +02:00
Thomas Lamprecht
0b79680694 cli: filter out aliases when trying to expand command
we do not complete them in bash copletion either and their just there
for backward compatibillity, so filter them out.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-14 08:58:54 +02:00
Thomas Lamprecht
24ccf353c7 generate_usage_str: show short usage help for unknown commands
followup for previous commit to show the full short usage string for
the CLI tool in the case of an unknown command

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-06-13 08:31:25 +02:00
Dietmar Maurer
57c0d0c69c generate_usage_str: do no generate help for unknown commands
Before:

...
USAGE: pvesm aaa zfsscan

With this patch applied:

no such command 'aaa'

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-13 08:16:45 +02:00
Dominik Csapak
ac927fbcfd add a generalized 'read and confirm password' sub
to use everywhere we read two passwords and compare them

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2018-06-12 14:59:16 +02:00
Dietmar Maurer
6142051558 CLIHandler.pm: fix command line completion for simple commands
You can simply test behavior using 'qmrestore' ...

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-12 11:01:39 +02:00
Dietmar Maurer
1e5ecf7bf8 api_dump: add $raw_dump options
Allow to return the original tree with all refs. We use this
with our new pveclient which needs the full api definition.
Keeping refs makes it possible to store the tree more efficiently.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-06-12 11:01:31 +02:00
Wolfgang Bumiller
5082a17b81 bash completion: complete fully specified command
This contains 2 functional changes:

First: resolve_cmd no longer keeps a hash of which arguments
were expanded. This information is not required and not used
properly: For one it would conflict if the same word
appeared twice in a longer subcommand, and secondly we lose
the information when recursing into an alias anyway. And
lastly, we do not support tab completing multiple parameters
simultaneously anyway (as in, `pveum u a<tab>` does not
become `pveum user add`).
So now we simply return the expanded version of the last
command or undef if it was unknown in place of the hash we
returned previously.

The second change is how we use the new returned value:
Previously if resolve_cmd() returned a new subcommand in
$def we skipped over finishing the last word. Of course, if
the command was already fully specified (but no space put
after it), we already considered it complete and returned
the new $def.
This condition can be detected as in this case the $prev
command equals the $cur command. (Additionally, the $cur
command is either '' (after the space) or also the $prev
command (before the space), but checking this would only be
required when the same word can actually appear multiple
times in a row in a sub command chain...)
This case now takes precedence over looking through the
nested $def, so that bash will put the space after a full
command which requires another subcommand to be added.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-06-08 06:27:10 +02:00
Wolfgang Bumiller
0ed806982c cleanup: fix variable typo
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-06-08 06:27:06 +02:00
Dietmar Maurer
ff2bf45fab fix getopt when invoking without arguments 2018-06-07 07:09:59 +02:00
Wolfgang Bumiller
893ec6f259 tools: unbless errors in run_fork_with_timeout
We cannot properly encode blessed objects as json, so
instead, we should stringify them. This happened for
instance if a VM's systemd scope wasn't cleaned up as we
got an error as a Net::DBus::Error object causing a
"malformed json string" error to appear instead of the
actual message.

Additionally, add a 'must_stringify' helper: The above error
object implements a '""' operator for stringification (as
all error should), but in theory that could die as well, in
which case we just return a generic error string we'll
hopefully never see...

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-06-04 12:55:57 +02:00
Thomas Lamprecht
d86dc5eeaf bump version to 5.0-32 2018-05-29 08:28:29 +02:00
Wolfgang Bumiller
8733bb8078 fix #1766: compare task starttime numerically
Not only because <=> is correct, but using 'cmp' also has
the side effect that it adds a string version to the
variable and the API's json output turns into a string as
well, and this only happens once a task has completed
(while it's an integer while it's still running...)

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-05-18 15:01:58 +02:00
Dietmar Maurer
903ea3fff3 api_dump_remove_refs: prepare API tree for use with to_json($tree)
We want to use this with the extractapi.pl helper (pve-docs, pve-api-client).
2018-05-18 10:13:00 +02:00
Thomas Lamprecht
02548f7bb6 bump version to 5.0-31 2018-05-04 12:57:25 +02:00
Fabian Grünbichler
55ffa426f3 build: install ACME files
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2018-04-30 13:06:52 +02:00
Fabian Grünbichler
f6a70fbfdf acme: add challenge plugins
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2018-04-30 13:06:52 +02:00
Fabian Grünbichler
11c08f1472 acme: add ACME library
this implements those parts of draft-ietf-acme-acme-09 which are needed
to use Let's Encrypt's v2 API.

(based on an internal implement for the Let's Encrypt v1 API)
Co-Authored-By: Wolfgang Bumiller <w.bumiller@proxmox.com>
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2018-04-27 15:18:02 +02:00
Fabian Grünbichler
4e0952c9e8 add Certificate helper
general purpose certificate related helper functions

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2018-04-27 15:18:02 +02:00
Dietmar Maurer
62635f9235 new helper PVE::Tools::du() - get disk usage
We simply call the external binary 'du', so that we can abort the command
when we run into a timeout.
2018-04-25 10:29:58 +02:00
Dominik Csapak
fd58bb2bff untaint df return values
since we sometimes use their length in a format string for printf

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Co-authored-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-04-24 10:42:13 +02:00
Thomas Lamprecht
1e83e254ed README.dev: inkscape no longer needed, s/git-core/git/ 2018-04-23 08:22:27 +02:00
Thomas Lamprecht
597320d761 README.dev: s/jessie/stretch 2018-04-23 08:22:27 +02:00
Dietmar Maurer
68ab3fce31 use ssh -X for upload target 2018-04-05 12:23:17 +02:00
Thomas Lamprecht
eb8ebfa0e5 bump version to 5.0-30
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-03-22 09:10:14 +01:00
Wolfgang Bumiller
c93778bca1 pty: fix read_password prototype
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-03-14 11:08:21 +01:00
Wolfgang Bumiller
c7171ff272 cli: more generic interactive parameter definition
Instead of hardcoding 'password' as a special case in the
JSONSchema's getopt handling, extend the new parameter
mapping to allow defining a parameters as 'interactive'.
They also take an optional argument on the command line
directly.

This effectively deprecates the password special case which
should be replaced in pct/pveum/... and then dropped in
pve-common.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-03-13 11:04:58 +01:00
Dietmar Maurer
3defa1690b bump version to 5.0-29 2018-03-09 08:56:27 +01:00
Thomas Lamprecht
f932646909 CLIHandler: fix command usage string generation
track our command string, i.e. everything which cannot be an argument
for a specific command, in resolve_cmd, as we go through the commando
definition there anyway and know if a ARGV element is part of the
command itself or its arguments.

Fixes a problem where a invalid command had all the passed parameter
attached in the resulting USAGE output.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-03-08 15:10:51 +01:00
Fabian Grünbichler
7c5eeae56a fix #1682: handle relative years absolutely
the timegm(gmtime()) and timelocal(localtime(()) constructs are
problematic in the following case: - $last is such that $year gets set
to a two-digit value (e.g., the referred to timestamp is somewhere in
the range of 1900-1999) - the current date is such that the value of
$year gets interpreted wrongly (e.g., anything other than 1950).

the exact breakage depends on the actual current date AND value of
$last, since localtime/gmtime will interpret two-digit years as (perldoc
Time::Local):
    [...] shorthand for years in the rolling "current century," defined
    as 50 years on either side of the current year. Thus, today, in
    1999, 0 would refer to 2000, and 45 to 2045, but 55 would refer to
    1955.  Twenty years from now, 55 would instead refer to 2055.

fix it by adding 1900 to force 4-digit $year values, as the localtime
documentation suggests.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2018-03-07 11:35:28 +01:00
Dietmar Maurer
c44ec0f663 use better name for string_param_file_mapping (param_mapping).
But keep old one for compatibility.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-03-06 08:47:00 +01:00
Dietmar Maurer
4e0214faae rename $can_read_pass to $read_password_func
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-03-06 08:47:00 +01:00
Dietmar Maurer
8d3eb3ce17 rename $pwcallback to $read_password_func
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-03-06 08:47:00 +01:00
Dietmar Maurer
94e0f9540f rename $can_str_param_fmap to $param_mapping_func
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-03-06 08:47:00 +01:00
Dietmar Maurer
b01af86160 rename $stringfilemap to $param_mapping_func
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-03-06 08:47:00 +01:00
Dietmar Maurer
dfc6cff8e3 introduce compute_param_mapping_hash helper
This allows us to specify a arbitrary mapping func for any param.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-03-06 08:47:00 +01:00