- if chunk['tagname']=='omf_control':
- # scan all versions of omf-resctl
- etc_path="/vservers/%s/etc/"%name
- pattern = etc_path + "omf-resctl-*/omf-resctl.yaml.in"
- templates = glob.glob (pattern)
- if not templates:
- logger.log("WARNING: omf_resctl plugin, no template found for slice %s using pattern %s"\
- %(name,pattern))
- continue
- for template in templates:
- # remove the .in extension
- yaml=template[:-3]
- # figure service name as subdir under etc/
- service_name=os.path.split(template.replace(etc_path,''))[0]
- # read template and replace
- template_contents=file(template).read()
- yaml_contents=template_contents\
- .replace('@XMPP_SERVER@',xmpp_server)\
- .replace('@NODE_HRN@','default # xxx todo in omf-resctl nm plugin')\
- .replace('@SLICE_NAME@',name)
- changes=tools.replace_file_with_string(yaml,yaml_contents)
- if changes:
- sp=subprocess.Popen(['vserver',name,'exec','service',service_name,'restart'],
- stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
- (output,retcod)=sp.communicate()
- logger.log("omf_resctl: %s: restarted resource controller (retcod=%r)"%(name,retcod))
- logger.log("omf_resctl: got output\n%s"%output)
- else:
- logger.log("omf_resctl: %s: omf_control'ed sliver has no change" % name)
+ if chunk['tagname']=='omf_control': return True
+
+ for sliver in data['slivers']:
+ # skip non OMF-friendly slices
+ if not is_omf_friendly (sliver): continue
+ slicename=sliver['name']
+ expires=str(sliver['expires'])
+ yaml_template = config_ple_template
+ yaml_contents = yaml_template\
+ .replace('_xmpp_server_',xmpp_server)\
+ .replace('_slicename_',slicename)\
+ .replace('_hostname_',hostname)\
+ .replace('_expires_',expires)
+ yaml_full_path="/vservers/%s/%s"%(slicename,yaml_slice_path)
+ yaml_full_dir=os.path.dirname(yaml_full_path)
+ if not os.path.isdir(yaml_full_dir):
+ try: os.makedirs(yaml_full_dir)
+ except OSError: pass
+
+ config_changes=tools.replace_file_with_string(yaml_full_path,yaml_contents)
+ logger.log("yaml_contents length=%d, config_changes=%r"%(len(yaml_contents),config_changes))
+ # would make sense to also check for changes to authorized_keys
+ # would require saving a copy of that some place for comparison
+ # xxx todo
+ keys_changes = False
+ if config_changes or keys_changes:
+ # instead of restarting the service we call a companion script
+ try:
+ fetch_trigger_script_if_missing (slicename)
+ # the trigger script actually needs to be run in the slice context of course
+ # in addition there is a requirement to pretend we run as a login shell
+ # hence sudo -i
+ slice_command = [ "sudo", "-i", omf_rc_trigger_script ]
+ to_run = tools.command_in_slice (slicename, slice_command)
+ log_filename = "/vservers/%s/%s"%(slicename,omf_rc_trigger_log)
+ logger.log("omf_resctl: starting %s"%to_run)
+ logger.log("redirected into %s"%log_filename)
+ logger.log("*not* waiting for completion..")
+ with open(log_filename,"a") as log_file:
+ subprocess.Popen(to_run, stdout=log_file,stderr=subprocess.STDOUT)
+ # a first version tried to 'communicate' on that subprocess instance
+ # but that tended to create deadlocks in some cases
+ # causing nodemanager to stall...
+ # we're only losing the child's retcod, no big deal
+ except:
+ import traceback
+ traceback.print_exc()
+ logger.log_exc("omf_resctl: WARNING: Could not call trigger script %s"%\
+ omf_rc_trigger_script, name=slicename)
+ else:
+ logger.log("omf_resctl: %s: omf_control'ed sliver has no change" % slicename)