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 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        self._cpus = cpus
28        self._mem = mem # GiB
29        self._src_mem_bind = src_mem_bind # List of NUMA nodes
30        self._src_cpu_bind = src_cpu_bind # List of pCPUs
31        self._dst_mem_bind = dst_mem_bind # List of NUMA nodes
32        self._dst_cpu_bind = dst_cpu_bind # List of pCPUs
33        self._prealloc_pages = prealloc_pages
34        self._huge_pages = huge_pages
35        self._locked_pages = locked_pages
36
37
38    def serialize(self):
39        return {
40            "cpus": self._cpus,
41            "mem": self._mem,
42            "src_mem_bind": self._src_mem_bind,
43            "dst_mem_bind": self._dst_mem_bind,
44            "src_cpu_bind": self._src_cpu_bind,
45            "dst_cpu_bind": self._dst_cpu_bind,
46            "prealloc_pages": self._prealloc_pages,
47            "huge_pages": self._huge_pages,
48            "locked_pages": self._locked_pages,
49        }
50
51    @classmethod
52    def deserialize(cls, data):
53        return cls(
54            data["cpus"],
55            data["mem"],
56            data["src_cpu_bind"],
57            data["src_mem_bind"],
58            data["dst_cpu_bind"],
59            data["dst_mem_bind"],
60            data["prealloc_pages"],
61            data["huge_pages"],
62            data["locked_pages"])
63