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
df9e7d08
authored
Oct 17, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
occi: os tpl
parent
b1f56b18
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
6 deletions
+72
-6
circle/circle/urls.py
+1
-1
circle/occi/occi.py
+38
-3
circle/occi/templates/occi/os_tpl.html
+3
-0
circle/occi/urls.py
+4
-1
circle/occi/views.py
+26
-1
No files found.
circle/circle/urls.py
View file @
df9e7d08
...
...
@@ -68,7 +68,7 @@ urlpatterns = patterns(
url
(
r'^info/support/$'
,
TemplateView
.
as_view
(
template_name
=
"info/support.html"
),
name
=
"info.support"
),
url
(
r'^
occi/
'
,
include
(
'occi.urls'
)),
url
(
r'^'
,
include
(
'occi.urls'
)),
)
...
...
circle/occi/occi.py
View file @
df9e7d08
...
...
@@ -5,7 +5,7 @@ from vm.models import Instance, Lease
from
vm.models.common
import
ARCHITECTURES
from
vm.models.instance
import
ACCESS_METHODS
OCCI_ADDR
=
"http://
pc3.szgt.uni-miskolc.hu:5863
/"
OCCI_ADDR
=
"http://
localhost:8080
/"
class
Category
():
...
...
@@ -50,6 +50,10 @@ class Kind(Category):
pass
class
Mixin
(
Category
):
pass
class
Attribute
():
def
__init__
(
self
,
name
,
property
=
None
):
self
.
name
=
name
...
...
@@ -87,7 +91,7 @@ class Compute(Resource):
def
__init__
(
self
,
instance
=
None
,
attrs
=
None
,
**
kwargs
):
self
.
attrs
=
{}
if
instance
:
self
.
location
=
"
%
s
occi/vm/
%
d
"
%
(
OCCI_ADDR
,
instance
.
pk
)
self
.
location
=
"
%
s
vm/
%
d/
"
%
(
OCCI_ADDR
,
instance
.
pk
)
self
.
instance
=
instance
self
.
init_attrs
()
elif
attrs
:
...
...
@@ -124,7 +128,7 @@ class Compute(Resource):
params
[
'name'
]
=
"from occi yo"
i
=
Instance
.
create
(
params
=
params
,
disks
=
[],
networks
=
[],
req_traits
=
[],
tags
=
[])
self
.
location
=
"
%
s
occi/vm/
%
d
"
%
(
OCCI_ADDR
,
i
.
pk
)
self
.
location
=
"
%
s
vm/
%
d/
"
%
(
OCCI_ADDR
,
i
.
pk
)
def
render_location
(
self
):
return
"X-OCCI-Location:
%
s"
%
self
.
location
...
...
@@ -141,6 +145,28 @@ class Compute(Resource):
self
.
attrs
[
k
]
=
getattr
(
self
.
instance
,
v
,
None
)
class
OsTemplate
(
Mixin
):
def
__init__
(
self
,
template
):
self
.
term
=
"os_tpl_
%
d"
%
template
.
pk
self
.
title
=
template
.
system
self
.
scheme
=
"http://cloud.bme.hu/occi/infrastructure/os_tpl#"
self
.
rel
=
"http://schemas.ogf.org/occi/infrastructure#os_tpl"
self
.
location
=
"/mixin/os_tpl/
%
s/"
%
self
.
term
def
render_location
(
self
):
return
self
.
location
def
render_body
(
self
):
return
render_to_string
(
"occi/os_tpl.html"
,
{
'term'
:
self
.
term
,
'scheme'
:
self
.
scheme
,
'rel'
:
self
.
rel
,
'location'
:
self
.
location
,
'class'
:
"mixin"
,
'title'
:
self
.
title
,
})
"""predefined stuffs
...
...
@@ -203,3 +229,12 @@ COMPUTE_KIND = Kind(
actions
=
COMPUTE_ACTIONS
,
location
=
"
%
scompute/"
,
)
OS_TPL_MIXIN
=
Mixin
(
term
=
"os_tpl"
,
scheme
=
"http://schemas.ogf.org/occi/infrastructure#"
,
class_
=
"mixin"
,
title
=
"os template"
,
location
=
"/mixin/os_tpl/"
,
)
circle/occi/templates/occi/os_tpl.html
0 → 100644
View file @
df9e7d08
{% spaceless %}
Category: {{ term }}; scheme="{{ scheme }}"; class="{{ class }}"; title="{{ title }}"; rel="{{ rel }}"; location="{{ location }}";
{% endspaceless %}
circle/occi/urls.py
View file @
df9e7d08
...
...
@@ -18,11 +18,14 @@
from
__future__
import
absolute_import
from
django.conf.urls
import
url
,
patterns
from
occi.views
import
QueryInterface
,
ComputeInterface
,
VmInterface
from
occi.views
import
(
QueryInterface
,
ComputeInterface
,
VmInterface
,
OsTplInterface
,
)
urlpatterns
=
patterns
(
''
,
url
(
r'^-/$'
,
QueryInterface
.
as_view
(),
name
=
"occi.query"
),
url
(
r'^compute/$'
,
ComputeInterface
.
as_view
(),
name
=
"occi.compute"
),
url
(
r'^os_tpl/$'
,
OsTplInterface
.
as_view
(),
name
=
"occi.os_tpl"
),
url
(
r'^vm/(?P<pk>\d+)/$'
,
VmInterface
.
as_view
(),
name
=
"occi.vm"
),
)
circle/occi/views.py
View file @
df9e7d08
...
...
@@ -3,12 +3,14 @@ from django.utils.decorators import method_decorator
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.generic
import
View
,
DetailView
from
vm.models
import
Instance
from
vm.models
import
Instance
,
InstanceTemplate
from
.occi
import
(
Compute
,
OsTemplate
,
COMPUTE_KIND
,
COMPUTE_ACTIONS
,
OS_TPL_MIXIN
,
)
...
...
@@ -16,9 +18,13 @@ class QueryInterface(View):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
response
=
"Category:
%
s
\n
"
%
COMPUTE_KIND
.
render_values
()
response
=
"Category:
%
s
\n
"
%
OS_TPL_MIXIN
.
render_values
()
for
c
in
COMPUTE_ACTIONS
:
response
+=
"Category:
%
s
\n
"
%
c
.
render_values
()
for
t
in
InstanceTemplate
.
objects
.
all
():
response
+=
OsTemplate
(
t
)
.
render_body
()
return
HttpResponse
(
response
,
content_type
=
"text/plain"
,
...
...
@@ -81,6 +87,25 @@ class VmInterface(DetailView):
def
dispatch
(
self
,
*
args
,
**
kwargs
):
return
super
(
VmInterface
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
class
OsTplInterface
(
View
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
response
=
"
\n
"
.
join
([
OsTemplate
(
template
=
t
)
.
render_location
()
for
t
in
InstanceTemplate
.
objects
.
all
()])
return
HttpResponse
(
response
,
content_type
=
"text/plain"
,
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
pass
@method_decorator
(
csrf_exempt
)
# decorator on post method doesn't work
def
dispatch
(
self
,
*
args
,
**
kwargs
):
return
super
(
OsTplInterface
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
"""
test commands:
curl 10.7.0.103:8080/occi/-/ -X GET
...
...
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