Commit Graph

162 Commits

Author SHA1 Message Date
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
Fabian Grünbichler
34f860a262 fix #923: uninitalized value in remove_lock 2016-04-01 07:15:21 +02:00
Dietmar Maurer
df79b4284d get_property_description: introduce new $style parameter
config => colon separated config files
arg => command line argument
fixed => fixed command line argument (see usage_str())
2016-03-31 05:57:37 +02:00
Wolfgang Bumiller
166e27c74f cleanup: whitespace and than/then typo 2016-03-23 11:38:26 +01:00
Dietmar Maurer
a736ac996c get_property_description: add new 'text' format 2016-03-23 10:19:15 +01:00
Dietmar Maurer
921f91d1d5 get_property_description: use correct base name opt[n] 2016-03-23 09:27:18 +01:00
Dietmar Maurer
8fa050cd62 new PVE::RESTHandler::dump_properties
The plan is to replace code in PodParser.
2016-03-23 06:58:10 +01:00
Dietmar Maurer
8ff24fe8cb fix spelling errors 2016-03-22 10:39:16 +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
Fabian Grünbichler
5f80891404 add missing check for undef in is_mounted 2016-03-16 16:47:51 +01:00
Wolfgang Bumiller
ab08ec798d net: don't die in get_active_interfaces() and try both address families 2016-03-15 06:45:29 +01:00
Wolfgang Bumiller
c4534006af cleanup: regex match group reference
Don't refer to the regex match group via $1 after running
other code.
2016-03-09 17:58:08 +01:00
Wolfgang Bumiller
1b915170db net: improve ingress tc filter
Instead of doing a dummy "0 == 0" comparison with the u32
filter just use the 'basic' filter.
2016-03-08 15:58:57 +01:00
Wolfgang Bumiller
bce2a5b34c net: tap_plug() needs to apply rate limiting
Any action we take in tap_plug() when using OVS will undo
our rate limiting, which means any hotplug change must
restore the previous rate setting.
Since this means tap_plug() would always be followed by a
tap_rate_limit() call anyway we just include the rate
parameter here and let the caller decide whether the full
tap_plug() is required or the simple tap_rate_limit()
suffices.
2016-03-08 15:50:17 +01:00
Wolfgang Bumiller
ad066ae2de network: tap_rate_limit: fix uninitialized value 2016-03-08 15:50:03 +01:00
Wolfgang Bumiller
5a917b429a pod: skip aliases in generate_property_text
These are special and have no other properties to access.
2016-03-08 12:00:56 +01:00
Fabian Grünbichler
246232024f Decide whether volume is added as unused in subclass
since we need the volume ID of the volume/drive/mp, which is
only available after parsing, this needs to be done in the
subclasses.

__snapshot_delete_vol_snapshot() gets a new parameter, and
pushes the volid to this array if it should be added as
unused.
2016-03-08 11:33:28 +01:00
Fabian Grünbichler
ba9db5df17 Introduce __snapshot_create_vol_snapshots_hook
This hook runs before and after creating volume snapshots,
as well as after unfreezing. Only needed for Qemu right now,
so the base case in PVE::AbstractConfig is a noop.
2016-03-08 11:32:24 +01:00
Fabian Grünbichler
53c255218e Add AbstractConfig base class
This class contains common code formerly duplicated in
PVE::LXC and PVE::QemuServer, as well as abstract methods
that must be implemented for LXC and Qemu seperately.

Currently implemented in PVE::LXC::Config, Qemu refactoring
will follow.
2016-03-03 10:11:51 +01:00
Thomas Lamprecht
19e95cd08f Add since and until parameter to dump_journal
journalctl can check their validness itself
2016-03-02 06:22:47 +01:00
Wolfgang Bumiller
7b1e4b04b2 pod: generate property string documentation
Generate the more detailed documentation with the
'description' property provided in the property-string
format schema for the '*.conf'(5) manpages.
2016-02-27 10:38:38 +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
f029c1d092 network: get rid of ioctl.ph 2016-02-12 11:17:20 +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
44acb12c27 added syncfs syscall and sync_mountpoint helper 2016-02-11 11:24:11 +01:00
Wolfgang Bumiller
12a235d624 Fix #882: active state of interfaces depends on ipv6
read_etc_network_interfaces used the content of
/proc/net/if_inet6 to decide whether an interface's state is
"active", which means an interface is only active when it
has an ipv6 address, thus using net.ipv6.conf.*.disable_ipv6
on an interface will cause it to show as inactive in the web
interface.

We now filter the interfaces found in /proc/dev/net by their
IFF_UP flag read via an SIOCGIFFLAGS ioctl().
2016-02-10 12:20:21 +01:00
Fabian Grünbichler
f127adaba5 Implement refcounting for flocks
This was already implemented in PVE::LXC::lock_aquire() and
lock_release(). Enabling refcounting in the general
PVE::Tools::lock_file() and lock_file_full() methods allows
us to use one code base for flocking.

Furthermore, we could get rid of various xx_no_lock methods
that were required because the old non-refcounting version
did not support nested flocks (the inner most flock would
close the file handle and thus release the flock).
2016-02-10 11:12:12 +01:00
Wolfgang Bumiller
881eb75531 CLIHandler: add missing use PVE::INotify
It uses PVE::INotify::inotify_init() in run_cli_handler().
2016-02-10 10:26:33 +01:00
Thomas Lamprecht
c1073fdc48 add upid_wait method
Waits for a process identified by a UPID to end by busy waiting
and is intended for long running workers.

waitfunc gets called every wait cycle after min $sleep_interval
seconds and can be used for outputting/logging something or timing
out the wait.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2016-01-27 16:54:50 +01:00
Dietmar Maurer
ebd2b0aca5 SectionConfig: disable duplicate plugin registration 2016-01-26 13:16:19 +01:00
Wolfgang Bumiller
891b224a8f Tools: add setns system call 2016-01-23 08:59:07 +01:00
Wolfgang Bumiller
846337ad41 network: fix uninitialized value error 2016-01-18 11:01:35 +01:00
Alexandre Derumier
b0b34ffd4e network : add trunks support
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
2016-01-15 17:25:42 +01:00
Wolfgang Bumiller
e34c27f474 Fix #861: use safer sprintf formatting 2016-01-08 12:49:40 +01:00
Dietmar Maurer
7a83df1bc9 improve asciidoc markup 2015-12-29 18:43:12 +01:00
Dietmar Maurer
fe3f1fdef1 add experimental 'asciidoc' generator
useful to generate manual pages using asciidoc.
2015-12-29 17:02:00 +01:00
Thomas Lamprecht
b148e99f3f Output also lockname if it cannot be acquired
If we can't acquire the lock in lock_file_full and get interrupted
by a signal inqeual to EINTR (e.g. SIGTERM), output also it's name
in the error message to allow better debugging.

Also fix a typo.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2015-12-19 09:05:00 +01:00
Thomas Lamprecht
e4a1d8e240 allow fall back to default completion
This allows a fall back to the default completion, which completes
possible paths/files, if nothing can be generated from the PVE
completion handler ($print_bash_completion) or if the user starts
to entry a path.
This is especially useful for restore or create commands which can
take an archive file as argument.

The bash-completions get generated at each package build through the
respective Makefile, so to let this change come in effect the package
needs to be rebuild and installed (and the respective file from
/usr/share/bash-completion/completions/<pve cli tool> needs to be
sourced again (or simply open a new terminal))

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2015-12-19 09:04:40 +01:00
Wolfgang Bumiller
9db0800b69 Daemon: don't clear CLOEXEC on daemon sockets
They were leaking into processes blocking full restarts of
the daemons.

Note that perl's fcntl doesn't work on numeric
filedescriptors (neither does POSIX::fcntl, which even stays
silent about it and returns EBADF without ever trying to
actually perform the fcntl syscall), so the socket handles
need to be stored ($daemon_sockets).
The flag is added back when the socket gets reopened.
2015-12-07 11:16:44 +01:00
Thomas Lamprecht
7e82692825 run_command: return exit code and add noerr
Allow to return the exit code of the executed command.
And as we do not reach the return of the exit code if it was not 0,
a noerr parameter is also needed so we can suppress the 'command
failed' die in case of an exit code unequal to 0.

This is required as some programs return another value than 0 when
they succeed, For example `systemctl list-jobs` returns  a value
>= 0 on a successful execution, normally 1.
Without this patch a run_command call to `systemctl list-jobs` gets
marked as failed although it was successful.

This does not break current behaviour in any way as setting the
noerr parameter is required to return something other than 0 or
undef, which are equal in a boolean comparison.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2015-11-30 12:59:45 +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 Link
23e0e0d786 add function file_copy
to have a save copy.
2015-11-26 08:08:31 +01:00
Dietmar Maurer
34eb365639 avoid access to undefinded var $tag 2015-11-19 06:23:12 +01:00
Wolfgang Bumiller
072dfa92a5 ProcFSTools: implement conforming parse_mounts
There are a few places where we grep over /proc/mounts
without taking the encoding into acount.
ProcFSTools::parse_mounts parses mount data and decodes all
the special character the kernel might encode into it.

Shortcut: parse_proc_mounts to do
parse_mounts(read_proc_mounts()).
is_mounted() updated to parse mounts correctly.
2015-11-13 11:16:13 +01:00
Wolfgang Bumiller
be8f0477bc fix CLONE constant declaration 2015-10-30 11:04:51 +01:00
Wolfgang Bumiller
817c6be02c Tools: make unshare behave like other perl syscalls
Most syscall wrappers in perl return 1 on success and our
current use of Tools::unshare isn't using the return value
(yet), so let's fix this while we can.

Also it seems to make sense to use prototyping on syscalls
to add some compile-time argument checking.
2015-10-30 11:03:55 +01:00