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
b6a0fdb4
authored
Nov 12, 2014
by
Kálmán Viktor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
occi: network list
parent
4b185b09
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
142 additions
and
1 deletions
+142
-1
circle/occi/occi.py
+78
-0
circle/occi/templates/occi/network.html
+7
-0
circle/occi/urls.py
+6
-1
circle/occi/views.py
+51
-0
No files found.
circle/occi/occi.py
View file @
b6a0fdb4
...
...
@@ -523,6 +523,52 @@ class StorageLink(Link):
self
.
instance
.
detach_disk
(
user
=
user
,
disk
=
self
.
disk
)
class
Network
(
Resource
):
def
__init__
(
self
,
vlan
=
None
,
data
=
None
):
self
.
attrs
=
{}
if
vlan
:
self
.
location
=
"/network2/
%
d/"
%
(
vlan
.
vid
)
self
.
vlan
=
vlan
self
.
init_attrs
()
@classmethod
def
create_object
(
cls
,
data
):
pass
def
render_location
(
self
):
return
"
%
s"
%
self
.
location
def
render_body
(
self
):
kind
=
NETWORK_KIND
mixins
=
[]
return
render_to_string
(
"occi/network.html"
,
{
'kind'
:
kind
,
'attrs'
:
self
.
attrs
,
'mixins'
:
mixins
,
})
def
init_attrs
(
self
):
translate
=
{
'occi.core.id'
:
"vid"
,
'occi.core.title'
:
"name"
,
'occi.network.vlan'
:
"vid"
,
'occi.network.label'
:
"name"
,
}
for
k
,
v
in
translate
.
items
():
self
.
attrs
[
k
]
=
getattr
(
self
.
vlan
,
v
,
None
)
self
.
attrs
[
'occi.compute.state'
]
=
"active"
def
trigger_action
(
self
,
data
):
pass
def
delete
(
self
):
# TODO
user
=
User
.
objects
.
get
(
username
=
"test"
)
self
.
instance
.
destroy
(
user
=
user
)
"""predefined stuffs
...
...
@@ -656,3 +702,35 @@ STORAGE_LINK_KIND = Kind(
location
=
"/link/storagelink/"
,
attributes
=
STORAGE_LINK_ATTRS
)
NETWORK_ATTRS
=
[
Attribute
(
"occi.network.vlan"
),
Attribute
(
"occi.network.label"
),
Attribute
(
"occi.network.state"
,
"immutable"
),
]
NETWORK_KIND
=
Kind
(
term
=
"network"
,
scheme
=
"http://schemas.ogf.org/occi/infrastructure#network"
,
class_
=
"kind"
,
title
=
"network resource"
,
rel
=
"http://schemas.ogf.org/occi/core#resource"
,
location
=
"/network2/"
,
attributes
=
NETWORK_ATTRS
,
)
IPNETWORK_ATTRS
=
[
Attribute
(
"occi.network.address"
),
Attribute
(
"occi.network.gateway"
),
Attribute
(
"occi.network.allocation"
),
]
IPNETWORK_MIXIN
=
Kind
(
term
=
"ipnetwork"
,
scheme
=
"http://schemas.ogf.org/occi/infrastructure/network#"
,
class_
=
"mixin"
,
title
=
"ipnetwork"
,
location
=
"/mixin/ipnetwork/"
,
attributes
=
IPNETWORK_ATTRS
,
)
circle/occi/templates/occi/network.html
0 → 100644
View file @
b6a0fdb4
Category: compute; scheme="{{ kind.scheme }}"; class="{{ kind.class }}";
{% for m in mixins %}
{{ m.render_body }}
{% endfor %}
{% for k, v in attrs.items %}
X-OCCI-Attribute: {{ k }}={% if v.isdigit == False or k == "occi.core.id" %}"{{ v }}"{% else %}{{ v }}{% endif %}
{% endfor %}
circle/occi/urls.py
View file @
b6a0fdb4
...
...
@@ -20,7 +20,8 @@ from django.conf.urls import url, patterns
from
occi.views
import
(
QueryInterface
,
ComputeInterface
,
VmInterface
,
OsTplInterface
,
StorageInterface
,
DiskInterface
,
StorageLinkInterface
StorageInterface
,
DiskInterface
,
StorageLinkInterface
,
NetworkInterface
,
VlanInterface
,
)
urlpatterns
=
patterns
(
...
...
@@ -29,10 +30,14 @@ 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'^storage/(?P<pk>\d+)/?$'
,
DiskInterface
.
as_view
(),
name
=
"occi.disk"
),
url
(
r'^link/storagelink/$'
,
StorageLinkInterface
.
as_view
()),
url
(
r'^link/storagelink/vm(?P<vm_pk>\d+)_disk(?P<disk_pk>\d+)/?$'
,
StorageLinkInterface
.
as_view
(),
name
=
"occi.storagelink"
),
url
(
r'^network2/?$'
,
NetworkInterface
.
as_view
(),
),
url
(
r'^network2/(?P<vid>\d+)/?$'
,
VlanInterface
.
as_view
(),
),
)
circle/occi/views.py
View file @
b6a0fdb4
...
...
@@ -4,12 +4,14 @@ from django.utils.decorators import method_decorator
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.generic
import
View
,
DetailView
from
firewall.models
import
Vlan
from
vm.models
import
Instance
,
InstanceTemplate
from
storage.models
import
Disk
from
.occi
import
(
Compute
,
Storage
,
Network
,
OsTemplate
,
StorageLink
,
COMPUTE_KIND
,
...
...
@@ -18,6 +20,8 @@ from .occi import (
STORAGE_LINK_KIND
,
COMPUTE_ACTIONS
,
OS_TPL_MIXIN
,
NETWORK_KIND
,
IPNETWORK_MIXIN
,
)
...
...
@@ -49,6 +53,8 @@ class QueryInterface(View):
response
+=
"Category:
%
s
\n
"
%
LINK_KIND
.
render_values
()
response
+=
"Category:
%
s
\n
"
%
STORAGE_LINK_KIND
.
render_values
()
response
+=
"Category:
%
s
\n
"
%
OS_TPL_MIXIN
.
render_values
()
response
+=
"Category:
%
s
\n
"
%
NETWORK_KIND
.
render_values
()
response
+=
"Category:
%
s
\n
"
%
IPNETWORK_MIXIN
.
render_values
()
for
c
in
COMPUTE_ACTIONS
:
response
+=
"Category:
%
s
\n
"
%
c
.
render_values
()
...
...
@@ -251,3 +257,48 @@ class StorageLinkInterface(View):
@method_decorator
(
csrf_exempt
)
def
dispatch
(
self
,
*
args
,
**
kwargs
):
return
super
(
StorageLinkInterface
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
class
NetworkInterface
(
View
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
response
=
"
\n
"
.
join
([
Network
(
vlan
=
v
)
.
render_location
()
for
v
in
Vlan
.
objects
.
all
()])
return
HttpResponse
(
response
,
content_type
=
"text/plain"
,
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
pass
# we don't really want to create networks via OCCI yet
@method_decorator
(
csrf_exempt
)
# decorator on post method doesn't work
def
dispatch
(
self
,
*
args
,
**
kwargs
):
return
super
(
NetworkInterface
,
self
)
.
dispatch
(
*
args
,
**
kwargs
)
class
VlanInterface
(
DetailView
):
model
=
Vlan
slug_field
=
'vid'
slug_url_kwarg
=
'vid'
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
vlan
=
self
.
get_object
()
c
=
Network
(
vlan
=
vlan
)
return
HttpResponse
(
c
.
render_body
(),
content_type
=
"text/plain"
,
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
pass
# no actions
def
delete
(
self
,
request
,
*
args
,
**
kwargs
):
vm
=
self
.
get_object
()
Compute
(
instance
=
vm
)
.
delete
()
return
HttpResponse
()
@method_decorator
(
csrf_exempt
)
# decorator on post method doesn't work
def
dispatch
(
self
,
*
args
,
**
kwargs
):
return
super
(
VlanInterface
,
self
)
.
dispatch
(
*
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