Revision 7d6fed3a
b/snf-deploy/snfdeploy/lib.py | ||
---|---|---|
36 | 36 |
if not sys.stdout.isatty(): |
37 | 37 |
disable_color() |
38 | 38 |
|
39 |
|
|
39 | 40 |
class Host(object): |
40 | 41 |
def __init__(self, hostname, ip, mac, domain): |
41 | 42 |
self.hostname = hostname |
... | ... | |
58 | 59 |
|
59 | 60 |
class Alias(Host): |
60 | 61 |
def __init__(self, host, alias): |
61 |
super(Alias, self).__init__(host.hostname, host.ip, host.mac, host.domain) |
|
62 |
super(Alias, self).__init__(host.hostname, host.ip, host.mac, |
|
63 |
host.domain) |
|
62 | 64 |
self.alias = alias |
63 | 65 |
|
64 | 66 |
@property |
65 | 67 |
def cnamerecord(self): |
66 |
return self.alias + " IN CNAME " + self.hostname + "." + self.domain + ".\n" |
|
68 |
return (self.alias + " IN CNAME " + self.hostname + "." + |
|
69 |
self.domain + ".\n") |
|
67 | 70 |
|
68 | 71 |
@property |
69 | 72 |
def fqdn(self): |
... | ... | |
85 | 88 |
self.node2hostname = dict(conf.get_section("nodes", "hostnames")) |
86 | 89 |
self.node2ip = dict(conf.get_section("nodes", "ips")) |
87 | 90 |
self.node2mac = dict(conf.get_section("nodes", "macs")) |
88 |
self.hostnames = [self.node2hostname[n] for n in self.nodes.split(",")] |
|
89 |
self.ips = [self.node2ip[n] for n in self.nodes.split(",")] |
|
90 |
self.cluster_hostnames = [self.node2hostname[n] for n in self.cluster_nodes.split(",")] |
|
91 |
self.cluster_ips = [self.node2ip[n] for n in self.cluster_nodes.split(",")] |
|
91 |
self.hostnames = [self.node2hostname[n] |
|
92 |
for n in self.nodes.split(",")] |
|
93 |
|
|
94 |
self.ips = [self.node2ip[n] |
|
95 |
for n in self.nodes.split(",")] |
|
96 |
|
|
97 |
self.cluster_hostnames = [self.node2hostname[n] |
|
98 |
for n in self.cluster_nodes.split(",")] |
|
99 |
|
|
100 |
self.cluster_ips = [self.node2ip[n] |
|
101 |
for n in self.cluster_nodes.split(",")] |
|
92 | 102 |
|
93 | 103 |
self.net = ipaddr.IPNetwork(self.subnet) |
94 | 104 |
|
... | ... | |
96 | 106 |
self.hosts_info = {} |
97 | 107 |
self.ips_info = {} |
98 | 108 |
for node in self.nodes.split(","): |
99 |
host = Host(self.node2hostname[node],
|
|
100 |
self.node2ip[node],
|
|
101 |
self.node2mac[node], self.domain)
|
|
109 |
host = Host(self.node2hostname[node], |
|
110 |
self.node2ip[node], |
|
111 |
self.node2mac[node], self.domain) |
|
102 | 112 |
|
103 | 113 |
self.nodes_info[node] = host |
104 | 114 |
self.hosts_info[host.hostname] = host |
105 | 115 |
self.ips_info[host.ip] = host |
106 | 116 |
|
107 |
self.cluster = Host(self.cluster_name, self.cluster_ip, None, self.domain) |
|
117 |
self.cluster = Host(self.cluster_name, self.cluster_ip, None, |
|
118 |
self.domain) |
|
108 | 119 |
self.master = self.nodes_info[self.master_node] |
109 | 120 |
|
110 | 121 |
self.roles = {} |
... | ... | |
112 | 123 |
self.roles[role] = Alias(self.nodes_info[node], role) |
113 | 124 |
setattr(self, role, self.roles[role]) |
114 | 125 |
|
126 |
|
|
115 | 127 |
class Conf(object): |
116 | 128 |
|
117 | 129 |
files = { |
118 |
"nodes": ["network", "info"], |
|
119 |
"deploy": ["dirs", "packages"], |
|
120 |
"vcluster": ["cluster", "image"], |
|
121 |
"synnefo": ["cred", "synnefo", "roles"], |
|
122 |
"packages": ["debian", "ganeti", "synnefo", "other"], |
|
123 |
"ganeti": [], |
|
130 |
"nodes": ["network", "info"],
|
|
131 |
"deploy": ["dirs", "packages"],
|
|
132 |
"vcluster": ["cluster", "image"],
|
|
133 |
"synnefo": ["cred", "synnefo", "roles"],
|
|
134 |
"packages": ["debian", "ganeti", "synnefo", "other"],
|
|
135 |
"ganeti": [],
|
|
124 | 136 |
} |
125 | 137 |
|
126 | 138 |
def __init__(self, confdir, cluster_name): |
... | ... | |
186 | 198 |
def debug(host, msg): |
187 | 199 |
|
188 | 200 |
print HEADER + host + \ |
189 |
OKBLUE + ": " + msg + ENDC
|
|
201 |
OKBLUE + ": " + msg + ENDC |
|
190 | 202 |
|
191 | 203 |
|
192 | 204 |
def check_pidfile(pidfile): |
... | ... | |
203 | 215 |
|
204 | 216 |
|
205 | 217 |
def randomMAC(): |
206 |
mac = [ 0x52, 0x54, 0x56,
|
|
207 |
random.randint(0x00, 0xff), |
|
208 |
random.randint(0x00, 0xff), |
|
209 |
random.randint(0x00, 0xff) ]
|
|
218 |
mac = [0x52, 0x54, 0x56, |
|
219 |
random.randint(0x00, 0xff),
|
|
220 |
random.randint(0x00, 0xff),
|
|
221 |
random.randint(0x00, 0xff)]
|
|
210 | 222 |
return ':'.join(map(lambda x: "%02x" % x, mac)) |
211 | 223 |
|
212 | 224 |
|
... | ... | |
222 | 234 |
def get_netinfo(): |
223 | 235 |
_, pdev = get_default_route() |
224 | 236 |
r = re.compile(".*inet (\S+)/(\S+).*") |
225 |
s = subprocess.Popen(['ip', 'addr', 'show', 'dev', pdev], stdout=subprocess.PIPE) |
|
237 |
s = subprocess.Popen(['ip', 'addr', 'show', 'dev', pdev], |
|
238 |
stdout=subprocess.PIPE) |
|
239 |
|
|
226 | 240 |
for line in s.stdout.readlines(): |
227 | 241 |
match = r.search(line) |
228 | 242 |
if match: |
... | ... | |
259 | 273 |
|
260 | 274 |
|
261 | 275 |
def raddr(addr): |
262 |
return list(reversed(addr.replace("/","-").split("."))) |
|
276 |
return list(reversed(addr.replace("/", "-").split("."))) |
Also available in: Unified diff