2 Configure interfaces inside a container by pulling down files via URL.
11 from hashlib import sha1 as sha
19 try: return sha(f.read()).digest()
25 logger.log("interfaces: plugin starting up...")
27 PREFIX = "# ----- This section added by nodemanager hostmap module. Do not edit. -----"
28 SUFFIX = "# ----- End -----"
30 def GetSlivers(data, config=None, plc=None):
32 if 'slivers' not in data:
33 logger.log_missing_data("hostmap.GetSlivers",'slivers')
36 if 'hostname' not in data:
37 logger.log_missing_data("hostmap.GetSlivers", 'hostname')
39 hostname = data['hostname']
41 for sliver in data['slivers']:
42 slicename = sliver['name']
43 for tag in sliver['attributes']:
44 if tag['tagname'] == 'slice_hostmap':
45 fn = "/vservers/%s/etc/hosts" % slicename
46 if not os.path.exists(fn):
49 contents = file(fn,"r").read()
52 for index, entry in enumerate(tag["value"].split("\n")):
53 parts = entry.split(" ")
55 if parts[1] == hostname:
56 line = "127.0.0.1 %s.%s private%d" % (slicename, parts[1], index)
58 line = "%s %s.%s private%d" % (parts[0], slicename, parts[1], index)
61 line = line + " headnode"
65 hostmap = "\n".join(hostmap)
66 hostmap = PREFIX + "\n" + hostmap + "\n" + SUFFIX + "\n"
68 if (hostmap in contents):
72 # remove anything between PREFIX and SUFFIX from contents
74 pattern = PREFIX + ".*" + SUFFIX + "\n"
75 regex = re.compile(pattern, re.DOTALL)
76 if regex.search(contents) != None:
77 contents = regex.sub(hostmap, contents)
79 contents = contents + hostmap
82 file(fn, "w").write(contents)
84 logger.log_exc("hostmap (%s): failed to write %s" % (slicename, fn))