Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a264fdc7
authored
Apr 18, 2014
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common, vm: register operations based on their 'host_cls' attribute by default
parent
50fb8a87
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
20 deletions
+25
-20
circle/common/operations.py
+12
-1
circle/vm/operations.py
+13
-19
No files found.
circle/common/operations.py
View file @
a264fdc7
...
@@ -128,7 +128,7 @@ class OperatedMixin(object):
...
@@ -128,7 +128,7 @@ class OperatedMixin(object):
(
self
.
__class__
.
__name__
,
name
))
(
self
.
__class__
.
__name__
,
name
))
def
register_operation
(
target_cls
,
op_cls
,
op_id
=
None
):
def
register_operation
(
op_cls
,
op_id
=
None
,
target_cls
=
None
):
"""Register the specified operation with the target class.
"""Register the specified operation with the target class.
You can optionally specify an ID to be used for the registration;
You can optionally specify an ID to be used for the registration;
...
@@ -144,6 +144,17 @@ def register_operation(target_cls, op_cls, op_id=None):
...
@@ -144,6 +144,17 @@ def register_operation(target_cls, op_cls, op_id=None):
"host. Alternatively, provide the name "
"host. Alternatively, provide the name "
"in the 'op_id' parameter to this call."
)
"in the 'op_id' parameter to this call."
)
if
target_cls
is
None
:
try
:
target_cls
=
op_cls
.
host_cls
except
AttributeError
:
raise
NotImplementedError
(
"Operations should specify a 'host_cls' "
"attribute designating the host class "
"the operation should be registered to. "
"Alternatively, provide the host class "
"in the 'target_cls' parameter to this "
"call."
)
if
not
issubclass
(
target_cls
,
OperatedMixin
):
if
not
issubclass
(
target_cls
,
OperatedMixin
):
raise
TypeError
(
"
%
r is not a subclass of
%
r"
%
raise
TypeError
(
"
%
r is not a subclass of
%
r"
%
(
target_cls
.
__name__
,
OperatedMixin
.
__name__
))
(
target_cls
.
__name__
,
OperatedMixin
.
__name__
))
...
...
circle/vm/operations.py
View file @
a264fdc7
...
@@ -20,6 +20,7 @@ logger = getLogger(__name__)
...
@@ -20,6 +20,7 @@ logger = getLogger(__name__)
class
InstanceOperation
(
Operation
):
class
InstanceOperation
(
Operation
):
acl_level
=
'owner'
acl_level
=
'owner'
async_operation
=
async_instance_operation
async_operation
=
async_instance_operation
host_cls
=
Instance
def
__init__
(
self
,
instance
):
def
__init__
(
self
,
instance
):
super
(
InstanceOperation
,
self
)
.
__init__
(
subject
=
instance
)
super
(
InstanceOperation
,
self
)
.
__init__
(
subject
=
instance
)
...
@@ -54,10 +55,6 @@ class InstanceOperation(Operation):
...
@@ -54,10 +55,6 @@ class InstanceOperation(Operation):
user
=
user
)
user
=
user
)
def
register_instance_operation
(
op_cls
,
op_id
=
None
):
return
register_operation
(
Instance
,
op_cls
,
op_id
)
class
DeployOperation
(
InstanceOperation
):
class
DeployOperation
(
InstanceOperation
):
activity_code_suffix
=
'deploy'
activity_code_suffix
=
'deploy'
id
=
'deploy'
id
=
'deploy'
...
@@ -91,7 +88,7 @@ class DeployOperation(InstanceOperation):
...
@@ -91,7 +88,7 @@ class DeployOperation(InstanceOperation):
self
.
instance
.
renew
(
which
=
'both'
,
base_activity
=
activity
)
self
.
instance
.
renew
(
which
=
'both'
,
base_activity
=
activity
)
register_
instance_
operation
(
DeployOperation
)
register_operation
(
DeployOperation
)
class
DestroyOperation
(
InstanceOperation
):
class
DestroyOperation
(
InstanceOperation
):
...
@@ -131,7 +128,7 @@ class DestroyOperation(InstanceOperation):
...
@@ -131,7 +128,7 @@ class DestroyOperation(InstanceOperation):
self
.
instance
.
save
()
self
.
instance
.
save
()
register_
instance_
operation
(
DestroyOperation
)
register_operation
(
DestroyOperation
)
class
MigrateOperation
(
InstanceOperation
):
class
MigrateOperation
(
InstanceOperation
):
...
@@ -161,7 +158,7 @@ class MigrateOperation(InstanceOperation):
...
@@ -161,7 +158,7 @@ class MigrateOperation(InstanceOperation):
self
.
instance
.
deploy_net
()
self
.
instance
.
deploy_net
()
register_
instance_
operation
(
MigrateOperation
)
register_operation
(
MigrateOperation
)
class
RebootOperation
(
InstanceOperation
):
class
RebootOperation
(
InstanceOperation
):
...
@@ -174,7 +171,7 @@ class RebootOperation(InstanceOperation):
...
@@ -174,7 +171,7 @@ class RebootOperation(InstanceOperation):
self
.
instance
.
reboot_vm
(
timeout
=
timeout
)
self
.
instance
.
reboot_vm
(
timeout
=
timeout
)
register_
instance_
operation
(
RebootOperation
)
register_operation
(
RebootOperation
)
class
ResetOperation
(
InstanceOperation
):
class
ResetOperation
(
InstanceOperation
):
...
@@ -186,7 +183,7 @@ class ResetOperation(InstanceOperation):
...
@@ -186,7 +183,7 @@ class ResetOperation(InstanceOperation):
def
_operation
(
self
,
activity
,
user
,
system
,
timeout
=
5
):
def
_operation
(
self
,
activity
,
user
,
system
,
timeout
=
5
):
self
.
instance
.
reset_vm
(
timeout
=
timeout
)
self
.
instance
.
reset_vm
(
timeout
=
timeout
)
register_
instance_
operation
(
ResetOperation
)
register_operation
(
ResetOperation
)
class
SaveAsTemplateOperation
(
InstanceOperation
):
class
SaveAsTemplateOperation
(
InstanceOperation
):
...
@@ -255,7 +252,7 @@ class SaveAsTemplateOperation(InstanceOperation):
...
@@ -255,7 +252,7 @@ class SaveAsTemplateOperation(InstanceOperation):
return
tmpl
return
tmpl
register_
instance_
operation
(
SaveAsTemplateOperation
)
register_operation
(
SaveAsTemplateOperation
)
class
ShutdownOperation
(
InstanceOperation
):
class
ShutdownOperation
(
InstanceOperation
):
...
@@ -284,7 +281,7 @@ class ShutdownOperation(InstanceOperation):
...
@@ -284,7 +281,7 @@ class ShutdownOperation(InstanceOperation):
self
.
instance
.
yield_vnc_port
()
self
.
instance
.
yield_vnc_port
()
register_
instance_
operation
(
ShutdownOperation
)
register_operation
(
ShutdownOperation
)
class
ShutOffOperation
(
InstanceOperation
):
class
ShutOffOperation
(
InstanceOperation
):
...
@@ -310,7 +307,7 @@ class ShutOffOperation(InstanceOperation):
...
@@ -310,7 +307,7 @@ class ShutOffOperation(InstanceOperation):
self
.
instance
.
yield_vnc_port
()
self
.
instance
.
yield_vnc_port
()
register_
instance_
operation
(
ShutOffOperation
)
register_operation
(
ShutOffOperation
)
class
SleepOperation
(
InstanceOperation
):
class
SleepOperation
(
InstanceOperation
):
...
@@ -346,7 +343,7 @@ class SleepOperation(InstanceOperation):
...
@@ -346,7 +343,7 @@ class SleepOperation(InstanceOperation):
# VNC port needs to be kept
# VNC port needs to be kept
register_
instance_
operation
(
SleepOperation
)
register_operation
(
SleepOperation
)
class
WakeUpOperation
(
InstanceOperation
):
class
WakeUpOperation
(
InstanceOperation
):
...
@@ -386,11 +383,12 @@ class WakeUpOperation(InstanceOperation):
...
@@ -386,11 +383,12 @@ class WakeUpOperation(InstanceOperation):
self
.
instance
.
renew
(
which
=
'both'
,
base_activity
=
activity
)
self
.
instance
.
renew
(
which
=
'both'
,
base_activity
=
activity
)
register_
instance_
operation
(
WakeUpOperation
)
register_operation
(
WakeUpOperation
)
class
NodeOperation
(
Operation
):
class
NodeOperation
(
Operation
):
async_operation
=
async_node_operation
async_operation
=
async_node_operation
host_cls
=
Node
def
__init__
(
self
,
node
):
def
__init__
(
self
,
node
):
super
(
NodeOperation
,
self
)
.
__init__
(
subject
=
node
)
super
(
NodeOperation
,
self
)
.
__init__
(
subject
=
node
)
...
@@ -413,10 +411,6 @@ class NodeOperation(Operation):
...
@@ -413,10 +411,6 @@ class NodeOperation(Operation):
node
=
self
.
node
,
user
=
user
)
node
=
self
.
node
,
user
=
user
)
def
register_node_operation
(
op_cls
,
op_id
=
None
):
return
register_operation
(
Node
,
op_cls
,
op_id
)
class
FlushOperation
(
NodeOperation
):
class
FlushOperation
(
NodeOperation
):
activity_code_suffix
=
'flush'
activity_code_suffix
=
'flush'
id
=
'flush'
id
=
'flush'
...
@@ -430,4 +424,4 @@ class FlushOperation(NodeOperation):
...
@@ -430,4 +424,4 @@ class FlushOperation(NodeOperation):
i
.
migrate
()
i
.
migrate
()
register_
node_
operation
(
FlushOperation
)
register_operation
(
FlushOperation
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment