import struct
import threading
import xmlrpclib
-import sliver_lxc
+import slivermanager
try:
from PLC.Parameter import Parameter, Mixed
# A better approach will involve more extensive code splitting, I think.
try: import database
except: import logger as database
-#try: import sliver_vs
-#except: import logger as sliver_vs
import ticket as ticket_module
import tools
@export_to_api(0)
def GetXIDs():
"""Return an dictionary mapping Slice names to XIDs"""
- return dict([(pwent[0], pwent[2]) for pwent in pwd.getpwall() if pwent[6] == sliver_lxc.Sliver_LXC.SHELL])
+ return dict([(pwent[0], pwent[2]) for pwent in pwd.getpwall() if pwent[6] == slivermanager.sliver_password_shell])
@export_to_docbook(roles=['self'],
accepts=[],
import logger
import os
-import libvirt
+
from config import Config
+import slivermanager
CODEMUXCONF="/etc/codemux/codemux.conf"
try:
# Check to see if sliver is running. If not, continue
- if isLXCDomRunning(sliver['name']):
+ if slivermanager.is_running(sliver['name']):
# Check if new or needs updating
if (sliver['name'] not in slicesinconf.keys()) \
or (params not in slicesinconf.get(sliver['name'], [])):
logger.log_call(["/etc/init.d/codemux", "stop", ])
logger.log_call(["/sbin/chkconfig", "codemux", "off"])
-def isLXCDomRunning(domName):
- try:
- running = False
- conn = libvirt.open('lxc://')
- dom = conn.lookupByName(domName)
- running = dom.info()[0] == libvirt.VIR_DOMAIN_RUNNING
- finally:
- conn.close()
- return running
-
-#
"""Sliver manager.
The sliver manager has several functions. It is responsible for
import database
import account
import controller
-import sliver_lxc
-try: from bwlimitlxc import bwmin, bwmax
-except ImportError: bwmin, bwmax = 8, 1000*1000*1000
+try:
+ import sliver_lxc
+ implementation='lxc'
+ sliver_default_type='sliver.LXC'
+ sliver_class_to_register = sliver_lxc.Sliver_LXC
+ sliver_password_shell = sliver_lxc.Sliver_LXC.SHELL
+except:
+ import sliver_vs
+ implementation='vs'
+ sliver_default_type='sliver.VServer'
+ sliver_class_to_register = sliver_vs.Sliver_VS
+ sliver_password_shell = sliver_vs.Sliver_VS.SHELL
+
+# temporary - hopefully bwlimit will be packaged separately and there will be no need to do this any longer
+try:
+ from bwlimitlxc import bwmin, bwmax
+except:
+ try : from bwlimit import bwmin, bwmax
+ except: bwmin, bwmax = 8, 1000*1000*1000
priority=10
if rec['instantiation'].lower() == 'nm-controller':
rec.setdefault('type', attributes.get('type', 'controller.Controller'))
else:
- rec.setdefault('type', attributes.get('type', 'sliver.LXC'))
+ rec.setdefault('type', attributes.get('type', sliver_default_type))
# set the vserver reference. If none, set to default.
rec.setdefault('vref', attributes.get('vref', 'default'))
def start():
# No default allocation values for LXC yet, think if its necessary given
# that they are also default allocation values in this module
- #for resname, default_amount in sliver_vs.DEFAULT_ALLOCATION.iteritems():
- # DEFAULT_ALLOCATION[resname]=default_amount
+ if implementation == 'vs':
+ for resname, default_amount in sliver_vs.DEFAULT_ALLOCATION.iteritems():
+ DEFAULT_ALLOCATION[resname]=default_amount
- account.register_class(sliver_lxc.Sliver_LXC)
+ account.register_class(sliver_class_to_register)
account.register_class(controller.Controller)
database.start()
api_calls.deliver_ticket = deliver_ticket
api.start()
+
+### check if a sliver is running
+### a first step to a unified code for codemux
+def is_running (name):
+ if implementation=='vs':
+ import vserver
+ return vserver.VServer(name).is_running()
+ else:
+ import libvirt
+ running = False
+ try:
+ conn = libvirt.open('lxc://')
+ dom = conn.lookupByName(name)
+ running = dom.info()[0] == libvirt.VIR_DOMAIN_RUNNING
+ finally:
+ conn.close()
+ return running