1#
2# Migration test migration operation progress
3#
4# Copyright (c) 2016 Red Hat, Inc.
5#
6# This library is free software; you can redistribute it and/or
7# modify it under the terms of the GNU Lesser General Public
8# License as published by the Free Software Foundation; either
9# version 2.1 of the License, or (at your option) any later version.
10#
11# This library is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14# Lesser General Public License for more details.
15#
16# You should have received a copy of the GNU Lesser General Public
17# License along with this library; if not, see <http://www.gnu.org/licenses/>.
18#
19
20
21class ProgressStats(object):
22
23    def __init__(self,
24                 transferred_bytes,
25                 remaining_bytes,
26                 total_bytes,
27                 duplicate_pages,
28                 skipped_pages,
29                 normal_pages,
30                 normal_bytes,
31                 dirty_rate_pps,
32                 transfer_rate_mbs,
33                 iterations):
34        self._transferred_bytes = transferred_bytes
35        self._remaining_bytes = remaining_bytes
36        self._total_bytes = total_bytes
37        self._duplicate_pages = duplicate_pages
38        self._skipped_pages = skipped_pages
39        self._normal_pages = normal_pages
40        self._normal_bytes = normal_bytes
41        self._dirty_rate_pps = dirty_rate_pps
42        self._transfer_rate_mbs = transfer_rate_mbs
43        self._iterations = iterations
44
45    def serialize(self):
46        return {
47            "transferred_bytes": self._transferred_bytes,
48            "remaining_bytes": self._remaining_bytes,
49            "total_bytes": self._total_bytes,
50            "duplicate_pages": self._duplicate_pages,
51            "skipped_pages": self._skipped_pages,
52            "normal_pages": self._normal_pages,
53            "normal_bytes": self._normal_bytes,
54            "dirty_rate_pps": self._dirty_rate_pps,
55            "transfer_rate_mbs": self._transfer_rate_mbs,
56            "iterations": self._iterations,
57        }
58
59    @classmethod
60    def deserialize(cls, data):
61        return cls(
62            data["transferred_bytes"],
63            data["remaining_bytes"],
64            data["total_bytes"],
65            data["duplicate_pages"],
66            data["skipped_pages"],
67            data["normal_pages"],
68            data["normal_bytes"],
69            data["dirty_rate_pps"],
70            data["transfer_rate_mbs"],
71            data["iterations"])
72
73
74class Progress(object):
75
76    def __init__(self,
77                 status,
78                 ram,
79                 now,
80                 duration,
81                 downtime,
82                 downtime_expected,
83                 setup_time,
84                 throttle_pcent):
85
86        self._status = status
87        self._ram = ram
88        self._now = now
89        self._duration = duration
90        self._downtime = downtime
91        self._downtime_expected = downtime_expected
92        self._setup_time = setup_time
93        self._throttle_pcent = throttle_pcent
94
95    def serialize(self):
96        return {
97            "status": self._status,
98            "ram": self._ram.serialize(),
99            "now": self._now,
100            "duration": self._duration,
101            "downtime": self._downtime,
102            "downtime_expected": self._downtime_expected,
103            "setup_time": self._setup_time,
104            "throttle_pcent": self._throttle_pcent,
105        }
106
107    @classmethod
108    def deserialize(cls, data):
109        return cls(
110            data["status"],
111            ProgressStats.deserialize(data["ram"]),
112            data["now"],
113            data["duration"],
114            data["downtime"],
115            data["downtime_expected"],
116            data["setup_time"],
117            data["throttle_pcent"])
118