Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
RECIRCLE
/
portal
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
11
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
Commit
8c418722
authored
Apr 26, 2019
by
Belákovics Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic API design
parent
70b0f82c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
114 additions
and
44 deletions
+114
-44
recircle/instance/models.py
+34
-5
recircle/instance/serializers.py
+1
-1
recircle/instance/urls.py
+8
-5
recircle/instance/views.py
+51
-27
recircle/recircle/settings.py
+12
-2
recircle/recircle/urls.py
+8
-4
No files found.
recircle/instance/models.py
View file @
8c418722
from
django.db
import
models
from
django.db
import
models
from
django.conf
import
settings
class
Instance
(
models
.
Model
):
name
=
models
.
CharField
(
blank
=
True
,
max_length
=
100
,
verbose_name
=
"name"
,
help_text
=
"Human readable name of instance."
)
description
=
models
.
TextField
(
blank
=
True
,
verbose_name
=
"description"
,
help_text
=
"The description of the instance."
)
ACCESS_METHODS
=
tuple
([(
key
,
val
[
0
])
for
key
,
val
in
settings
.
VM_ACCESS_PROTOCOLS
.
items
()])
# Temporary solution
LEASE_TYPES
=
(
(
"project"
,
"Project"
),
(
"server"
,
"Server"
),
(
"infinite"
,
"Infinite lease"
)
)
# Temporary solution
OS_TYPES
=
(
(
"win10"
,
"Windows 10"
),
(
"ubuntu1804"
,
"Ubuntu 18.04"
),
)
class
Instance
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
,
help_text
=
"Human readable name of instance"
)
description
=
models
.
TextField
(
blank
=
True
,
help_text
=
"The description of the instance"
)
access_method
=
models
.
CharField
(
max_length
=
10
,
choices
=
ACCESS_METHODS
,
help_text
=
"Primary remote access method."
)
lease
=
models
.
CharField
(
max_length
=
50
,
choices
=
LEASE_TYPES
,
help_text
=
"Expiration method"
)
system
=
models
.
CharField
(
max_length
=
50
,
choices
=
OS_TYPES
,
help_text
=
"Operating system type"
)
# template
# password
# time_of_suspend
# time_of_delete
# disks
# owner
recircle/instance/serializers.py
View file @
8c418722
...
@@ -9,4 +9,4 @@ class InstanceSerializer(serializers.ModelSerializer):
...
@@ -9,4 +9,4 @@ class InstanceSerializer(serializers.ModelSerializer):
model
=
Instance
model
=
Instance
fields
=
(
"name"
,
fields
=
(
"name"
,
"description"
,
"description"
,
)
)
recircle/instance/urls.py
View file @
8c418722
from
django.urls
import
path
from
django.urls
import
path
from
rest_framework.urlpatterns
import
format_suffix_patterns
from
.
import
views
from
instance
import
views
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
views
.
instance_list
),
path
(
'instances/'
,
views
.
InstanceList
.
as_view
()),
]
path
(
'instances/<int:pk>/'
,
views
.
InstanceDetail
.
as_view
()),
\ No newline at end of file
path
(
'instances/<int:pk>/action/'
,
views
.
InstanceAction
.
as_view
())
]
urlpatterns
=
format_suffix_patterns
(
urlpatterns
)
recircle/instance/views.py
View file @
8c418722
from
django.http
import
HttpResponse
,
JsonResponse
from
django.views.decorators.csrf
import
csrf_exempt
from
rest_framework.renderers
import
JSONRenderer
from
rest_framework.parsers
import
JSONParser
from
instance.models
import
Instance
from
instance.models
import
Instance
from
instance.serializers
import
InstanceSerializer
from
django.http
import
Http404
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
def
index
(
request
):
from
rest_framework
import
status
return
HttpResponse
(
"Hello, world. You're at the instance index."
)
@csrf_exempt
# class InstanceList(APIView):
def
instance_list
(
request
):
# def get(self, request, format=None):
"""
# instances = Instance.objects.all()
List all instances, or create a new one.
# # get OpenStack attribs
"""
if
request
.
method
==
'GET'
:
# # create response
instances
=
Instance
.
objects
.
all
()
# # serializer = SnippetSerializer(snippets, many=True)
serializer
=
InstanceSerializer
(
instances
,
many
=
True
)
return
JsonResponse
(
serializer
.
data
,
safe
=
False
)
# return Response(serializer.data)
elif
request
.
method
==
'POST'
:
# def post(self, request, format=None):
data
=
JSONParser
()
.
parse
(
request
)
# serializer = SnippetSerializer(data=request.data)
serializer
=
InstanceSerializer
(
data
=
data
)
# if serializer.is_valid():
if
serializer
.
is_valid
():
# serializer.save()
serializer
.
save
()
# return Response(serializer.data, status=status.HTTP_201_CREATED)
return
JsonResponse
(
serializer
.
data
,
status
=
201
)
# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
return
JsonResponse
(
serializer
.
errors
,
status
=
400
)
# class SnippetDetail(APIView):
# """
# Retrieve, update or delete a snippet instance.
# """
# def get_object(self, pk):
# try:
# return Snippet.objects.get(pk=pk)
# except Snippet.DoesNotExist:
# raise Http404
# def get(self, request, pk, format=None):
# snippet = self.get_object(pk)
# serializer = SnippetSerializer(snippet)
# return Response(serializer.data)
# def put(self, request, pk, format=None):
# snippet = self.get_object(pk)
# serializer = SnippetSerializer(snippet, data=request.data)
# if serializer.is_valid():
# serializer.save()
# return Response(serializer.data)
# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
# def delete(self, request, pk, format=None):
# snippet = self.get_object(pk)
# snippet.delete()
# return Response(status=status.HTTP_204_NO_CONTENT)
recircle/recircle/settings.py
View file @
8c418722
...
@@ -43,6 +43,7 @@ INSTALLED_APPS = [
...
@@ -43,6 +43,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles'
,
'django.contrib.staticfiles'
,
'rest_framework'
,
'rest_framework'
,
'djoser'
,
'djoser'
,
'rest_framework_swagger'
,
]
]
MIDDLEWARE
=
[
MIDDLEWARE
=
[
...
@@ -123,4 +124,14 @@ USE_TZ = True
...
@@ -123,4 +124,14 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL
=
'/static/'
STATIC_URL
=
'/static/'
\ No newline at end of file
################################################################################################
# RECIRCLE CONFIG
################################################################################################
# VM ACCESS PROTOCOLS
VM_ACCESS_PROTOCOLS
=
{
"rdp"
:
[
"Remote Desktop Protocol"
,
3389
,
"tcp"
],
"ssh"
:
[
"Secure Shell"
,
22
,
"tcp"
]
}
recircle/recircle/urls.py
View file @
8c418722
...
@@ -15,10 +15,15 @@ Including another URLconf
...
@@ -15,10 +15,15 @@ Including another URLconf
"""
"""
from
django.contrib
import
admin
from
django.contrib
import
admin
from
django.urls
import
path
,
re_path
,
include
from
django.urls
import
path
,
re_path
,
include
from
rest_framework_swagger.views
import
get_swagger_view
schema_view
=
get_swagger_view
(
title
=
'RECIRCLE API'
)
urlpatterns
=
[
urlpatterns
=
[
path
(
'
instance/'
,
include
(
'instance.urls'
)),
path
(
'
api/v1/'
,
include
(
endpoints_v1
)),
path
(
'admin/'
,
admin
.
site
.
urls
),
path
(
'admin/'
,
admin
.
site
.
urls
),
re_path
(
r'^auth/'
,
include
(
'djoser.urls'
)),
re_path
(
r'^auth/'
,
include
(
'djoser.urls'
)),
re_path
(
r'^auth/'
,
include
(
'djoser.urls.authtoken'
))
re_path
(
r'^auth/'
,
include
(
'djoser.urls.authtoken'
)),
]
path
(
r'swagger'
,
schema_view
)
\ No newline at end of file
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment