Commit c7fbfc51 by Karsa Zoltán István

initial setup for rest api - IaC

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