X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sliver_vs.py;h=48d7a4780bbd303bdf8812dc8b161c25b1841179;hb=09bd9c14822b9dd1dc133bcb3f02f54dbd94b49f;hp=f1c381efd90855be7aebc2bf54f83d8e69d80700;hpb=673e1ce1fc12e96341f12d9cd45efd280569c38d;p=nodemanager.git diff --git a/sliver_vs.py b/sliver_vs.py index f1c381e..48d7a47 100644 --- a/sliver_vs.py +++ b/sliver_vs.py @@ -24,6 +24,9 @@ import vserver import accounts import logger import tools +from threading import BoundedSemaphore + +globalsem = BoundedSemaphore() # special constant that tells vserver to keep its existing settings KEEP_LIMIT = vserver.VC_LIM_KEEP @@ -42,7 +45,7 @@ class Sliver_VS(accounts.Account, vserver.VServer): SHELL = '/bin/vsh' TYPE = 'sliver.VServer' - _init_disk_info_sem = tools.NMLock("/var/run/nm-disk-info.lock") + _init_disk_info_sem = globalsem def __init__(self, rec): logger.verbose ('initing Sliver_VS with name=%s'%rec['name']) @@ -60,6 +63,7 @@ class Sliver_VS(accounts.Account, vserver.VServer): self.keys = '' self.rspec = {} self.initscript = '' + self.slice_id = rec['slice_id'] self.disk_usage_initialized = False self.initscriptchanged = False self.configure(rec) @@ -74,39 +78,44 @@ class Sliver_VS(accounts.Account, vserver.VServer): # this is a first draft, and more a proof of concept thing # the idea is to parse vref for dash-separated wishes, # and to project these against the defaults - # however for cases like when vref is 'planetflow', if we do not understand - # any of the wishes we take vref as is - # this could be improved by having the vserver-reference init script be a bit smarter - # so we could take planetflow as the pldistro part here - as_is=None - # defaults - default=file("/etc/planetlab/defaultvref").read() + # so e.g. if the default slice family (as found in /etc/planetlab/slicefamily) + # is planetlab-f8-i386, then here is what we get + # vref=x86_64 -> vuseradd -t planetlab-f8-x86_64 + # vref=centos5 -> vuseradd -t planetlab-centos5-i386 + # vref=centos5-onelab -> vuseradd -t onelab-centos5-i386 + # vref=planetflow -> vuseradd -t planetflow-f8-i386 + # vref=x86_64-planetflow -> vuseradd -t planetflow-f8-x86_64 + + # default + default=file("/etc/planetlab/slicefamily").read().strip() (pldistro,fcdistro,arch) = default.split("-") + + known_archs = [ 'i386', 'x86_64' ] + known_fcdistros = [ 'f8', 'f9', 'centos5' ] # from the slice attribute: cut dashes and try to figure the meaning slice_wishes = vref.split("-") for wish in slice_wishes: - if wish == "i386" or wish == "x86_64": + if wish in known_archs: arch=wish - elif wish == "planetlab" or wish == "onelab" or wish == "vini": - pldistro=wish - elif wish == "f8" or wish == "centos5" : + elif wish in known_fcdistros: fcdistro=wish else: - # if we find something like e.g. planetflow, use it as-is - as_is=vref - break - if as_is: - refname=as_is - else: - refname="-".join( (pldistro,fcdistro,arch) ) + pldistro=wish + + # rejoin the parts + refname="-".join( (pldistro,fcdistro,arch) ) + # check the templates exists -- there's probably a better way.. if not os.path.isdir ("/vservers/.vref/%s"%refname): - log.verbose("%s (%s) : vref %s not found, using default %s"%( + logger.verbose("%s (%s) : vref %s not found, using default %s"%( name,vref,refname,default)) refname=default + # could check again, but as we have /etc/slicefamily + # there's probably no /vservers/.vref/default + except IOError: - # have not found defaultvref - logger.verbose("%s (%s): using fallback vrefname 'default'"%(name,vref)) + # have not found slicefamily + logger.verbose("%s (%s): legacy node - using fallback vrefname 'default'"%(name,vref)) # for legacy nodes refname="default" except: @@ -150,9 +159,10 @@ class Sliver_VS(accounts.Account, vserver.VServer): time.sleep(delay) child_pid = os.fork() if child_pid == 0: - # VServer.start calls fork() internally, so just close the nonstandard fds and fork once to avoid creating zombies + # VServer.start calls fork() internally, + # so just close the nonstandard fds and fork once to avoid creating zombies tools.close_nonstandard_fds() - vserver.VServer.start(self, True) + vserver.VServer.start(self) os._exit(0) else: os.waitpid(child_pid, 0) else: logger.log('%s: not starting, is not enabled' % self.name) @@ -196,18 +206,6 @@ class Sliver_VS(accounts.Account, vserver.VServer): if self.rspec['capabilities']: logger.log('%s: setting capabilities to %s' % (self.name, self.rspec['capabilities'])) - if False: # this code was commented out before - # N.B. net_*_rate are in kbps because of XML-RPC maxint - # limitations, convert to bps which is what bwlimit.py expects. - net_limits = (self.rspec['net_min_rate'] * 1000, - self.rspec['net_max_rate'] * 1000, - self.rspec['net_i2_min_rate'] * 1000, - self.rspec['net_i2_max_rate'] * 1000, - self.rspec['net_share']) - logger.log('%s: setting net limits to %s bps' % (self.name, net_limits[:-1])) - logger.log('%s: setting net share to %d' % (self.name, net_limits[-1])) - self.set_bwlimit(*net_limits) - cpu_pct = self.rspec['cpu_pct'] cpu_share = self.rspec['cpu_share'] @@ -225,9 +223,14 @@ class Sliver_VS(accounts.Account, vserver.VServer): self.set_sched_config(cpu_pct, cpu_share) # if IP address isn't set (even to 0.0.0.0), sliver won't be able to use network if self.rspec['ip_addresses'] != '0.0.0.0': - logger.log('%s: setting IP address(es) to %s' % (self.name, self.rspec['ip_addresses'])) + logger.log('%s: setting IP address(es) to %s' % \ + (self.name, self.rspec['ip_addresses'])) self.set_ipaddresses_config(self.rspec['ip_addresses']) + if self.is_running(): + logger.log("%s: Setting name to %s" % (self.name, self.slice_id),2) + self.setname(self.slice_id) + if False: # Does not work properly yet. if self.have_limits_changed(): logger.log('%s: limits have changed --- restarting' % self.name)