Cleaned up Cobbler provisioner

This commit is contained in:
Maxim Kulkin 2012-05-15 15:50:46 +04:00
parent 21d5443406
commit 62f0c27c8e
3 changed files with 45 additions and 57 deletions

View File

@ -0,0 +1,35 @@
import logging
class ProvisionerException:
def __init__(self, message=""):
self.message = message
def __str__(self):
return self.message
class Provisioner:
"""
Abstract provisioner.
FIXME:
At the moment you have to use child classes like ProvisionerCobbler that implement
abstract provisioner api. For future it would be nice to use Provisioner itself and
initialize definite implementation via config data.
"""
logger_name = 'provisioner'
def set_node(self, **data):
raise ProvisionerException("Must be implemented")
def list_nodes(self):
raise ProvisionerException("Must be implemented")

View File

@ -1,37 +1,24 @@
import logging
import xmlrpclib
from provisioner import ProvisionerException
from provisioner import Provisioner
from . import Provisioner, ProvisionerException
class ProvisionerCobbler(Provisioner):
class CobblerProvisioner(Provisioner):
"""
Cobbler provisioner implementation.
Cobbler provisioner.
"""
def __init__(self, **data):
def __init__(self, cobbler_url, cobbler_user, cobbler_password):
self.logger = logging.getLogger(self.logger_name)
self.cobbler_url = cobbler_url
self.cobbler_user = cobbler_user
self.cobbler_password = cobbler_password
if 'cobbler_url' not in data:
self.logger.error('Cobbler url was not provided.')
raise ProvisionerException("You must provide cobbler_url.")
self.logger.debug('Cobbler url provided: %s' % str(data['cobbler_url']))
self.cobbler_url = data['cobbler_url']
if 'cobbler_user' not in data or 'cobbler_password' not in data:
self.logger.error('Cobbler credentials were not provided correctly.')
raise ProvisionerException("You must provide cobbler_user and cobbler_password.")
self.logger.debug('Cobbler credentials: cobbler_user=%s, cobbler_password=%s' % (str(data['cobbler_user']), str(data['cobbler_password'])))
self.cobbler_user = data['cobbler_user']
self.cobbler_password = data['cobbler_password']
self.logger.debug('Cobbler config: url="%s", user="%s", password="%s"' % (cobbler_url, cobbler_user, cobbler_password))
self.server = xmlrpclib.Server(self.cobbler_url)
try:
self.server = xmlrpclib.Server(self.cobbler_url)
self.token = self.server.login(self.cobbler_user, self.cobbler_password)
except Exception as e:
self.logger.error('Error occured while connecting to cobbler server.')
@ -44,3 +31,4 @@ class ProvisionerCobbler(Provisioner):
def list_nodes(self):
return self.server.get_systems()

View File

@ -1,35 +0,0 @@
import logging
class ProvisionerException:
def __init__(self, message=""):
self.message = message
def __str__(self):
return self.message
class Provisioner:
"""
Abstract provisioner.
FIXME:
At the moment you have to use child classes like ProvisionerCobbler that implement
abstract provisioner api. For future it would be nice to use Provisioner itself and
initialize definite implementation via config data.
"""
logger_name = 'provisioner'
def set_node(self, **data):
raise ProvisionerException("Must be implemented")
def list_nodes(self):
raise ProvisionerException("Must be implemented")