fix #975, use new keyAlias feature.

Also remove unneccessary format_descriptions for boolean and enums.
This commit is contained in:
Dietmar Maurer 2016-05-11 10:11:49 +02:00
parent 391c2230d4
commit 7f694a7113

View File

@ -132,7 +132,7 @@ my $cpu_fmt = {
cputype => { cputype => {
description => "Emulated CPU type.", description => "Emulated CPU type.",
type => 'string', type => 'string',
enum => [ sort keys %$cpu_vendor_list ], enum => [ sort { "\L$a" cmp "\L$b" } keys %$cpu_vendor_list ],
format_description => 'cputype', format_description => 'cputype',
default => 'kvm64', default => 'kvm64',
default_key => 1, default_key => 1,
@ -532,7 +532,6 @@ my $numa_fmt = {
memory => { memory => {
type => "number", type => "number",
description => "Amount of memory this numa node provides.", description => "Amount of memory this numa node provides.",
format_description => "mb",
optional => 1, optional => 1,
}, },
hostnodes => { hostnodes => {
@ -545,7 +544,6 @@ my $numa_fmt = {
policy => { policy => {
type => 'string', type => 'string',
enum => [qw(preferred bind interleave)], enum => [qw(preferred bind interleave)],
format_description => 'preferred|bind|interleave',
description => "numa allocation policy.", description => "numa allocation policy.",
optional => 1, optional => 1,
}, },
@ -573,10 +571,17 @@ my $net_fmt = {
pattern => qr/[0-9a-f]{2}(?::[0-9a-f]{2}){5}/i, pattern => qr/[0-9a-f]{2}(?::[0-9a-f]{2}){5}/i,
description => "MAC address", description => "MAC address",
format_description => "XX:XX:XX:XX:XX:XX", format_description => "XX:XX:XX:XX:XX:XX",
keyAlias => 'model',
optional => 1, optional => 1,
}, },
model => { alias => 'macaddr', default_key => 1 }, model => {
(map { $_ => { group => 'model' } } @$nic_model_list), type => 'string',
description => 'Network Card Model.',
format_description => 'model',
enum => $nic_model_list,
default_key => 1,
},
(map { $_ => { keyAlias => 'model', alias => 'macaddr' }} @$nic_model_list),
bridge => { bridge => {
type => 'string', type => 'string',
description => 'Bridge to attach the network device to.', description => 'Bridge to attach the network device to.',
@ -587,46 +592,41 @@ my $net_fmt = {
type => 'integer', type => 'integer',
minimum => 0, maximum => 16, minimum => 0, maximum => 16,
description => 'Number of packet queues to be used on the device.', description => 'Number of packet queues to be used on the device.',
format_description => 'number',
optional => 1, optional => 1,
}, },
rate => { rate => {
type => 'number', type => 'number',
minimum => 0, minimum => 0,
description => 'Rate limit in mbps as floating point number.', description => 'Rate limit in mbps as floating point number.',
format_description => 'mbps',
optional => 1, optional => 1,
}, },
tag => { tag => {
type => 'integer', type => 'integer',
minimum => 2, maximum => 4094, minimum => 2, maximum => 4094,
description => 'VLAN tag to apply to packets on this interface.', description => 'VLAN tag to apply to packets on this interface.',
format_description => 'vlanid',
optional => 1, optional => 1,
}, },
trunks => { trunks => {
type => 'string', type => 'string',
pattern => qr/\d+(?:-\d+)?(?:;\d+(?:-\d+)?)*/, pattern => qr/\d+(?:-\d+)?(?:;\d+(?:-\d+)?)*/,
description => 'VLAN trunks to pass through this interface.', description => 'VLAN trunks to pass through this interface.',
format_description => 'id;id...', format_description => 'vlanid[;vlanid...]',
optional => 1, optional => 1,
}, },
firewall => { firewall => {
type => 'boolean', type => 'boolean',
description => 'Whether this interface should be protected by the firewall.', description => 'Whether this interface should be protected by the firewall.',
format_description => '0|1',
optional => 1, optional => 1,
}, },
link_down => { link_down => {
type => 'boolean', type => 'boolean',
description => 'Whether this interface should be DISconnected (like pulling the plug).', description => 'Whether this interface should be DISconnected (like pulling the plug).',
format_description => '0|1',
optional => 1, optional => 1,
}, },
}; };
my $netdesc = { my $netdesc = {
optional => 1, optional => 1,
type => 'string', format => 'pve-qm-net', type => 'string', format => $net_fmt,
description => <<EODESCR, description => <<EODESCR,
Specify network devices. Specify network devices.
@ -685,7 +685,6 @@ my %drivedesc_base = (
}, },
media => { media => {
type => 'string', type => 'string',
format_description => 'cdrom|disk',
enum => [qw(cdrom disk)], enum => [qw(cdrom disk)],
description => "The drive's media type.", description => "The drive's media type.",
default => 'disk', default => 'disk',
@ -693,45 +692,39 @@ my %drivedesc_base = (
}, },
cyls => { cyls => {
type => 'integer', type => 'integer',
format_description => 'count',
description => "Force the drive's physical geometry to have a specific cylinder count.", description => "Force the drive's physical geometry to have a specific cylinder count.",
optional => 1 optional => 1
}, },
heads => { heads => {
type => 'integer', type => 'integer',
format_description => 'count',
description => "Force the drive's physical geometry to have a specific head count.", description => "Force the drive's physical geometry to have a specific head count.",
optional => 1 optional => 1
}, },
secs => { secs => {
type => 'integer', type => 'integer',
format_description => 'count',
description => "Force the drive's physical geometry to have a specific sector count.", description => "Force the drive's physical geometry to have a specific sector count.",
optional => 1 optional => 1
}, },
trans => { trans => {
type => 'string', type => 'string',
format_description => 'none|lba|auto',
enum => [qw(none lba auto)], enum => [qw(none lba auto)],
description => "Force disk geometry bios translation mode.", description => "Force disk geometry bios translation mode.",
optional => 1, optional => 1,
}, },
snapshot => { snapshot => {
type => 'boolean', type => 'boolean',
format_description => 'on|off',
description => "Whether the drive should be included when making snapshots.", description => "Whether the drive should be included when making snapshots.",
optional => 1, optional => 1,
}, },
cache => { cache => {
type => 'string', type => 'string',
format_description => 'none|writethrough|writeback|unsafe|directsync',
enum => [qw(none writethrough writeback unsafe directsync)], enum => [qw(none writethrough writeback unsafe directsync)],
description => "The drive's cache mode", description => "The drive's cache mode",
optional => 1, optional => 1,
}, },
format => { format => {
type => 'string', type => 'string',
format_description => 'drive format', format_description => 'image format',
enum => [qw(raw cow qcow qed qcow2 vmdk cloop)], enum => [qw(raw cow qcow qed qcow2 vmdk cloop)],
description => "The drive's backing file's data format.", description => "The drive's backing file's data format.",
optional => 1, optional => 1,
@ -739,32 +732,29 @@ my %drivedesc_base = (
size => { size => {
type => 'string', type => 'string',
format => 'disk-size', format => 'disk-size',
format_description => 'DiskSize',
description => "Disk size. This is purely informational and has no effect.", description => "Disk size. This is purely informational and has no effect.",
optional => 1, optional => 1,
}, },
backup => { backup => {
type => 'boolean', type => 'boolean',
format_description => 'on|off',
description => "Whether the drive should be included when making backups.", description => "Whether the drive should be included when making backups.",
optional => 1, optional => 1,
}, },
werror => { werror => {
type => 'string', type => 'string',
format_description => 'enospc|ignore|report|stop',
enum => [qw(enospc ignore report stop)], enum => [qw(enospc ignore report stop)],
description => 'Write error action.', description => 'Write error action.',
optional => 1, optional => 1,
}, },
aio => { aio => {
type => 'string', type => 'string',
format_description => 'native|threads',
enum => [qw(native threads)], enum => [qw(native threads)],
description => 'AIO type to use.', description => 'AIO type to use.',
optional => 1, optional => 1,
}, },
discard => { discard => {
type => 'string', type => 'string',
format_description => 'ignore|on',
enum => [qw(ignore on)], enum => [qw(ignore on)],
description => 'Controls whether to pass discard/trim requests to the underlying storage.', description => 'Controls whether to pass discard/trim requests to the underlying storage.',
optional => 1, optional => 1,
@ -787,7 +777,6 @@ my %drivedesc_base = (
my %rerror_fmt = ( my %rerror_fmt = (
rerror => { rerror => {
type => 'string', type => 'string',
format_description => 'ignore|report|stop',
enum => [qw(ignore report stop)], enum => [qw(ignore report stop)],
description => 'Read error action.', description => 'Read error action.',
optional => 1, optional => 1,
@ -796,7 +785,6 @@ my %rerror_fmt = (
my %iothread_fmt = ( iothread => { my %iothread_fmt = ( iothread => {
type => 'boolean', type => 'boolean',
format_description => 'off|on',
description => "Whether to use iothreads for this drive", description => "Whether to use iothreads for this drive",
optional => 1, optional => 1,
}); });
@ -815,7 +803,6 @@ my %model_fmt = (
my %queues_fmt = ( my %queues_fmt = (
queues => { queues => {
type => 'integer', type => 'integer',
format_description => 'nbqueues',
description => "Number of queues.", description => "Number of queues.",
minimum => 2, minimum => 2,
optional => 1 optional => 1
@ -823,11 +810,11 @@ my %queues_fmt = (
); );
my $add_throttle_desc = sub { my $add_throttle_desc = sub {
my ($key, $type, $what, $size, $longsize) = @_; my ($key, $type, $what, $unit, $longunit) = @_;
$drivedesc_base{$key} = { $drivedesc_base{$key} = {
type => $type, type => $type,
format_description => $size, format_description => $unit,
description => "Maximum $what speed in $longsize per second.", description => "Maximum $what speed in $longunit per second.",
optional => 1, optional => 1,
}; };
}; };
@ -916,7 +903,7 @@ my $usb_fmt = {
usb3 => { usb3 => {
optional => 1, optional => 1,
type => 'boolean', type => 'boolean',
format_description => 'yes|no', # format_description => 'yes|no',
description => 'Specifies whether if given host option is a USB3 device or port', description => 'Specifies whether if given host option is a USB3 device or port',
}, },
}; };
@ -1813,37 +1800,37 @@ my $smbios1_fmt = {
version => { version => {
type => 'string', type => 'string',
pattern => '\S+', pattern => '\S+',
format_description => 'str', format_description => 'string',
optional => 1, optional => 1,
}, },
serial => { serial => {
type => 'string', type => 'string',
pattern => '\S+', pattern => '\S+',
format_description => 'str', format_description => 'string',
optional => 1, optional => 1,
}, },
manufacturer => { manufacturer => {
type => 'string', type => 'string',
pattern => '\S+', pattern => '\S+',
format_description => 'name', format_description => 'string',
optional => 1, optional => 1,
}, },
product => { product => {
type => 'string', type => 'string',
pattern => '\S+', pattern => '\S+',
format_description => 'name', format_description => 'string',
optional => 1, optional => 1,
}, },
sku => { sku => {
type => 'string', type => 'string',
pattern => '\S+', pattern => '\S+',
format_description => 'str', format_description => 'string',
optional => 1, optional => 1,
}, },
family => { family => {
type => 'string', type => 'string',
pattern => '\S+', pattern => '\S+',
format_description => 'str', format_description => 'string',
optional => 1, optional => 1,
}, },
}; };
@ -1874,17 +1861,6 @@ sub verify_bootdisk {
die "invalid boot disk '$value'\n"; die "invalid boot disk '$value'\n";
} }
PVE::JSONSchema::register_format('pve-qm-net', \&verify_net);
sub verify_net {
my ($value, $noerr) = @_;
return $value if parse_net($value);
return undef if $noerr;
die "unable to parse network options\n";
}
sub parse_watchdog { sub parse_watchdog {
my ($value) = @_; my ($value) = @_;