Commit c7fbfc51 by Karsa Zoltán István

initial setup for rest api - IaC

parent 796da6b9
......@@ -379,6 +379,7 @@ THIRD_PARTY_APPS = (
'statici18n',
'simplesshkey',
'pipeline',
'rest_framework',
)
......
......@@ -20,7 +20,7 @@ from django.views.generic import TemplateView
from django.conf import settings
from django.contrib import admin
from django.urls import reverse
from django.urls import reverse, path
from django.shortcuts import redirect
from django.contrib.auth.views import (
PasswordResetView, PasswordResetConfirmView
......@@ -71,6 +71,8 @@ urlpatterns = [
name="info.support"),
url(r'^info/resize-how-to/$', ResizeHelpView.as_view(),
name="info.resize"),
path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
if 'rosetta' in settings.INSTALLED_APPS:
......
......@@ -18,6 +18,7 @@
from django.conf.urls import url
from django.urls import path
from vm.models import Instance
from .views import (
......@@ -58,12 +59,13 @@ from .views import (
MessageList, MessageDetail, MessageCreate, MessageDelete,
EnableTwoFactorView, DisableTwoFactorView,
AclUserGroupAutocomplete, AclUserAutocomplete,
RescheduleView, GroupImportView, GroupExportView
RescheduleView, GroupImportView, GroupExportView, iac_vm_list
)
from .views.node import node_ops
from .views.vm import vm_ops, vm_mass_ops
urlpatterns = [
path('acpi/list', iac_vm_list),
url(r'^$', IndexView.as_view(), name="dashboard.index"),
url(r"^profile/list/$", UserList.as_view(),
name="dashboard.views.user-list"),
......
......@@ -20,6 +20,7 @@ import json
import logging
from collections import OrderedDict
from os import getenv
from urllib import response
from django.conf import settings
from django.contrib import messages
......@@ -86,6 +87,29 @@ except NameError:
logger = logging.getLogger(__name__)
from rest_framework import status
from rest_framework.decorators import api_view, authentication_classes, permission_classes
from rest_framework.response import Response
from rest_framework.authentication import SessionAuthentication, BasicAuthentication
from rest_framework.permissions import IsAdminUser
@api_view(['GET'])
@authentication_classes([SessionAuthentication, BasicAuthentication])
@permission_classes([IsAdminUser])
def iac_vm_list(request):
instances = Instance.objects.all()
instances = [{
'pk': i.pk,
'url': reverse('dashboard.views.detail', args=[i.pk]),
'name': i.name,
'icon': i.get_status_icon(),
'host': i.short_hostname,
'status': i.get_status_display(),
'owner': (i.owner.profile.get_display_name()),
} for i in instances]
return Response(instances)
class VmDetailVncTokenView(CheckedDetailView):
template_name = "dashboard/vm-detail.html"
model = Instance
......
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