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
33efa984
authored
May 13, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
occi: base classes
parent
7260a162
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
135 additions
and
3 deletions
+135
-3
circle/occi/occi.py
+125
-0
circle/occi/views.py
+10
-3
No files found.
circle/occi/occi.py
0 → 100644
View file @
33efa984
class
Category
():
"""Represents a Category object
actions needs a list of Actions
attributes needs a list of Attributes
"""
optional_arguments
=
[
"title"
,
"rel"
,
"location"
,
"attributes"
,
"actions"
,
"class"
]
def
__init__
(
self
,
term
,
scheme
,
class_
,
**
kwargs
):
# workaround for class named keyword argument
kwargs
[
'class'
]
=
class_
self
.
term
=
term
self
.
scheme
=
scheme
self
.
class_
=
class_
for
k
,
v
in
kwargs
.
iteritems
():
if
k
in
self
.
optional_arguments
:
setattr
(
self
,
k
,
v
)
def
render_values
(
self
):
ret
=
"
%
s;"
%
self
.
term
simple_arguments
=
[
"scheme"
,
"class"
,
"title"
,
"rel"
,
"location"
]
for
i
in
simple_arguments
:
if
hasattr
(
self
,
i
):
ret
+=
'
%
s="
%
s";'
%
(
i
,
getattr
(
self
,
i
))
if
hasattr
(
self
,
"attributes"
):
ret
+=
' attributes="
%
s";'
%
" "
.
join
(
[
a
.
render
()
for
a
in
self
.
attributes
])
if
hasattr
(
self
,
"actions"
):
ret
+=
' actions="
%
s";'
%
" "
.
join
(
[
a
.
render
()
for
a
in
self
.
actions
])
return
ret
[:
-
1
]
# trailing semicolon
# TODO related, entity_type, entities
class
Kind
(
Category
):
pass
class
Attribute
():
def
__init__
(
self
,
name
,
property
=
None
):
self
.
name
=
name
self
.
property
=
property
def
render
(
self
):
attr
=
self
.
name
if
self
.
property
:
attr
+=
"{
%
s}"
%
self
.
property
return
attr
class
Action
(
Category
):
def
render
(
self
):
return
"
%
s
%
s"
%
(
self
.
scheme
,
self
.
term
)
# TODO Entity
# TODO ^ Resource
# TODO ^ Compute
"""predefined stuffs
storage attributes and actions
http://ogf.org/documents/GFD.184.pdf 3.3 (page 7)
storagelink attributes
http://ogf.org/documents/GFD.184.pdf 3.4.2 (page 10)
"""
# compute attributes and actions
# http://ogf.org/documents/GFD.184.pdf 3.1 (page 5)
COMPUTE_ATTRS
=
[
Attribute
(
"occi.compute.architecture"
),
Attribute
(
"occi.compute.cores"
),
Attribute
(
"occi.compute.hostname"
),
Attribute
(
"occi.compute.speed"
),
Attribute
(
"occi.compute.memory"
),
Attribute
(
"occi.compute.state"
,
"immutable"
),
]
COMPUTE_ACTIONS
=
[
Action
(
"start"
,
"http://schemas.ogf.org/occi/infrastructure/compute/action#"
,
"action"
,
title
=
"Start compute resource"
,
),
Action
(
"stop"
,
"http://schemas.ogf.org/occi/infrastructure/compute/action#"
,
"action"
,
title
=
"Stop compute resource"
,
attributes
=
[
Attribute
(
"method"
)],
),
Action
(
"restart"
,
"http://schemas.ogf.org/occi/infrastructure/compute/action#"
,
"action"
,
title
=
"Restart compute resource"
,
attributes
=
[
Attribute
(
"method"
)],
),
Action
(
"suspend"
,
"http://schemas.ogf.org/occi/infrastructure/compute/action#"
,
"action"
,
title
=
"Suspend compute resource"
,
attributes
=
[
Attribute
(
"method"
)],
),
]
COMPUTE_KIND
=
Kind
(
term
=
"compute"
,
scheme
=
"http://schemas.ogf.org/occi/infrastructure#"
,
class_
=
"kind"
,
title
=
"Compute Resource type"
,
rel
=
"http://schemas.ogf.org/occi/core#resource"
,
attributes
=
COMPUTE_ATTRS
,
actions
=
COMPUTE_ACTIONS
,
location
=
"10.7.0.103:8080/occi/compute/"
,
)
circle/occi/views.py
View file @
33efa984
...
@@ -3,13 +3,20 @@ from django.utils.decorators import method_decorator
...
@@ -3,13 +3,20 @@ from django.utils.decorators import method_decorator
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.generic.base
import
View
from
django.views.generic.base
import
View
from
.occi
import
(
COMPUTE_KIND
,
COMPUTE_ACTIONS
,
)
class
QueryInterface
(
View
):
class
QueryInterface
(
View
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
response
=
HttpResponse
(
"Hai!"
)
response
=
"Category:
%
s
\n
"
%
COMPUTE_KIND
.
render_values
()
response
[
'yo'
]
=
"as"
for
c
in
COMPUTE_ACTIONS
:
return
response
response
+=
"Category:
%
s
\n
"
%
c
.
render_values
()
return
HttpResponse
(
response
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
response
=
HttpResponse
(
status
=
501
)
response
=
HttpResponse
(
status
=
501
)
...
...
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