1#
2# Migration test hardware configuration description
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 Hardware(object):
22    def __init__(self, cpus=1, mem=1,
23                 src_cpu_bind=None, src_mem_bind=None,
24                 dst_cpu_bind=None, dst_mem_bind=None,
25                 prealloc_pages = False,
26                 huge_pages=False, locked_pages=False,
27                 dirty_ring_size=0):
28        self._cpus = cpus
29        self._mem = mem # GiB
30        self._src_mem_bind = src_mem_bind # List of NUMA nodes
31        self._src_cpu_bind = src_cpu_bind # List of pCPUs
32        self._dst_mem_bind = dst_mem_bind # List of NUMA nodes
33        self._dst_cpu_bind = dst_cpu_bind # List of pCPUs
34        self._prealloc_pages = prealloc_pages
35        self._huge_pages = huge_pages
36        self._locked_pages = locked_pages
37        self._dirty_ring_size = dirty_ring_size
38
39
40    def serialize(self):
41        return {
42            "cpus": self._cpus,
43            "mem": self._mem,
44            "src_mem_bind": self._src_mem_bind,
45            "dst_mem_bind": self._dst_mem_bind,
46            "src_cpu_bind": self._src_cpu_bind,
47            "dst_cpu_bind": self._dst_cpu_bind,
48            "prealloc_pages": self._prealloc_pages,
49            "huge_pages": self._huge_pages,
50            "locked_pages": self._locked_pages,
51            "dirty_ring_size": self._dirty_ring_size,
52        }
53
54    @classmethod
55    def deserialize(cls, data):
56        return cls(
57            data["cpus"],
58            data["mem"],
59            data["src_cpu_bind"],
60            data["src_mem_bind"],
61            data["dst_cpu_bind"],
62            data["dst_mem_bind"],
63            data["prealloc_pages"],
64            data["huge_pages"],
65            data["locked_pages"],
66            data["dirty_ring_size"])
67