Commit graph

17 commits

Author SHA1 Message Date
Ruslan Kuprieiev
7197aff703 pycriu: images: pb2dict: preserve fields order with "pretty" option
Using collections.OrderedDict allows us to keep fields in the
same order as they appear in corresponding proto files, which
helps to impove readability. In non-pretty mode we still use
regular dict.

Signed-off-by: Ruslan Kuprieiev <rkuprieiev@cloudlinux.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-06-24 17:56:31 +03:00
Pavel Emelyanov
dbda403b8d crit: Avoid full exception trace when meeting unknown magic in image (v2)
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Andrew Vagin <avagin@virtuozzo.com>
2015-05-30 00:32:27 +03:00
Ruslan Kuprieiev
f57fdd34f3 pycriu: images: support netns.img
Reported-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Tested-by: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-05-08 15:33:56 +03:00
Ruslan Kuprieiev
300451fef1 crit: pycriu: images: fix images incoding and add more comments
Signed-off-by: Ruslan Kuprieiev <rkuprieiev@cloudlinux.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-04-14 15:18:33 +03:00
Pavel Emelyanov
f5ea330ce1 img: Introduce v1.1 images (v2)
These images have common magic in front of per-image one. With
this we have 3 "types" of images -- inventory (head), other
images, service files. The latter would be stats (not an image,
just happen to be in PB format) and irmap cache (not an image
again, just auxiliary thing which is in PB for convenience).

Since inventory file is the first one we read on restore it's
OK to set the global "new images" flag there. Dump (write) is
always in new format.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Ruslan Kuprieiev <rkuprieiev@cloudlinux.com>
Acked-by: Andrew Vagin <avagin@odin.com>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
2015-04-14 15:18:32 +03:00
Pavel Emelyanov
9ebb3738b2 crit: Print IP addresses in pretty mode
There are two places where we store IP addresses (both IPv4 and IPv6).
Mark them with custom option and print them in compressed form for
--pretty output.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Ruslan Kuprieiev <kupruser@gmail.com>
2015-01-29 18:47:30 +03:00
Pavel Emelyanov
0d2aeb3581 crit: Get rid of --format option
I plan to mark some fields as IP address and print them respectively.
The --format hex is not nice switch for this and introducing one more
(--format hex ipadd) is too bad.

So let's fix the cirt API to be simple and stupid. By default crit
generates canonical one-line JSON. With --pretty option it splits the
output into lines, adds indentation and prints hex as hex and IP as
IP.

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Acked-by: Ruslan Kuprieiev <kupruser@gmail.com>
2015-01-29 18:47:13 +03:00
Ruslan Kuprieiev
b0f40a2726 pycriu: images: treat tcp_stream image extra properly
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-29 18:43:36 +03:00
Ruslan Kuprieiev
0dc9c9837f pycriu: images: pb2dict: don't forget to throw an exception, if field has unsupported type
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-22 18:58:06 +03:00
Pavel Emelyanov
837e38fd73 crit: Fix uninitialized print_hex
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-22 17:23:47 +04:00
Ruslan Kuprieiev
87da3e3437 crit: add --format hex option
Pavel reported that decimal values for some fields are hard to read,
because people used to see hex values in there. Unfortunately, json
doesn't support hex representation of integers, so we can only store
them as hex strings. Not all field need to be represented as hex
strings, so this set introduces a custom field option called "criu"
to use in our proto files. One should use [(criu).hex = true] to mark
which field should be represented as a hex string. pb2dict module
from pycriu package will look into field options and if he finds that
criu.hex is set to True, it will convert such field to/from hex string.
Though, such behaviour is optional and user can request it by specifying
 --format hex when calling crit decode("crit encode" in its turn, detects
such fields automatically and doesn't require any special cmdline options
to be set).

We need our proto files to compile with both protoc and
protoc-c compilers, which requires creating google/protobuf
directory with a symlink to /usr/include/google/protobuf/
descriptor.proto to make protoc-c and generated c files happy.

Reported-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-19 18:13:55 +04:00
Ruslan Kuprieiev
a9ccdccc34 pycriu: images: pb2dict: perform pb<->json conversion properly
Currently we are handling conversion in the simplest way, by
just parsing protobuf text format representation of pb message,
splitting string in half and storing values wrapped in ""-s
in python dict. Which leads to a bunch of errors, like,
for example, when converting bytes fields. It also doesn't
handle types properly.

This patch introduces a proper way to handle pb<->json conversion
by iterating through pb fields and properly storing them in dict
or properly extracting values from dict.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-15 20:46:23 +04:00
Pavel Emelyanov
8878793d39 crit: Fix sk-queues extra handler variable name
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-15 02:07:00 +04:00
Ruslan Kuprieiev
0956230709 pycriu: images: mention raw data images when throwing an 'Unknown magic' exception
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-14 20:47:48 +04:00
Ruslan Kuprieiev
598a83cfd3 pycriu:images: treat pagemap.img as a special one
pagemap.img is the special one, as it starts with an entry
of pagemap_head type and is followed by entries of
pagemap_entry type. Currently we treat pagemap as if
pagemap_head is a payload and pagemap_entry's are
an extra, which is wrong.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-14 20:47:45 +04:00
Ruslan Kuprieiev
4997896bf4 pycriu: images: merge payload field into entry and add extra field to entry if needed
Before:
{
    "magic" : "FOO",
    "entries" : [
        {
            "payload" : {
                "foo" : "bar",
                "bar" : "foo"
            },
            "extra" : "abc"
        },
        {
            "payload" : {
            "foo" : "bar",
            "bar" : "foo"
            },
            "extra" : "abc"
        }
    ]
}

After:
{
    "magic" : "FOO",
    "entries" : [
        {
            "foo" : "bar",
            "bar" : "foo"
            "extra" : "abc"
        },
        {
            "foo" : "bar",
            "bar" : "foo"
            "extra" : "abc"
        }
    ]
}

We don't have any fields named "extra" in our pb msgs and it is
not likely that we will ever have one, so there is no reason to
worry about that.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-14 20:47:44 +04:00
Ruslan Kuprieiev
dfe8f838cf pycriu: add python package
pycriu is a python package, that, for now, consists
of rpc module and images package. rpc module contains
data structures for interacting with CRIU RPC.
images package contains methods for loading\dumping
criu images.

See a big comment below in pycriu/images/images.py file.

Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
2015-01-14 20:44:46 +04:00