5
0
mirror of git://git.proxmox.com/git/pve-common.git synced 2025-01-11 13:17:36 +03:00
Commit Graph

769 Commits

Author SHA1 Message Date
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
Fabian Grünbichler
e7ecadda06 bump version to 5.0-28 2018-02-19 11:41:34 +01:00
Wolfgang Bumiller
e9b54cc6cf replace brctl with iproute2 calls
And add a few helpers for the common cases.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-02-16 14:17:36 +01:00
Wolfgang Bumiller
2d167ad0d4 schema: add bwlimit standard option and format
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-02-05 09:49:21 +01:00
Wolfgang Bumiller
70ea225069 schema: allow ipv6 prefix lengths up to 128
There's no technical reason for *us* to limit this to 120.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-02-05 09:49:12 +01:00
Wolfgang Bumiller
edbdf0b240 net: remove flowid in traffic limit commands
We don't use them and iproute2 4.13.0 has an issue parsing
parameters after a policing description.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-02-05 09:48:32 +01:00
Wolfgang Bumiller
caf3f3a7a1 bump version to 5.0-27
Now breaks qemu-server<<5.0-21

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-01-22 15:10:05 +01:00
Dietmar Maurer
3b671d82b1 INotify.pm - new helper poll_changes
Useful to detect file changes.

Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-01-22 14:52:04 +01:00
Dietmar Maurer
04cba6c8c1 read_file: replace $versions->{$filename} with $cver
Signed-off-by: Dietmar Maurer <dietmar@proxmox.com>
2018-01-22 14:52:04 +01:00
Thomas Lamprecht
b8dc43668b CLIHandler: use resolved command definition
For sub commands we resolve the real $cmd, $def and its arguments,
thus we should also get the handler from the resolved $def, not the
global one.

No change for normal (consisting of only the first argument)
commands, for them $cmddef == $def.
This sneaked in in a respin/rebase of the series.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-01-22 11:07:23 +01:00
Wolfgang Bumiller
ca2835a1d4 bump version to 5.0-26
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-01-18 09:31:02 +01:00
Thomas Lamprecht
c1059f7c17 cli: document $cmddef structure
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Acked-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-01-18 08:59:34 +01:00
Thomas Lamprecht
6627ae09a0 cli: allow to pass sub commands to help as array
Improves usabillity by allowing to pass a sub copmmand unquoted to
the help command, e.g.:

 # pveum help user delete

without this only a quoted version worked, e.g.:
 # pveum help "user delete"

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Acked-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
2018-01-18 08:59:34 +01:00
Thomas Lamprecht
50b89b88bb cli: allow specifying sub commands through $cmddef
allow to use sub commands alá
 # pveum user add

The new resolve_cmd traverses $cmddef, resolves one level of aliases
and returns the respective sub command, its cmddef, arguments and if
it was expanded (e.g., pveum u d ... => pveum user delete ...) which
allows quite easy integration in the usage/synopsis generator, bash
completion helper and command handler.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2018-01-18 08:59:34 +01:00