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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
# Hosts
#
# Copyright (C) 2016 Andrew Cagney <cagney@gnu.org>
#
# 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. See <https://www.gnu.org/licenses/gpl2.txt>.
#
# 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.
import re
from os import path
from fab import utilsdir
class Host:
def __init__(self, name):
self.name = name
def __str__(self):
return self.name
def __lt__(self, peer):
return self.name < peer.name
class Guest:
def __init__(self, host, platform=None, guest=None):
self.platform = platform # netbsd, freebsd, ...
self.host = host # east, west, ...
self.name = guest or host.name
def __str__(self):
return self.name
def __lt__(self, peer):
return self.name < peer.name
class Set(set):
def __str__(self):
return " ".join(str(s) for s in self)
HOSTS = Set()
for xml in utilsdir.glob("../kvm/vm/*.xml"):
host = re.match(r'^.*/(.*).xml$', xml).group(1)
# For hosts, ignor E,W,N,...
if len(host) == 1:
continue
HOSTS.add(Host(host))
# should have kvm/platform/*
PLATFORMS = Set()
for t in utilsdir.glob("../kvm/*/upgrade.sh"):
# after the "*" in pattern
p = path.basename(path.dirname(t))
PLATFORMS.add(p)
GUESTS = Set()
for host in HOSTS:
if host.name in ("rise", "set"):
for platform in PLATFORMS:
GUESTS.add(Guest(host, platform, platform+host.name))
continue
if host.name in ("east", "west"):
GUESTS.add(Guest(host))
for platform in PLATFORMS:
GUESTS.add(Guest(host, platform, platform+host.name[0:1]))
continue
GUESTS.add(Guest(host))
# A dictionary, with GUEST_NAME (as used to manipulate the domain
# externally) as the KEY and HOST_NAME (what `hostname` within the
# domain would return) as the value.
_LOOKUP = dict()
for guest in GUESTS:
_LOOKUP[guest.name] = guest
def lookup(name):
if name in _LOOKUP:
return _LOOKUP[name]
return None
NIC = _LOOKUP["nic"]
EAST = _LOOKUP["east"]
|