-
Notifications
You must be signed in to change notification settings - Fork 1
/
manual.py
58 lines (45 loc) · 2.13 KB
/
manual.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Module for communcating with subscription-manager,
part of virt-whom, based on virt-who
Copyright (C) 2014 Carter Kozak <[email protected]>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
"""
class Manual(object):
def __init__(self, logger, hypervisors=None):
self.logger = logger
self.hypervisorList = hypervisors or []
self._parse_hypervisor_list()
def getHostGuestMapping(self):
return self.hypervisors
def ping(self):
return True
def _parse_hypervisor_list(self):
self.hypervisors = dict([self._parse_hypervisor(line) for line in self.hypervisorList])
def _parse_hypervisor(self, hypervisor_raw):
'''
takes a raw string such as "aaa-aaaa-aaa:bbb-ccc,ddd-eee" and parses it into
a key, value tuple ("aaa-aaaa-aaa", ["bbb-ccc", "ddd-eee"])
'''
data_parts = hypervisor_raw.split(':')
if len(data_parts) > 2 or not data_parts[0].strip():
raise ValueError("Hypervisor info must take the form 'hypervisorId:guestid1,guestid2,etc'")
hypervisor = data_parts[0].strip()
guestIds = []
if len(data_parts) == 2:
guestIds = filter(None, [guest.strip() for guest in data_parts[1].split(',')])
# Create full representation of the guest
guests = [self._create_guest(guestId) for guestId in guestIds]
return (hypervisor, guests)
def _create_guest(self, guest_id):
return {'guestId': guest_id,
'attributes': {'virtWhoType': 'manual'}}