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
33c94c56
authored
Nov 11, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
occi: create disk
parent
c45a17d0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
5 deletions
+41
-5
circle/occi/occi.py
+32
-3
circle/occi/views.py
+9
-2
No files found.
circle/occi/occi.py
View file @
33c94c56
...
...
@@ -2,7 +2,9 @@ import re
from
django.contrib.auth.models
import
User
from
django.template.loader
import
render_to_string
from
django.utils
import
timezone
from
storage.models
import
Disk
from
vm.models
import
Instance
,
InstanceTemplate
,
Lease
from
vm.models.common
import
ARCHITECTURES
from
vm.models.instance
import
ACCESS_METHODS
,
pwgen
...
...
@@ -290,8 +292,6 @@ class OsTemplate(Mixin):
class
Storage
(
Resource
):
""" Note: 100 priority = 5 Ghz
"""
def
__init__
(
self
,
disk
=
None
,
data
=
None
):
self
.
attrs
=
{}
...
...
@@ -302,7 +302,36 @@ class Storage(Resource):
@classmethod
def
create_object
(
cls
,
data
):
pass
attributes
=
{}
for
d
in
data
:
attr
=
occi_attribute_regex
.
match
(
d
)
if
attr
:
attributes
[
attr
.
group
(
"attribute"
)]
=
attr
.
group
(
"value"
)
size
=
attributes
.
get
(
"occi.storage.size"
)
if
not
(
size
and
size
.
isdigit
()):
return
None
name
=
attributes
.
get
(
"occi.core.title"
)
if
not
name
:
name
=
"disk create from OCCI at
%
s"
%
timezone
.
now
()
# TODO user
user
=
User
.
objects
.
get
(
username
=
"test"
)
params
=
{
'user'
:
user
,
'size'
:
int
(
float
(
size
)
*
1024
**
3
),
# GiB to byte
'type'
:
"qcow2-norm"
,
'name'
:
name
,
}
disk
=
Disk
.
create
(
**
params
)
disk
.
full_clean
()
cls
.
location
=
"
%
sdisk/
%
d"
%
(
OCCI_ADDR
,
disk
.
pk
)
return
cls
def
render_location
(
self
):
return
"
%
s"
%
self
.
location
...
...
circle/occi/views.py
View file @
33c94c56
...
...
@@ -146,8 +146,15 @@ class StorageInterface(View):
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
# TODO
pass
data
=
get_post_data_from_request
(
request
)
d
=
Storage
.
create_object
(
data
=
data
)
response
=
HttpResponse
(
"X-OCCI-Location:
%
s"
%
d
.
location
,
status
=
201
,
content_type
=
"text/plain"
,
)
return
response
@method_decorator
(
csrf_exempt
)
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