import xmlrpclib
import datetime
import traceback
+from types import StringTypes
+
import utils
from TestSite import TestSite
from TestNode import TestNode
def uninstall_vserver(self,options):
self.run_in_host("vserver --silent %s delete"%self.vservername)
+ return True
def uninstall(self,options):
if self.vserver:
### install
def install_chroot(self,options):
- utils.header('Installing from %s'%options.myplc_url)
- url=options.myplc_url
- utils.system('rpm -Uvh '+url)
- utils.system('service plc mount')
+ # nothing to do
return True
# xxx this would not work with hostname != localhost as mylc-init-vserver was extracted locally
- def install_vserver_create(self,options):
- # we need build dir for myplc-init-vserver
+ def install_vserver(self,options):
+ # we need build dir for vtest-init-vserver
build_dir=self.path+"/build"
if not os.path.isdir(build_dir):
if utils.system("svn checkout %s %s"%(options.build_url,build_dir)) != 0:
repo_url = options.myplc_url
repo_url = os.path.dirname(repo_url)
repo_url = os.path.dirname(repo_url)
- command="%s/myplc-init-vserver.sh %s %s -- --interface eth0:%s"%\
+ command="%s/vtest-init-vserver.sh %s %s -- --interface eth0:%s"%\
(build_dir,self.vservername,repo_url,self.vserverip)
if utils.system(command) != 0:
raise Exception,"Could not create vserver for %s"%self.vservername
+ # xxx temporary - initialize /etc/sysconfig/networking
+ networking="NETWORKING=yes\nHOSTNAME=%s\n"%self.plc_spec['vserverhostname']
+ file("/vservers/%s/etc/sysconfig/networking"%vservername,"w").write(networking)
+ return True
+
+ def install(self,options):
+ if self.vserver:
+ return self.install_vserver(options)
+ else:
+ return self.install_chroot(options)
+
+ ### install_rpm
+ def install_rpm_chroot(self,options):
+ utils.header('Installing from %s'%options.myplc_url)
+ url=options.myplc_url
+ utils.system('rpm -Uvh '+url)
+ utils.system('service plc mount')
return True
- def install_vserver_native(self,options):
+ def install_rpm_vserver(self,options):
self.run_in_guest("yum -y install myplc-native")
return True
- def install(self,options):
+ def install_rpm(self,options):
if self.vserver:
- return self.install_vserver_create(options)
- return self.install_vserver_yum(options)
+ return self.install_rpm_vserver(options)
else:
- return self.install_chroot(options)
+ return self.install_rpm_chroot(options)
###
def configure(self,options):
return self.do_sites(options)
def clean_sites (self,options):
- return self.do_sites(options,"delete")
+ return self.do_sites(options,action="delete")
def do_sites (self,options,action="add"):
for site_spec in self.plc_spec['sites']:
test_site = TestSite (self,site_spec)
- if (action == "delete"):
+ if (action != "add"):
utils.header("Deleting site %s in %s"%(test_site.name(),self.name()))
test_site.delete_site()
# deleted with the site
return True
def nodes (self, options):
+ return self.do_nodes(options)
+ def clean_nodes (self, options):
+ return self.do_nodes(options,action="delete")
+
+ def do_nodes (self, options,action="add"):
+ for site_spec in self.plc_spec['sites']:
+ test_site = TestSite (self,site_spec)
+ if action != "add":
+ utils.header("Deleting nodes in site %s"%test_site.name())
+ for node_spec in site_spec['nodes']:
+ test_node=TestNode(self,test_site,node_spec)
+ utils.header("Deleting %s"%test_node.name())
+ test_node.delete_node()
+ else:
+ utils.header("Creating nodes for site %s in %s"%(test_site.name(),self.name()))
+ for node_spec in site_spec['nodes']:
+ utils.show_spec('Creating node %s'%node_spec,node_spec)
+ test_node = TestNode (self,test_site,node_spec)
+ test_node.create_node ()
+ return True
+
+ # create nodegroups if needed, and populate
+ # no need for a clean_nodegroups if we are careful enough
+ def nodegroups (self, options):
+ # 1st pass to scan contents
+ groups_dict = {}
for site_spec in self.plc_spec['sites']:
test_site = TestSite (self,site_spec)
- utils.header("Creating nodes for site %s in %s"%(test_site.name(),self.name()))
for node_spec in site_spec['nodes']:
- utils.show_spec('Creating node %s'%node_spec,node_spec)
- test_node = TestNode (self,test_site,node_spec)
- test_node.create_node ()
+ test_node=TestNode (self,test_site,node_spec)
+ if node_spec.has_key('nodegroups'):
+ nodegroupnames=node_spec['nodegroups']
+ if isinstance(nodegroupnames,StringTypes):
+ nodegroupnames = [ nodegroupnames ]
+ for nodegroupname in nodegroupnames:
+ if not groups_dict.has_key(nodegroupname):
+ groups_dict[nodegroupname]=[]
+ groups_dict[nodegroupname].append(test_node.name())
+ auth=self.auth_root()
+ for (nodegroupname,group_nodes) in groups_dict.iteritems():
+ try:
+ self.server.GetNodeGroups(auth,{'name':nodegroupname})[0]
+ except:
+ self.server.AddNodeGroup(auth,{'name':nodegroupname})
+ for node in group_nodes:
+ self.server.AddNodeToNodeGroup(auth,node,nodegroupname)
return True
def bootcd (self, options):
def initscripts (self, options):
for initscript in self.plc_spec['initscripts']:
- utils.show_spec('Adding Initscript %s in plc %s'%\
- (initscript['name'],self.plc_spec['name']),
- initscript)
+ utils.show_spec('Adding Initscript in plc %s'%self.plc_spec['name'],initscript)
self.server.AddInitScript(self.auth_root(),initscript['initscript_fields'])
return True