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 ### 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 if 'accounts' not in data:
48 logger.log_missing_data("omf_resctl.GetSlivers",'accounts')
52 xmpp_server=data['xmpp']['server']
54 # we have the key but no value, just as bad
57 # disabled feature - bailing out
58 # xxx might need to clean up more deeply..
59 logger.log("PLC config unsufficient (not enabled, or no server set), see the PLC_OMF category -- plugin exiting")
62 hostname = data['hostname']
64 def is_omf_friendly (sliver):
65 for chunk in sliver['attributes']:
66 if chunk['tagname']=='omf_control': return True
68 for sliver in data['slivers']:
69 # skip non OMF-friendly slices
70 if not is_omf_friendly (sliver): continue
71 slicename=sliver['name']
72 yaml_template = config_ple_template
73 yaml_contents = yaml_template\
74 .replace('_xmpp_server_',xmpp_server)\
75 .replace('_slicename_',slicename)\
76 .replace('_hostname_',hostname)
77 yaml_full_path="/vservers/%s/%s"%(slicename,yaml_slice_path)
78 yaml_full_dir=os.path.dirname(yaml_full_path)
79 if not isdir(yaml_full_dir):
80 try: os.makedirs(yaml_full_dir)
83 changes=tools.replace_file_with_string(yaml_full_path,yaml_contents)
84 logger.log("yaml_contents length=%d, changes=%r"%(len(yaml_contents),changes))
86 # instead of restarting the service we call a companion script
87 sp=subprocess.Popen([omf_rc_trigger_script],
88 stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
89 (output,retcod)=sp.communicate()
90 logger.log("omf_resctl: %s: called OMF rc control script (retcod=%r)"%(slicename,retcod))
91 logger.log("omf_resctl: got output\n%s"%output)
93 logger.log("omf_resctl: %s: omf_control'ed sliver has no change" % slicename)