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
21 ### the new template for v6
22 # hard-wire this for now
23 # once the variables are expanded, this is expected to go into
24 config_ple_template="""---
26 # _slicename_ = nicta_ruby
27 # _hostname_ = planetlab1.research.nicta.com.au
28 # _xmpp_server_ = xmpp.planet-lab.eu
30 :uid: _slicename_@_hostname_
31 :uri: xmpp://_slicename_-_hostname_-<%= "#{Process.pid}" %>:_slicename_-_hostname_-<%= "#{Process.pid}" %>@_xmpp_server_
32 :environment: production
36 :root_cert_dir: /home/_slicename_/root_certs
37 :entity_cert: /home/_slicename_/entity.crt
38 :entity_key: /home/_slicename_/.ssh/id_rsa
41 # the path where the config is expected from within the sliver
42 yaml_slice_path="/etc/omf_rc/config.yml"
43 # the path for the script that we call when a change occurs
44 omf_rc_trigger_script="/some/path/to/the/change/script"
46 def GetSlivers(data, conf = None, plc = None):
47 logger.log("omf_resctl.GetSlivers")
48 if 'accounts' not in data:
49 logger.log_missing_data("omf_resctl.GetSlivers",'accounts')
53 xmpp_server=data['xmpp']['server']
55 # we have the key but no value, just as bad
58 # disabled feature - bailing out
59 # xxx might need to clean up more deeply..
60 logger.log("PLC config unsufficient (not enabled, or no server set), see the PLC_OMF category -- plugin exiting")
63 hostname = data['hostname']
65 def is_omf_friendly (sliver):
66 for chunk in sliver['attributes']:
67 if chunk['tagname']=='omf_control': return True
69 for sliver in data['slivers']:
70 # skip non OMF-friendly slices
71 if not is_omf_friendly (sliver): continue
72 slicename=sliver['name']
73 yaml_template = config_ple_template
74 yaml_contents = yaml_template\
75 .replace('_xmpp_server_',xmpp_server)\
76 .replace('_slicename_',slicename)\
77 .replace('_hostname_',hostname)
78 yaml_full_path="/vservers/%s/%s"%(slicename,yaml_slice_path)
79 yaml_full_dir=os.path.dirname(yaml_full_path)
80 if not os.path.isdir(yaml_full_dir):
81 try: os.makedirs(yaml_full_dir)
84 changes=tools.replace_file_with_string(yaml_full_path,yaml_contents)
85 logger.log("yaml_contents length=%d, changes=%r"%(len(yaml_contents),changes))
87 # instead of restarting the service we call a companion script
89 sp=subprocess.Popen([omf_rc_trigger_script],
90 stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
91 (output,retcod)=sp.communicate()
92 logger.log("omf_resctl: %s: called OMF rc control script (retcod=%r)"%(slicename,retcod))
93 logger.log("omf_resctl: got output\n%s"%output)
95 logger.log("omf_resctl: WARNING: Could not call trigger script %s"%omf_rc_trigger_script)
97 logger.log("omf_resctl: %s: omf_control'ed sliver has no change" % slicename)