Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
fc00f3a5
authored
Nov 19, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
occi: rework occi post data to list function into a mixin
parent
0c07829d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
15 deletions
+22
-15
circle/occi/views.py
+22
-15
No files found.
circle/occi/views.py
View file @
fc00f3a5
...
...
@@ -31,12 +31,23 @@ class CSRFExemptMixin(object):
return
super
(
CSRFExemptMixin
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
def
get_post_data_from_request
(
request
):
class
OCCIPostDataAsListMixin
(
object
):
def
get_post_data
(
self
,
request
):
""" Returns the post data in an array
"""
post_data
=
[]
accept
=
request
.
META
.
get
(
"HTTP_ACCEPT"
)
if
accept
and
accept
.
split
(
","
)[
0
]
==
"text/occi"
:
post_data
=
self
.
_parse_from_header
(
request
)
else
:
# text/plain or missing
for
l
in
request
.
readlines
():
if
l
:
post_data
.
append
(
l
.
strip
())
return
post_data
def
_parse_from_header
(
self
,
request
):
post_data
=
[]
for
k
,
v
in
request
.
META
.
iteritems
():
if
k
.
startswith
(
"HTTP_X_OCCI_ATTRIBUTE"
):
for
l
in
v
.
split
(
","
):
...
...
@@ -44,10 +55,6 @@ def get_post_data_from_request(request):
if
k
.
startswith
(
"HTTP_CATEGORY"
):
for
l
in
v
.
split
(
","
):
post_data
.
append
(
"Category:
%
s"
%
l
.
strip
())
else
:
# text/plain or missing
for
l
in
request
.
readlines
():
if
l
:
post_data
.
append
(
l
.
strip
())
return
post_data
...
...
@@ -77,7 +84,7 @@ class QueryInterface(CSRFExemptMixin, View):
return
response
class
ComputeInterface
(
CSRFExemptMixin
,
View
):
class
ComputeInterface
(
CSRFExemptMixin
,
OCCIPostDataAsListMixin
,
View
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
response
=
"
\n
"
.
join
([
Compute
(
instance
=
i
)
.
render_location
()
...
...
@@ -88,7 +95,7 @@ class ComputeInterface(CSRFExemptMixin, View):
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
data
=
get_post_data_from_request
(
request
)
data
=
self
.
get_post_data
(
request
)
c
=
Compute
.
create_object
(
data
=
data
)
response
=
HttpResponse
(
...
...
@@ -99,7 +106,7 @@ class ComputeInterface(CSRFExemptMixin, View):
return
response
class
VmInterface
(
CSRFExemptMixin
,
DetailView
):
class
VmInterface
(
CSRFExemptMixin
,
OCCIPostDataAsListMixin
,
DetailView
):
model
=
Instance
def
get_object
(
self
):
...
...
@@ -115,7 +122,7 @@ class VmInterface(CSRFExemptMixin, DetailView):
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
data
=
get_post_data_from_request
(
request
)
data
=
self
.
get_post_data
(
request
)
action
=
request
.
GET
.
get
(
"action"
)
vm
=
self
.
get_object
()
if
action
:
...
...
@@ -143,7 +150,7 @@ class OsTplInterface(CSRFExemptMixin, View):
pass
class
StorageInterface
(
CSRFExemptMixin
,
View
):
class
StorageInterface
(
CSRFExemptMixin
,
OCCIPostDataAsListMixin
,
View
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
response
=
"
\n
"
.
join
([
Storage
(
disk
=
d
)
.
render_location
()
...
...
@@ -154,7 +161,7 @@ class StorageInterface(CSRFExemptMixin, View):
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
data
=
get_post_data_from_request
(
request
)
data
=
self
.
get_post_data
(
request
)
d
=
Storage
.
create_object
(
data
=
data
)
response
=
HttpResponse
(
...
...
@@ -165,7 +172,7 @@ class StorageInterface(CSRFExemptMixin, View):
return
response
class
DiskInterface
(
CSRFExemptMixin
,
DetailView
):
class
DiskInterface
(
CSRFExemptMixin
,
OCCIPostDataAsListMixin
,
DetailView
):
model
=
Disk
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
...
...
@@ -178,7 +185,7 @@ class DiskInterface(CSRFExemptMixin, DetailView):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
# TODO actions (we only support resize)
data
=
get_post_data_from_request
(
request
)
data
=
self
.
get_post_data
(
request
)
action
=
request
.
GET
.
get
(
"action"
)
disk
=
self
.
get_object
()
if
action
:
...
...
@@ -190,7 +197,7 @@ class DiskInterface(CSRFExemptMixin, DetailView):
return
HttpResponse
(
""
)
class
StorageLinkInterface
(
CSRFExemptMixin
,
View
):
class
StorageLinkInterface
(
CSRFExemptMixin
,
OCCIPostDataAsListMixin
,
View
):
def
get_vm_and_disk
(
self
):
vm
=
get_object_or_404
(
Instance
.
objects
.
filter
(
destroyed_at
=
None
),
...
...
@@ -217,7 +224,7 @@ class StorageLinkInterface(CSRFExemptMixin, View):
if
request
.
GET
.
get
(
"action"
):
return
HttpResponse
(
""
,
status
=
500
)
data
=
get_post_data_from_request
(
request
)
data
=
self
.
get_post_data
(
request
)
sl
=
StorageLink
.
create_object
(
data
=
data
)
if
sl
:
response
=
HttpResponse
(
...
...
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