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
e46e344b
authored
Nov 04, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
occi: list / describe disks
parent
9f0bd886
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
152 additions
and
0 deletions
+152
-0
circle/occi/occi.py
+96
-0
circle/occi/templates/occi/storage.html
+6
-0
circle/occi/urls.py
+3
-0
circle/occi/views.py
+47
-0
No files found.
circle/occi/occi.py
View file @
e46e344b
...
...
@@ -280,6 +280,74 @@ class OsTemplate(Mixin):
})
class
Storage
(
Resource
):
""" Note: 100 priority = 5 Ghz
"""
def
__init__
(
self
,
disk
=
None
,
data
=
None
):
self
.
attrs
=
{}
if
disk
:
self
.
location
=
"
%
sdisk/
%
d/"
%
(
OCCI_ADDR
,
disk
.
pk
)
self
.
disk
=
disk
self
.
init_attrs
()
@classmethod
def
create_object
(
cls
,
data
):
pass
def
render_location
(
self
):
return
"
%
s"
%
self
.
location
def
render_body
(
self
):
kind
=
STORAGE_KIND
mixins
=
[]
return
render_to_string
(
"occi/storage.html"
,
{
'kind'
:
kind
,
'attrs'
:
self
.
attrs
,
'mixins'
:
mixins
,
})
def
init_attrs
(
self
):
translate
=
{
'occi.core.id'
:
"id"
,
'occi.storage.size'
:
"size"
,
'occi.core.title'
:
"name"
,
}
for
k
,
v
in
translate
.
items
():
self
.
attrs
[
k
]
=
getattr
(
self
.
disk
,
v
,
None
)
self
.
attrs
[
'occi.storage.state'
]
=
"online"
self
.
attrs
[
'occi.storage.size'
]
/=
1024
*
1024
*
1024.0
def
trigger_action
(
self
,
data
):
method
=
None
action_term
=
None
for
d
in
data
:
m
=
occi_attribute_regex
.
match
(
d
)
if
m
:
attribute
=
m
.
group
(
"attribute"
)
if
attribute
==
"method"
:
method
=
m
.
group
(
"value"
)
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
)
"""predefined stuffs
...
...
@@ -343,6 +411,34 @@ COMPUTE_KIND = Kind(
location
=
"/compute/"
,
)
STORAGE_ATTRS
=
[
Attribute
(
"occi.storage.architecture"
),
Attribute
(
"occi.storage.state"
,
"immutable"
),
]
STORAGE_ACTIONS
=
[
Action
(
"resize"
,
"http://schemas.ogf.org/occi/infrastructure/storage/action#"
,
"action"
,
title
=
"Resize disk"
,
attributes
=
[
Attribute
(
"size"
)],
),
]
STORAGE_KIND
=
Kind
(
term
=
"storage"
,
scheme
=
"http://schemas.ogf.org/occi/infrastructure#"
,
class_
=
"kind"
,
title
=
"Storage Resource type"
,
rel
=
"http://schemas.ogf.org/occi/core#resource"
,
attributes
=
STORAGE_ATTRS
,
actions
=
STORAGE_ACTIONS
,
location
=
"/storage/"
,
)
OS_TPL_MIXIN
=
Mixin
(
term
=
"os_tpl"
,
scheme
=
"http://schemas.ogf.org/occi/infrastructure#"
,
...
...
circle/occi/templates/occi/storage.html
0 → 100644
View file @
e46e344b
Category: storage; scheme="{{ kind.scheme }}"; class="{{ kind.class }}";
{% spaceless %}
{% for k, v in attrs.items %}
X-OCCI-Attribute: {{ k }}={% if v.isdigit == False or k == "occi.core.id" %}"{{ v }}"{% else %}{{ v }}{% endif %}{% endfor %}
{% for m in mixins %}{{ m.render_body }}{% endfor %}
{% endspaceless %}
circle/occi/urls.py
View file @
e46e344b
...
...
@@ -20,6 +20,7 @@ from django.conf.urls import url, patterns
from
occi.views
import
(
QueryInterface
,
ComputeInterface
,
VmInterface
,
OsTplInterface
,
StorageInterface
,
DiskInterface
,
)
urlpatterns
=
patterns
(
...
...
@@ -28,4 +29,6 @@ urlpatterns = patterns(
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"
),
url
(
r'^storage/$'
,
StorageInterface
.
as_view
(),
name
=
"occi.storage"
),
url
(
r'^disk/(?P<pk>\d+)/$'
,
DiskInterface
.
as_view
(),
name
=
"occi.disk"
),
)
circle/occi/views.py
View file @
e46e344b
...
...
@@ -4,11 +4,14 @@ from django.views.decorators.csrf import csrf_exempt
from
django.views.generic
import
View
,
DetailView
from
vm.models
import
Instance
,
InstanceTemplate
from
storage.models
import
Disk
from
.occi
import
(
Compute
,
Storage
,
OsTemplate
,
COMPUTE_KIND
,
STORAGE_KIND
,
COMPUTE_ACTIONS
,
OS_TPL_MIXIN
,
)
...
...
@@ -38,6 +41,7 @@ class QueryInterface(View):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
response
=
"Category:
%
s
\n
"
%
COMPUTE_KIND
.
render_values
()
response
+=
"Category:
%
s
\n
"
%
STORAGE_KIND
.
render_values
()
response
+=
"Category:
%
s
\n
"
%
OS_TPL_MIXIN
.
render_values
()
for
c
in
COMPUTE_ACTIONS
:
response
+=
"Category:
%
s
\n
"
%
c
.
render_values
()
...
...
@@ -127,6 +131,49 @@ class OsTplInterface(View):
return
super
(
OsTplInterface
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
class
StorageInterface
(
View
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
response
=
"
\n
"
.
join
([
Storage
(
disk
=
d
)
.
render_location
()
for
d
in
Disk
.
objects
.
filter
(
destroyed
=
None
)])
return
HttpResponse
(
response
,
content_type
=
"text/plain"
,
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
# TODO
pass
@method_decorator
(
csrf_exempt
)
def
dispatch
(
self
,
*
args
,
**
kwargs
):
return
super
(
StorageInterface
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
class
DiskInterface
(
DetailView
):
model
=
Disk
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
disk
=
self
.
get_object
()
c
=
Storage
(
disk
=
disk
)
return
HttpResponse
(
c
.
render_body
(),
content_type
=
"text/plain"
,
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
# TODO
data
=
get_post_data_from_request
(
request
)
action
=
request
.
GET
.
get
(
"action"
)
disk
=
self
.
get_object
()
if
action
:
Storage
(
disk
=
disk
)
.
trigger_action
(
data
)
return
HttpResponse
()
@method_decorator
(
csrf_exempt
)
def
dispatch
(
self
,
*
args
,
**
kwargs
):
return
super
(
DiskInterface
,
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