2 # NodeManager plugin - first step of handling omf_controlled slices
6 Overwrites the 'resctl' tag of slivers controlled by OMF so slivermanager.py does the right thing
19 logger.log("omf_resctl: plugin starting up...")
21 def GetSlivers(data, conf = None, plc = None):
22 if 'accounts' not in data:
23 logger.log_missing_data("omf_resctl.GetSlivers",'accounts')
27 xmpp_server=data['xmpp']['server']
29 # we have the key but no value, just as bad
32 # disabled feature - bailing out
33 # xxx might need to clean up more deeply..
34 logger.log("PLC config unsufficient (not enabled, or no server set), see the PLC_OMF category -- plugin exiting")
37 # as hrn is set only at AddNode-time, upgraded myplcs might still miss this
38 # clue: just overwrite the hostname of all nodes
39 # for node in GetNodes(): UpdateNode(node['node_id'],{'hostname':node['hostname']})
41 node_hrn = data['hrn']
42 if not node_hrn: raise Exception
44 logger.log("Failed to read hrn from GetSlivers, using 'default' - *please upgrade PLCAPI*")
45 node_hrn='default # Failed to read hrn from GetSlivers, please upgrade PLCAPI'
47 for sliver in data['slivers']:
49 sliver_pub_key_dir=os.path.join("/home", name, ".ssh/")
50 sliver_private_key=os.path.join(sliver_pub_key_dir, "id_rsa")
51 for chunk in sliver['attributes']:
52 if chunk['tagname']=='omf_control':
53 # scan all versions of omf-resctl
54 etc_path="/vservers/%s/etc/"%name
55 pattern = etc_path + "omf-resctl-*/omf-resctl.yaml.in"
56 templates = glob.glob (pattern)
58 logger.log("WARNING: omf_resctl plugin, no template found for slice %s using pattern %s"\
61 for template in templates:
62 # remove the .in extension
64 # figure service name as subdir under etc/
65 service_name=os.path.split(template.replace(etc_path,''))[0]
66 # read template and replace
67 template_contents=file(template).read()
68 yaml_contents=template_contents\
69 .replace('@XMPP_SERVER@',xmpp_server)\
70 .replace('@NODE_HRN@',node_hrn)\
71 .replace('@SLICE_NAME@',name)\
72 .replace('@SLIVER_PRIVATE_KEY@',sliver_private_key)\
73 .replace('@SLIVER_PUB_KEY_DIR@',sliver_pub_key_dir)
74 changes=tools.replace_file_with_string(yaml,yaml_contents)
75 logger.log("yaml_contents length=%d, changes=%r"%(len(yaml_contents),changes))
77 sp=subprocess.Popen(['vserver',name,'exec','service',service_name,'restart'],
78 stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
79 (output,retcod)=sp.communicate()
80 logger.log("omf_resctl: %s: restarted resource controller (retcod=%r)"%(name,retcod))
81 logger.log("omf_resctl: got output\n%s"%output)
83 logger.log("omf_resctl: %s: omf_control'ed sliver has no change" % name)