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
ec1b0b86
authored
May 14, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
occi: compute interface
note: new vm creation is kinda flunky, no auth, a few random things
parent
33efa984
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
4 deletions
+106
-4
circle/occi/occi.py
+62
-3
circle/occi/urls.py
+2
-1
circle/occi/views.py
+42
-0
No files found.
circle/occi/occi.py
View file @
ec1b0b86
from
django.contrib.auth.models
import
User
from
vm.models
import
Instance
,
Lease
from
vm.models.common
import
ARCHITECTURES
from
vm.models.instance
import
ACCESS_METHODS
class
Category
():
"""Represents a Category object
...
...
@@ -56,10 +63,62 @@ class Action(Category):
def
render
(
self
):
return
"
%
s
%
s"
%
(
self
.
scheme
,
self
.
term
)
# TODO Entity
# TODO ^ Resource
# TODO ^ Compute
class
Entity
():
def
__init__
(
self
,
id
,
title
,
kind
):
self
.
id
=
id
self
.
title
=
title
self
.
kind
=
kind
class
Resource
(
Entity
):
def
__init__
(
self
,
id
,
title
,
kind
,
summary
,
links
):
super
(
Resource
,
self
)
.
__init__
(
id
,
title
,
kind
)
self
.
summary
=
summary
self
.
links
=
links
class
Compute
(
Resource
):
# TODO better init, for new resources
def
__init__
(
self
,
instance
=
None
,
attrs
=
None
,
**
kwargs
):
if
instance
:
self
.
location
=
"http://10.7.0.103:8080/occi/vm/
%
d"
%
instance
.
pk
elif
attrs
:
self
.
attrs
=
attrs
self
.
_create_object
()
translate
=
{
'occi.compute.architecture'
:
"arch"
,
'occi.compute.cores'
:
"num_cores"
,
'occi.compute.hostname'
:
"???"
,
'occi.compute.speed'
:
"priority"
,
'occi.compute.memory'
:
"ram_size"
,
}
def
_create_object
(
self
):
params
=
{}
for
a
in
self
.
attrs
:
t
=
a
.
split
(
"="
)
params
[
self
.
translate
.
get
(
t
[
0
])]
=
t
[
1
]
print
params
params
[
'lease'
]
=
Lease
.
objects
.
all
()[
0
]
params
[
'priority'
]
=
10
params
[
'max_ram_size'
]
=
params
[
'ram_size'
]
params
[
'system'
]
=
"welp"
params
[
'pw'
]
=
"killmenow"
params
[
'arch'
]
=
(
ARCHITECTURES
[
0
][
0
]
if
"64"
in
params
[
'arch'
]
else
ARCHITECTURES
[
1
][
0
])
params
[
'access_method'
]
=
ACCESS_METHODS
[
0
][
0
]
params
[
'owner'
]
=
User
.
objects
.
get
(
username
=
"test"
)
params
[
'name'
]
=
"from occi yo"
i
=
Instance
.
create
(
params
=
params
,
disks
=
[],
networks
=
[],
req_traits
=
[],
tags
=
[])
self
.
location
=
"http://10.7.0.103:8080/occi/vm/
%
d"
%
i
.
pk
def
render_location
(
self
):
return
"X-OCCI-Location:
%
s"
%
self
.
location
"""predefined stuffs
...
...
circle/occi/urls.py
View file @
ec1b0b86
...
...
@@ -18,9 +18,10 @@
from
__future__
import
absolute_import
from
django.conf.urls
import
url
,
patterns
from
occi.views
import
QueryInterface
from
occi.views
import
QueryInterface
,
ComputeInterface
urlpatterns
=
patterns
(
''
,
url
(
r'^-/$'
,
QueryInterface
.
as_view
(),
name
=
"occi.query"
),
url
(
r'^compute/$'
,
ComputeInterface
.
as_view
(),
name
=
"occi.compute"
),
)
circle/occi/views.py
View file @
ec1b0b86
...
...
@@ -3,7 +3,10 @@ from django.utils.decorators import method_decorator
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.generic.base
import
View
from
vm.models
import
Instance
from
.occi
import
(
Compute
,
COMPUTE_KIND
,
COMPUTE_ACTIONS
,
)
...
...
@@ -25,3 +28,42 @@ class QueryInterface(View):
@method_decorator
(
csrf_exempt
)
# decorator on post method doesn't work
def
dispatch
(
self
,
*
args
,
**
kwargs
):
return
super
(
QueryInterface
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
class
ComputeInterface
(
View
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
response
=
"
\n
"
.
join
([
Compute
(
instance
=
i
)
.
render_location
()
for
i
in
Instance
.
active
.
all
()])
return
HttpResponse
(
response
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
occi_attrs
=
None
category
=
None
for
k
,
v
in
request
.
META
.
iteritems
():
if
k
.
startswith
(
"HTTP_X_OCCI_ATTRIBUTE"
):
occi_attrs
=
v
.
split
(
","
)
elif
k
.
startswith
(
"HTTP_CATEGORY"
)
and
category
is
None
:
category
=
v
c
=
Compute
(
attrs
=
occi_attrs
)
response
=
HttpResponse
()
response
[
'Location'
]
=
c
.
location
return
response
@method_decorator
(
csrf_exempt
)
# decorator on post method doesn't work
def
dispatch
(
self
,
*
args
,
**
kwargs
):
return
super
(
ComputeInterface
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
"""
test commands:
curl 10.7.0.103:8080/occi/-/ -X GET
curl 10.7.0.103:8080/occi/compute/ -X GET
curl 10.7.0.103:8080/occi/compute/ -X POST
--header "X-OCCI-Attribute: occi.compute.cores=2"
--header "X-OCCI-Attribute: occi.compute.architecture=x86"
--header "X-OCCI-Attribute: occi.compute.speed=1"
--header "X-OCCI-Attribute: occi.compute.memory=1024" -I
"""
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