Commit Graph

52 Commits

Author SHA1 Message Date
Dietmar Maurer
b54ad320a5 fix doc generator (do not convert efidisk0 to efidisk[N])
Also fix spacing in typetext generator.
2016-09-29 12:15:47 +02:00
Dietmar Maurer
05185ea25a schema_get_type_text: always access values as number
Else PVE::RESTHandler::api_dump prints values as strings.
2016-09-05 09:27:50 +02:00
Wolfgang Bumiller
88a490ff71 allow Regexp objects for strings in the schema
The 'pattern' property has type string and format regex, so
it makes sense to allow Regexp objects to be used for it.

While check_type() doesn't know the format, Regexp objects
can be treated like strings anyway, including compared via
'eq' or matched via '=~', so we allow strings to generally
come from a Regexp object.
2016-07-14 10:28:57 +02:00
Wolfgang Bumiller
e43faad9ff Consider /31 and /32 valid subnet masks.
Since we already allow this for container IP addresses it is
reasonable to assume the host might be using such a setup as
well. (You can use an additional route to reach the gateway
and then simply have no "LAN".) Some people seem to want
this...
2016-06-03 11:21:42 +02:00
Wolfgang Bumiller
971353e8ac print_property_string: don't print the default key's name
We had this behavior in the past and didn't mean to change
it.
2016-05-23 06:24:46 +02:00
Dietmar Maurer
32f8e0c75b improve doc generator, introduce verbose_description property 2016-05-19 13:11:26 +02:00
Dietmar Maurer
2289890bad print_property_string: correctly implement skip parameter 2016-05-12 07:25:51 +02:00
Dietmar Maurer
c88c582dec fix keyAlias test 2016-05-11 13:04:01 +02:00
Dietmar Maurer
d8c2b9477c JSONSchema fix property sort order
order: default_key, required options, other
2016-05-11 10:57:06 +02:00
Dietmar Maurer
bf27456b4e remove PodParser.pm, implement keyAlias feature
The keyAlias feature replaces the previous 'group_ feature.
2016-05-11 10:02:34 +02:00
Wolfgang Bumiller
445e8267b2 property strings: introduce key grouping feature
Use case: networks for kvm use a <model>=<macaddr> scheme
where the model represents the network card. The schema
previously could not represent this, so we now introduce a
'group' key which works similar to an alias with the
difference that the data structure also gets an entry named
after the group filled with the name of the key that was
used to fill it.

Usage:
{
    virtio => { group => 'model' },
    e1000 => { group => 'model' },
    model => {
        type => 'string',
        pattern => ... # pattern for mac address
        ...
    }
}

Now the string 'virtio=aa:bb:cc:dd:ee:ff' gets parsed into:
{
    model => 'virtio',
    virtio => 'aa:bb:cc:dd:ee:ff'
}

Error examples:
  With bad value:
    virtio: value does not match the regex pattern
  Missing group:
    model: property is missing and it is not optional

parse_net() however used the 'macaddr' key for the mac
address, which can be achieved by aliasing 'model' to
'macaddr':
{
    virtio => { group => 'model' },
    e1000 => { group => 'model' },
    model => { alias => 'macaddr' },
    macaddr => {
        type => 'string',
        pattern => ... # pattern for mac address
        ...
    }
}

Then the above string will be parsed into:
{
    model => 'virtio',
    macaddr => 'aa:bb:cc:dd:ee:ff'
}

The error output now always shows the 'macaddr' key:
Error examples:
  With bad value:
    macaddr: value does not match the regex pattern
  Missing group:
    macaddr: property is missing and it is not optional

In order to support specifying no mac address we can now set
model.default_key = 1 and macaddr.optional = 1.
That way `virtio,bridge=vmbr2` gets parsed correctly into
just a model with no macaddr. This works because default
keys as aliases have previously not been supported and would
not have been aliased accordingly. This case is now also
taken into account when printing default keys, which is now
skipped if it is also an alias.
2016-04-01 09:00:53 +02:00
Wolfgang Bumiller
166e27c74f cleanup: whitespace and than/then typo 2016-03-23 11:38:26 +01:00
Wolfgang Bumiller
c77b4c9640 add the 'urlencoded' string format 2016-03-21 08:09:22 +01:00
Wolfgang Bumiller
28a2669d9b cleanup: full path package references to self
This started happening when moving the 'pve-storage-id'
option from pve-storage and curously kept on going since
then...
2016-03-21 08:08:40 +01:00
Wolfgang Bumiller
b14889b1c8 cleanup: newlines in die/warn 2016-03-21 08:04:17 +01:00
Wolfgang Bumiller
ae6682cd08 property strings: check for commas in values 2016-03-21 08:03:55 +01:00
Wolfgang Bumiller
f0ba41a135 schema: error on missing keys without default keys 2016-02-18 09:40:13 +01:00
Dominik Csapak
50ae94c97b limit vmid with JSON format
if we do not do this, vmids < 100 (not really bad) and
vmids > 999999999 are possible, which can lead to vms which you can
only get rid of, if you delete the config files manually

also this makes the api consistent with the webgui for vmids

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2016-02-15 12:52:54 +01:00
Wolfgang Bumiller
d1e490c12f schema: disable additional properties in property strings
Changed the default additional_properties parameter when
verifying them from undefined (which defaults to 1) to 0.

parse_property_strings() now takes an optional
additional_properties parameter, too.
2016-02-11 12:03:00 +01:00
Wolfgang Bumiller
35e7d23983 print_property_string: skip keys early
Keys in the skip-list don't need to be valid schema keys.
This was overly strict before which makes it harder to
include temporary internal keys in a such an object.
2015-11-26 12:10:48 +01:00
Wolfgang Bumiller
20b69017a8 print_property_string: skip undefined values 2015-10-30 07:03:10 +01:00
Wolfgang Bumiller
0526cc2d79 allow /32 ipv4 cidrs 2015-10-16 09:52:26 +02:00
Wolfgang Bumiller
303a9b34ea support aliases in property strings
In qemu the 'volume' key maps to 'file', both can be used,
so to support this case in the comma-separated property
list parser we need a way to alias keys to one another.
This allows declaring a key like:

  volume => {
      alias => 'file'
  }
  file => {
      type => 'string',
      format => 'pve-volume-id',
      default_key => 1,
      format_description => 'volume'
  }

With this the following property strings are equivalent and
result in the same datastructure being returned from
parse_property_string:

  local:disk.raw
  file=local:disk.raw
  volume=local:disk.raw
2015-10-15 12:36:07 +02:00
Wolfgang Bumiller
5f3f697dcd print_property_string: disk-size is a format, not a type 2015-10-15 12:20:50 +02:00
Dietmar Maurer
2d468b1aa2 parse_property_string: add newline to error strings
to prevent perl from adding 'at line xxx'
2015-10-09 08:38:37 +02:00
Wolfgang Bumiller
94dd443532 added JSONSchema::print_property_string
This will be used to format comma-separated property list
strings.
2015-10-01 11:24:24 +02:00
Wolfgang Bumiller
b944a22a6d JSONSchema: added disk-size format
It's a special case in some output functions as it needs
to use format_size(), so it'll be its own type and handled
in the upcoming print_property_string() function.
2015-10-01 11:24:00 +02:00
Wolfgang Bumiller
878fea8ef0 Added PVE::JSONSchema::parse_size/format_size 2015-10-01 11:23:21 +02:00
Wolfgang Bumiller
2421fba133 Support named formats in typetext generation
Now that generate_typetext doesn't need to be accessed
anymore it made sense to move it to PodParser.pm as this is
the only place that uses it now.
PodParser now needs access to JSONSchema's $format_list, so
a JSONSchema::get_format was added.
2015-10-01 11:22:39 +02:00
Wolfgang Bumiller
751ffbdd03 JSONSchema::generate_typetext: default_key support 2015-09-23 08:10:46 +02:00
Wolfgang Bumiller
2f9e609a46 JSONSchema: verify comma-separated property strings 2015-09-23 08:08:43 +02:00
Wolfgang Bumiller
095b88fd51 Added JSONSchema::parse_property_string 2015-09-23 08:04:54 +02:00
Wolfgang Bumiller
40605176f3 generate_typetext: better handling of only-optional cases 2015-09-23 08:01:44 +02:00
Wolfgang Bumiller
8c2d3ca159 JSONSchema::generate_typetext: raw typetext support
Instead of a format_description which ends up in the
documentation as 'key=<$desc>', a typetext can now be used
for an as-is string. (Eg. for when the key isn't required,
like for volumes in mountpoints, typetext can be set to
[volume=]volume)
2015-09-23 07:59:46 +02:00
Wolfgang Bumiller
703c1f8831 JSONSchema: pve-ipv4/6-config and CIDR split
Split CIDR schema into CIDRv4 and CIDRv6 and added
pve-ipv4-config and pve-ipv6-config formats.
2015-09-22 08:01:58 +02:00
Wolfgang Bumiller
86425a09da JSONSchema::check_object_warn
A version of check_object that warns and returns true or
false.
2015-09-22 08:01:48 +02:00
Wolfgang Bumiller
d5d10f8580 JSONSchema: format_description + generate_typetext
Helper to generate schema-based typetext properties for
comma separated list configuration strings (like -net0 and -ip)
using a 'format_description' schema property.
2015-09-22 08:00:59 +02:00
Emmanuel Kasper
87cb0e6064 Allow top level devel domain name up to 63 characters in email adresses
This corrects the server side validation, and fixes the bug: https://bugzilla.proxmox.com/show_bug.cgi?id=716
2015-09-17 12:56:48 +02:00
Dietmar Maurer
638edfd429 add missing formatter property to method schema 2015-09-04 13:50:06 +02:00
Dietmar Maurer
4347914633 get_options: avoid warning for -list format 2015-09-04 08:52:57 +02:00
Wolfgang Bumiller
1068aeb398 remove + from getopt's prefix_pattern
Perl by default interprets + as a parameter prefix, which
means commands like `pct resize 103 rootfs +1G` error with
'Unknown option: 1g', we don't want that.
2015-09-03 11:19:28 +02:00
Dietmar Maurer
7829989f5e add new property to support bash completions 2015-09-02 13:31:17 +02:00
Wolfgang Bumiller
5851be88ad added 'extra-args' CLI handling
added 'extra-args' standard option
added 'extra-args' handling to PVE::JSONSchema::get_options
untainting 'extra-args' separately in RESTHandler::handle
2015-09-01 17:46:04 +02:00
Dietmar Maurer
c38ac70fe0 get_standard_option: do not overwrite defaults when they evaluate to false 2015-08-04 08:58:09 +02:00
Wolfgang Bumiller
3c4d612a70 improve parse_config in JSONSchema and SectionConfig
The old code used string substitution for every line of the
input string, while perl can also iterate over all matches
via the /g re modifier, and can turn ^ and $ to act as
beginning/end of line via the /m modifier.

Effectively allowing a "match over all lines" via a simple
while ($data =~ /^.*$/gm);

The situation is a little different in SectionConfig because
there's a nested loop invovled which doesn't work with /g.
For this there are two options and I chose the safer one by
simply doing a split on newlines first.
The alternative would be to open the data as a
filehandle-to-string and use <$fh> to read lines, however
I'd have to throw in an eval{} to be sure to close the
handle afterwards.
2015-07-22 08:15:54 +02:00
Wolfgang Bumiller
d07b7084c4 spice-proxy format now uses new address format
spice-proxy used dns-name before which matches a combination of letters,
digits and dots, which happens to include ipv4 addresses but not ipv6
ones.
Since 'dns-name' sounds like it's only for names, I'm adding an address
format which is either a dns-name or an ip (including ipv6).
2015-05-27 15:32:11 +02:00
Dietmar Maurer
93276209cc fix typo 2015-04-23 09:14:48 +02:00
Dietmar Maurer
ed5880acdc add additional methods for IP address verification 2015-04-23 08:19:03 +02:00
Dietmar Maurer
c70c3bbc83 cleanup: remove unnecessary prefix 2015-04-22 10:08:37 +02:00
Dietmar Maurer
b0edd8e6d2 register new standard option pve-startup-order
We can use this for lxc and qemu.
2015-04-22 09:49:15 +02:00