Skip to content
Snippets Groups Projects
Commit ef2e708f authored by Anael Beutot's avatar Anael Beutot
Browse files

Moved singleton metaclass in utils.py.

parent 051833c8
No related branches found
No related tags found
No related merge requests found
......@@ -14,7 +14,7 @@ import pyev
from cloudcontrol.node.exc import TunnelError, DRBDAllocationError, DRBDError
from cloudcontrol.node.jobs import BaseThreadedJob
from cloudcontrol.node.utils import SocketBuffer, subproc_call
from cloudcontrol.node.utils import SocketBuffer, subproc_call, Singleton
logger = logging.getLogger(__name__)
......@@ -573,23 +573,10 @@ class TCPTunnel(object):
# logger.debug('Proccessed write event')
class Meta(type):
"""DRBDAllocator metaclass used for singleton implementation."""
def __init__(cls, name, bases, dict):
super(Meta, cls).__init__(cls, bases, dict)
cls._instance = None
def __call__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(Meta, cls).__call__(*args, **kwargs)
return cls._instance
class DRBDAllocator(object):
"""Keeps a list of allocated DRBD devices."""
__metaclass__ = Meta
__metaclass__ = Singleton
RMMOD = '/sbin/rmmod'
MODPROBE = '/sbin/modprobe'
......
......@@ -81,3 +81,16 @@ class SocketBuffer(deque):
def is_empty(self):
return self.current_len == 0
class Singleton(type):
"""Singleton metaclass."""
def __init__(cls, name, bases, dict):
super(Singleton, cls).__init__(cls, bases, dict)
cls._instance = None
def __call__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instance
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment