[bonfiredemokit] Annotation of /virt-cluster/vc/hostsfile.py
Annotation of /virt-cluster/vc/hostsfile.py
Parent Directory
| Revision Log
Revision 1 -
(view)
(download)
(as text)
1 : |
agomez |
1 |
def load(file_path):
|
2 : |
|
|
hosts = {}
|
3 : |
|
|
with open(file_path) as file:
|
4 : |
|
|
for line in file:
|
5 : |
|
|
line = line.strip()
|
6 : |
|
|
if not line or line.startswith('#'):
|
7 : |
|
|
continue
|
8 : |
|
|
elements = line.split()
|
9 : |
|
|
hosts[elements[0]] = elements[1:]
|
10 : |
|
|
return hosts
|
11 : |
|
|
|
12 : |
|
|
def store(file_path,hosts):
|
13 : |
|
|
output = "\n".join([ " ".join(list(host)) for host in hosts ]) + "\n"
|
14 : |
|
|
with open(file_path,'w') as file:
|
15 : |
|
|
file.write(output)
|
16 : |
|
|
|
17 : |
|
|
def append(file_path,ip,hostname):
|
18 : |
|
|
with open(file_path,'a') as file:
|
19 : |
|
|
file.write("\n%s %s\n" % (ip,hostname))
|
|