Commit aff5f70f by Kálmán Viktor

Merge branch 'feature-occi' into feature-voms-occi

Conflicts:
	circle/circle/settings/base.py
	circle/circle/urls.py
	circle/occi/occi.py
	circle/occi/templates/occi/compute.html
	circle/occi/urls.py
	circle/occi/views.py
parents 326a5574 df9e7d08
...@@ -68,7 +68,7 @@ urlpatterns = patterns( ...@@ -68,7 +68,7 @@ urlpatterns = patterns(
url(r'^info/support/$', url(r'^info/support/$',
TemplateView.as_view(template_name="info/support.html"), TemplateView.as_view(template_name="info/support.html"),
name="info.support"), name="info.support"),
url(r'^occi/', include('occi.urls')), url(r'^', include('occi.urls')), # this seems silly
) )
......
...@@ -5,7 +5,7 @@ from vm.models import Instance, Lease ...@@ -5,7 +5,7 @@ from vm.models import Instance, Lease
from vm.models.common import ARCHITECTURES from vm.models.common import ARCHITECTURES
from vm.models.instance import ACCESS_METHODS from vm.models.instance import ACCESS_METHODS
OCCI_ADDR = "https://miskolc.cloud.bme.hu:12598/" OCCI_ADDR = "http://localhost:8080/"
class Category(): class Category():
...@@ -36,7 +36,7 @@ class Category(): ...@@ -36,7 +36,7 @@ class Category():
ret += ' %s="%s";' % (i, getattr(self, i)) ret += ' %s="%s";' % (i, getattr(self, i))
if hasattr(self, "location"): if hasattr(self, "location"):
ret += ' location="%s";' % (self.location % OCCI_ADDR) ret += ' location="%s";' % self.location
if hasattr(self, "attributes"): if hasattr(self, "attributes"):
ret += ' attributes="%s";' % " ".join( ret += ' attributes="%s";' % " ".join(
[a.render() for a in self.attributes]) [a.render() for a in self.attributes])
...@@ -52,6 +52,10 @@ class Kind(Category): ...@@ -52,6 +52,10 @@ class Kind(Category):
pass pass
class Mixin(Category):
pass
class Attribute(): class Attribute():
def __init__(self, name, property=None): def __init__(self, name, property=None):
self.name = name self.name = name
...@@ -89,7 +93,7 @@ class Compute(Resource): ...@@ -89,7 +93,7 @@ class Compute(Resource):
def __init__(self, instance=None, attrs=None, **kwargs): def __init__(self, instance=None, attrs=None, **kwargs):
self.attrs = {} self.attrs = {}
if instance: if instance:
self.location = "%socci/vm/%d/" % (OCCI_ADDR, instance.pk) self.location = "%svm/%d/" % (OCCI_ADDR, instance.pk)
self.instance = instance self.instance = instance
self.init_attrs() self.init_attrs()
elif attrs: elif attrs:
...@@ -127,7 +131,7 @@ class Compute(Resource): ...@@ -127,7 +131,7 @@ class Compute(Resource):
params['name'] = "from occi yo" params['name'] = "from occi yo"
i = Instance.create(params=params, disks=[], networks=[], i = Instance.create(params=params, disks=[], networks=[],
req_traits=[], tags=[]) req_traits=[], tags=[])
self.location = "%socci/vm/%d/" % (OCCI_ADDR, i.pk) self.location = "%svm/%d/" % (OCCI_ADDR, i.pk)
def render_location(self): def render_location(self):
return "%s" % self.location return "%s" % self.location
...@@ -144,6 +148,28 @@ class Compute(Resource): ...@@ -144,6 +148,28 @@ class Compute(Resource):
self.attrs[k] = getattr(self.instance, v, None) 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 """predefined stuffs
...@@ -204,5 +230,13 @@ COMPUTE_KIND = Kind( ...@@ -204,5 +230,13 @@ COMPUTE_KIND = Kind(
rel="http://schemas.ogf.org/occi/core#resource", rel="http://schemas.ogf.org/occi/core#resource",
attributes=COMPUTE_ATTRS, attributes=COMPUTE_ATTRS,
actions=COMPUTE_ACTIONS, actions=COMPUTE_ACTIONS,
location="%scompute/", location="/compute/",
)
OS_TPL_MIXIN = Mixin(
term="os_tpl",
scheme="http://schemas.ogf.org/occi/infrastructure#",
class_="mixin",
title="os template",
location="/mixin/os_tpl/",
) )
{% spaceless %}
Category: {{ term }}; scheme="{{ scheme }}"; class="{{ class }}"; title="{{ title }}"; rel="{{ rel }}"; location="{{ location }}";
{% endspaceless %}
...@@ -18,11 +18,14 @@ ...@@ -18,11 +18,14 @@
from __future__ import absolute_import from __future__ import absolute_import
from django.conf.urls import url, patterns from django.conf.urls import url, patterns
from occi.views import QueryInterface, ComputeInterface, VmInterface from occi.views import (
QueryInterface, ComputeInterface, VmInterface, OsTplInterface,
)
urlpatterns = patterns( urlpatterns = patterns(
'', '',
url(r'^-/$', QueryInterface.as_view(), name="occi.query"), url(r'^-/$', QueryInterface.as_view(), name="occi.query"),
url(r'^compute/$', ComputeInterface.as_view(), name="occi.compute"), 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'^vm/(?P<pk>\d+)/$', VmInterface.as_view(), name="occi.vm"),
) )
...@@ -3,12 +3,14 @@ from django.utils.decorators import method_decorator ...@@ -3,12 +3,14 @@ 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 import View, DetailView from django.views.generic import View, DetailView
from vm.models import Instance from vm.models import Instance, InstanceTemplate
from .occi import ( from .occi import (
Compute, Compute,
OsTemplate,
COMPUTE_KIND, COMPUTE_KIND,
COMPUTE_ACTIONS, COMPUTE_ACTIONS,
OS_TPL_MIXIN,
) )
...@@ -16,9 +18,13 @@ class QueryInterface(View): ...@@ -16,9 +18,13 @@ class QueryInterface(View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
response = "Category: %s\n" % COMPUTE_KIND.render_values() response = "Category: %s\n" % COMPUTE_KIND.render_values()
response += "Category: %s\n" % OS_TPL_MIXIN.render_values()
for c in COMPUTE_ACTIONS: for c in COMPUTE_ACTIONS:
response += "Category: %s\n" % c.render_values() response += "Category: %s\n" % c.render_values()
for t in InstanceTemplate.objects.all():
response += OsTemplate(t).render_body()
return HttpResponse( return HttpResponse(
response, response,
content_type="text/plain", content_type="text/plain",
...@@ -81,6 +87,25 @@ class VmInterface(DetailView): ...@@ -81,6 +87,25 @@ class VmInterface(DetailView):
def dispatch(self, *args, **kwargs): def dispatch(self, *args, **kwargs):
return super(VmInterface, self).dispatch(*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: test commands:
curl 10.7.0.103:8080/occi/-/ -X GET curl 10.7.0.103:8080/occi/-/ -X GET
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment