Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
452214f8
authored
Oct 27, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
occi: add actions
parent
aff5f70f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
2 deletions
+66
-2
circle/occi/occi.py
+49
-0
circle/occi/views.py
+17
-2
No files found.
circle/occi/occi.py
View file @
452214f8
import
re
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.template.loader
import
render_to_string
from
django.template.loader
import
render_to_string
...
@@ -7,6 +9,29 @@ from vm.models.instance import ACCESS_METHODS
...
@@ -7,6 +9,29 @@ from vm.models.instance import ACCESS_METHODS
OCCI_ADDR
=
"http://localhost:8080/"
OCCI_ADDR
=
"http://localhost:8080/"
occi_attribute_regex
=
re
.
compile
(
'^X-OCCI-Attribute: ?method="(?P<method>[a-zA-Z]+)"$'
)
occi_action_regex
=
re
.
compile
(
'^Category: (?P<term>[a-zA-Z]+); ?scheme=".+"; ?class="action"$'
)
compute_action_to_operation
=
{
'stop'
:
{
'graceful'
:
"shutdown"
,
'acpioff'
:
"shutdown"
,
'poweroff'
:
"shut_off"
,
},
'restart'
:
{
'graceful'
:
"restart"
,
'warm'
:
"restart"
,
'cold'
:
"reset"
,
},
'suspend'
:
{
'suspend'
:
"sleep"
,
'hibernate'
:
"sleep"
,
}
}
class
Category
():
class
Category
():
"""Represents a Category object
"""Represents a Category object
...
@@ -147,6 +172,30 @@ class Compute(Resource):
...
@@ -147,6 +172,30 @@ class Compute(Resource):
for
k
,
v
in
self
.
translate
.
items
():
for
k
,
v
in
self
.
translate
.
items
():
self
.
attrs
[
k
]
=
getattr
(
self
.
instance
,
v
,
None
)
self
.
attrs
[
k
]
=
getattr
(
self
.
instance
,
v
,
None
)
def
trigger_action
(
self
,
data
):
method
=
None
action_term
=
None
for
d
in
data
:
m
=
occi_attribute_regex
.
match
(
d
)
if
m
:
method
=
m
.
group
(
"method"
)
m
=
occi_action_regex
.
match
(
d
)
if
m
:
action_term
=
m
.
group
(
"term"
)
if
action_term
==
"start"
:
if
self
.
instance
.
status
==
"SUSPENDED"
:
operation
=
"wake_up"
else
:
operation
=
"deploy"
else
:
action
=
compute_action_to_operation
.
get
(
action_term
)
operation
=
action
.
get
(
method
)
# TODO user
user
=
User
.
objects
.
get
(
username
=
"test"
)
getattr
(
self
.
instance
,
operation
)
.
async
(
user
=
user
)
class
OsTemplate
(
Mixin
):
class
OsTemplate
(
Mixin
):
def
__init__
(
self
,
template
):
def
__init__
(
self
,
template
):
...
...
circle/occi/views.py
View file @
452214f8
...
@@ -80,8 +80,23 @@ class VmInterface(DetailView):
...
@@ -80,8 +80,23 @@ class VmInterface(DetailView):
)
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
# actions, resource change
data
=
self
.
get_post_data
(
request
)
pass
action
=
request
.
GET
.
get
(
"action"
)
vm
=
self
.
get_object
()
if
action
:
Compute
(
instance
=
vm
)
.
trigger_action
(
data
)
return
HttpResponse
()
def
get_post_data
(
self
,
request
):
post_data
=
[]
accept
=
request
.
META
.
get
(
"HTTP_ACCEPT"
)
if
accept
and
accept
.
split
(
","
)[
0
]
==
"text/occi"
:
pass
else
:
# text/plain or missing
for
l
in
request
.
readlines
():
if
l
:
post_data
.
append
(
l
.
strip
())
return
post_data
@method_decorator
(
csrf_exempt
)
# decorator on post method doesn't work
@method_decorator
(
csrf_exempt
)
# decorator on post method doesn't work
def
dispatch
(
self
,
*
args
,
**
kwargs
):
def
dispatch
(
self
,
*
args
,
**
kwargs
):
...
...
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