Commit df9e7d08 by Kálmán Viktor

occi: os tpl

parent b1f56b18
......@@ -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')),
)
......
......@@ -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 = "%socci/vm/%d" % (OCCI_ADDR, instance.pk)
self.location = "%svm/%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 = "%socci/vm/%d" % (OCCI_ADDR, i.pk)
self.location = "%svm/%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/",
)
{% spaceless %}
Category: {{ term }}; scheme="{{ scheme }}"; class="{{ class }}"; title="{{ title }}"; rel="{{ rel }}"; location="{{ location }}";
{% endspaceless %}
......@@ -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"),
)
......@@ -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
......
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