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(
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')), # this seems silly
)
......
......@@ -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 = "https://miskolc.cloud.bme.hu:12598/"
OCCI_ADDR = "http://localhost:8080/"
class Category():
......@@ -36,7 +36,7 @@ class Category():
ret += ' %s="%s";' % (i, getattr(self, i))
if hasattr(self, "location"):
ret += ' location="%s";' % (self.location % OCCI_ADDR)
ret += ' location="%s";' % self.location
if hasattr(self, "attributes"):
ret += ' attributes="%s";' % " ".join(
[a.render() for a in self.attributes])
......@@ -52,6 +52,10 @@ class Kind(Category):
pass
class Mixin(Category):
pass
class Attribute():
def __init__(self, name, property=None):
self.name = name
......@@ -89,7 +93,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:
......@@ -127,7 +131,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 "%s" % self.location
......@@ -144,6 +148,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
......@@ -204,5 +230,13 @@ COMPUTE_KIND = Kind(
rel="http://schemas.ogf.org/occi/core#resource",
attributes=COMPUTE_ATTRS,
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 @@
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