Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cc-node
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
cc-node
Commits
ef2e708f
Commit
ef2e708f
authored
12 years ago
by
Anael Beutot
Browse files
Options
Downloads
Patches
Plain Diff
Moved singleton metaclass in utils.py.
parent
051833c8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cloudcontrol/node/hypervisor/jobs.py
+2
-15
2 additions, 15 deletions
cloudcontrol/node/hypervisor/jobs.py
cloudcontrol/node/utils.py
+13
-0
13 additions, 0 deletions
cloudcontrol/node/utils.py
with
15 additions
and
15 deletions
cloudcontrol/node/hypervisor/jobs.py
+
2
−
15
View file @
ef2e708f
...
...
@@ -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
'
...
...
This diff is collapsed.
Click to expand it.
cloudcontrol/node/utils.py
+
13
−
0
View file @
ef2e708f
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment