From ac32a7847ed26019377496b0849df5127f3b479b Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Fri, 21 Mar 2008 16:35:32 +0000 Subject: [PATCH] support for multiple slice reference images * vserver-reference rpm names have changed and become vserver-@pldistro@-@fcdistro@-@arch@ vserver-systemslices-@pldistro@-@fcdistro@-@arch@ * this contains the images located as /vservers/.vref/@pldistro@-@fcdistro@-@arch@ and /vservers/.vstub/@pldistro@-@fcdistro@-@arch@/planetflow respectively * a stamp gets created on the nodes as /etc/planetlab/defaultvref that contains the name for the default slicefamily to use * nodemanager tries to be smart when chosing the right argument to pass to vuseradd for this purpose, the argument in 'vref' is taken as a dash-separated list of 'wishes' so e.g. is defaultvref is planetlab-f8-x86_64, then we should find for the image name: vref=i386 -> vuseradd -t planetlab-f8-i386 vref=centos5 -> vuseradd -t planetlab-centos5-x86_64 vref=planetflow -> vuseradd -t planetflow vref=centos5-onelab -> vuseradd -t onelab-centos5-x86_64 for legacy reasons, if the stamp is not found, 'default' is taken instead === status * this is only partly tested * a given node can install several variants of vserver-* this would require a manual upload of the rpms into the right install-rpms and manual changes in yumgroups. * next improvement would be to have the system (planetflow) slices have a smarter naming scheme as well this way a 'planetflow' vref would rather be rewritten as planetflow-f8-x86_64 for the time being it is not supported to install several variants of vserver-systemslices on the node - although it should be harmless --- NodeManager.spec | 4 +++- sliver_vs.py | 55 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/NodeManager.spec b/NodeManager.spec index f02dd37..fcf3bc6 100644 --- a/NodeManager.spec +++ b/NodeManager.spec @@ -3,6 +3,8 @@ # %define url $URL$ +%define slicefamily %{pldistro}-%{distroname}-%{_arch} + %define name NodeManager %define version 1.7 %define taglevel 2 @@ -27,7 +29,7 @@ URL: %(echo %{url} | cut -d ' ' -f 2) Obsoletes: sidewinder, sidewinder-common # vuseradd, vuserdel -Requires: vserver-reference +Requires: vserver-%{slicefamily} Requires: util-vserver >= 0.30.208-17 # vserver.py diff --git a/sliver_vs.py b/sliver_vs.py index 2f183c8..ca5d144 100644 --- a/sliver_vs.py +++ b/sliver_vs.py @@ -17,7 +17,7 @@ don't have to guess if there is a running process or not. """ import errno -import os +import os, os.path import time import vserver @@ -67,10 +67,55 @@ class Sliver_VS(accounts.Account, vserver.VServer): @staticmethod def create(name, vref = None): logger.verbose('Sliver_VS:create - name=%s'%name) - if vref is not None: - logger.log_call('/usr/sbin/vuseradd', '-t', vref, name) - else: - logger.log_call('/usr/sbin/vuseradd', name) + if vref is None: + vref='default' + try: + ### locating the right slicefamily + # 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() + (pldistro,fcdistro,arch) = default.split("-") + # 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": + arch=wish + elif wish == "planetlab" or wish == "onelab" or wish == "vini": + pldistro=wish + elif wish == "f8" or wish == "centos5" : + 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) ) + # 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"%( + name,vref,refname,default)) + refname=default + except IOError: + # have not found defaultvref + logger.verbose("%s (%s): using fallback vrefname 'default'"%(name,vref)) + # for legacy nodes + refname="default" + except: + import traceback + logger.log("%s (%s) : unexpected error follows - using 'default'"%( + name,vref)) + logger.log(traceback.format_exc()) + + logger.log_call('/usr/sbin/vuseradd', '-t', refname, name) open('/vservers/%s/etc/slicename' % name, 'w').write(name) @staticmethod -- 2.43.0