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
Commit
a35f2402
authored
Jul 01, 2019
by
Bodor Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reformat code and fix flake8 errors
parent
16394b7c
Hide whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
166 additions
and
202 deletions
+166
-202
recircle/image/admin.py
+1
-1
recircle/image/apps.py
+1
-1
recircle/image/models.py
+10
-4
recircle/image/serializers.py
+2
-1
recircle/image/tests.py
+1
-1
recircle/image/urls.py
+3
-6
recircle/image/views.py
+8
-6
recircle/instance/apps.py
+1
-1
recircle/instance/models.py
+29
-21
recircle/instance/serializers.py
+0
-1
recircle/instance/tests.py
+1
-1
recircle/instance/urls.py
+2
-2
recircle/instance/views.py
+6
-4
recircle/manage.py
+2
-2
recircle/recircle/settings.py
+47
-58
recircle/recircle/urls.py
+7
-7
recircle/recircle/wsgi.py
+1
-1
recircle/storage/admin.py
+1
-1
recircle/storage/apps.py
+1
-1
recircle/storage/models.py
+15
-5
recircle/storage/serializers.py
+2
-1
recircle/storage/tests.py
+1
-1
recircle/storage/views.py
+1
-1
recircle/template/admin.py
+1
-1
recircle/template/apps.py
+1
-1
recircle/template/models.py
+17
-7
recircle/template/serializers.py
+2
-1
recircle/template/tests.py
+1
-1
recircle/template/views.py
+1
-1
recircle/views.py
+0
-62
No files found.
recircle/image/admin.py
View file @
a35f2402
from
django.contrib
import
admin
#
from django.contrib import admin
# Register your models here.
recircle/image/apps.py
View file @
a35f2402
...
...
@@ -2,4 +2,4 @@ from django.apps import AppConfig
class
ImageConfig
(
AppConfig
):
name
=
'image'
name
=
"image"
recircle/image/models.py
View file @
a35f2402
from
django.db
import
models
class
Disk
(
models
.
Model
):
"""A virtual disk.
"""
name
=
models
.
CharField
(
blank
=
True
,
max_length
=
100
,
verbose_name
=
"name"
,
help_text
=
"Name of the disk"
)
remote_ID
=
models
.
CharField
(
max_length
=
40
,
unique
=
True
,
verbose_name
=
"remote_ID"
,
help_text
=
"ID, which helps access the disk"
)
\ No newline at end of file
name
=
models
.
CharField
(
blank
=
True
,
max_length
=
100
,
verbose_name
=
"name"
,
help_text
=
"Name of the disk"
)
remote_ID
=
models
.
CharField
(
max_length
=
40
,
unique
=
True
,
verbose_name
=
"remote_ID"
,
help_text
=
"ID, which helps access the disk"
,
)
recircle/image/serializers.py
View file @
a35f2402
...
...
@@ -2,7 +2,8 @@ from rest_framework import serializers
from
.models
import
Disk
class
DiskSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Disk
fields
=
(
'name'
,
'remote_ID'
,
)
fields
=
(
"name"
,
"remote_ID"
)
recircle/image/tests.py
View file @
a35f2402
from
django.test
import
TestCase
#
from django.test import TestCase
# Create your tests here.
recircle/image/urls.py
View file @
a35f2402
from
django.urls
import
include
,
path
from
django.urls
import
path
from
rest_framework.urlpatterns
import
format_suffix_patterns
from
image
import
views
urlpatterns
=
[
path
(
''
,
views
.
DiskList
.
as_view
()),
]
urlpatterns
=
[
path
(
""
,
views
.
DiskList
.
as_view
())]
urlpatterns
=
format_suffix_patterns
(
urlpatterns
)
\ No newline at end of file
urlpatterns
=
format_suffix_patterns
(
urlpatterns
)
recircle/image/views.py
View file @
a35f2402
from
image.models
import
Disk
from
image.serializers
import
DiskSerializer
from
django.shortcuts
import
render
#
from django.shortcuts import render
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
interface_openstack.implementation.image.OpenstackImageManager
import
OpenstackImageManager
from
interface_openstack.implementation.image.OpenstackImageManager
import
(
OpenstackImageManager
,
)
import
openstack
conn
=
openstack
.
connect
(
cloud
=
'openstack'
)
conn
=
openstack
.
connect
(
cloud
=
"openstack"
)
class
DiskList
(
APIView
):
def
get
(
self
,
request
,
format
=
None
):
#OpenStack
#
OpenStack
interface
=
OpenstackImageManager
(
conn
)
return
Response
([
disk
.
__dict__
for
disk
in
interface
.
list
()])
#Create response
#
Create response
disks
=
Disk
.
object
.
all
()
serializer
=
DiskSerializer
(
disks
,
many
=
True
)
return
Response
(
serializer
.
data
)
recircle/instance/apps.py
View file @
a35f2402
...
...
@@ -2,4 +2,4 @@ from django.apps import AppConfig
class
InstanceConfig
(
AppConfig
):
name
=
'instance'
name
=
"instance"
recircle/instance/models.py
View file @
a35f2402
...
...
@@ -2,36 +2,44 @@ from django.db import models
from
django.conf
import
settings
ACCESS_METHODS
=
tuple
([(
key
,
val
[
0
])
for
key
,
val
in
settings
.
VM_ACCESS_PROTOCOLS
.
items
()])
ACCESS_METHODS
=
tuple
(
[(
key
,
val
[
0
])
for
key
,
val
in
settings
.
VM_ACCESS_PROTOCOLS
.
items
()]
)
# Later stored in database
LEASE_TYPES
=
tuple
([(
val
[
"name"
],
val
[
"verbose_name"
])
for
val
in
settings
.
LEASE_TYPES
])
LEASE_TYPES
=
tuple
(
[(
val
[
"name"
],
val
[
"verbose_name"
])
for
val
in
settings
.
LEASE_TYPES
]
)
class
Instance
(
models
.
Model
):
name
=
models
.
CharField
(
max_length
=
100
,
help_text
=
"Human readable name of instance"
)
remote_id
=
models
.
CharField
(
max_length
=
100
,
help_text
=
"ID of the instance on the backend"
)
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"
)
system
=
models
.
CharField
(
max_length
=
50
,
help_text
=
"Operating system type"
)
password
=
models
.
CharField
(
max_length
=
50
,
help_text
=
"Original password of the instance"
)
lease
=
models
.
CharField
(
max_length
=
50
,
choices
=
LEASE_TYPES
,
help_text
=
"Expiration method"
)
name
=
models
.
CharField
(
max_length
=
100
,
help_text
=
"Human readable name of instance"
)
remote_id
=
models
.
CharField
(
max_length
=
100
,
help_text
=
"ID of the instance on the backend"
)
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"
)
system
=
models
.
CharField
(
max_length
=
50
,
help_text
=
"Operating system type"
)
password
=
models
.
CharField
(
max_length
=
50
,
help_text
=
"Original password of the instance"
)
lease
=
models
.
CharField
(
max_length
=
50
,
choices
=
LEASE_TYPES
,
help_text
=
"Expiration method"
)
time_of_suspend
=
models
.
DateTimeField
(
help_text
=
"After this point in time, the instance will be suspended"
)
help_text
=
"After this point in time, the instance will be suspended"
)
time_of_delete
=
models
.
DateTimeField
(
help_text
=
"After this point in time, the instance will be deleted!"
)
help_text
=
"After this point in time, the instance will be deleted!"
)
deleted
=
models
.
BooleanField
(
help_text
=
"Indicates if the instance is ready for garbage collection"
,
default
=
False
)
default
=
False
,
)
# template
# disks
# owner
recircle/instance/serializers.py
View file @
a35f2402
...
...
@@ -4,7 +4,6 @@ from .models import Instance
class
InstanceSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Instance
fields
=
"__all__"
recircle/instance/tests.py
View file @
a35f2402
from
django.test
import
TestCase
#
from django.test import TestCase
# Create your tests here.
recircle/instance/urls.py
View file @
a35f2402
...
...
@@ -3,8 +3,8 @@ from rest_framework.urlpatterns import format_suffix_patterns
from
instance
import
views
urlpatterns
=
[
path
(
'instances/'
,
views
.
InstanceList
.
as_view
()),
path
(
'instances/<int:pk>/'
,
views
.
InstanceDetail
.
as_view
()),
path
(
"instances/"
,
views
.
InstanceList
.
as_view
()),
path
(
"instances/<int:pk>/"
,
views
.
InstanceDetail
.
as_view
()),
# path('instances/<int:pk>/action/', views.InstanceAction.as_view())
]
...
...
recircle/instance/views.py
View file @
a35f2402
...
...
@@ -10,7 +10,7 @@ import openstack
import
datetime
conn
=
openstack
.
connect
(
cloud
=
'openstack'
)
conn
=
openstack
.
connect
(
cloud
=
"openstack"
)
class
InstanceList
(
APIView
):
...
...
@@ -22,9 +22,11 @@ class InstanceList(APIView):
data
=
request
.
data
interface
=
OSVirtualMachineManager
(
conn
)
imageId
=
"da51253f-867c-472d-8ce0-81e7b7126d60"
flavorId
=
'1'
flavorId
=
"1"
networks
=
[{
"uuid"
:
"c03d0d4b-413e-4cc6-9ebe-c0b5ca0dac3a"
}]
newBackendInstance
=
interface
.
create_vm_from_template
(
"Integration test vm 2"
,
imageId
,
flavorId
,
networks
)
newBackendInstance
=
interface
.
create_vm_from_template
(
"Integration test vm 2"
,
imageId
,
flavorId
,
networks
)
newInstance
=
Instance
(
name
=
data
[
"name"
],
remote_id
=
newBackendInstance
.
id
,
...
...
@@ -35,7 +37,7 @@ class InstanceList(APIView):
lease
=
data
[
"lease"
],
time_of_suspend
=
datetime
.
datetime
.
now
(),
time_of_delete
=
datetime
.
datetime
.
now
(),
deleted
=
False
deleted
=
False
,
)
newInstance
.
save
()
return
Response
(
newInstance
.
pk
)
...
...
recircle/manage.py
View file @
a35f2402
...
...
@@ -2,8 +2,8 @@
import
os
import
sys
if
__name__
==
'__main__'
:
os
.
environ
.
setdefault
(
'DJANGO_SETTINGS_MODULE'
,
'recircle.settings'
)
if
__name__
==
"__main__"
:
os
.
environ
.
setdefault
(
"DJANGO_SETTINGS_MODULE"
,
"recircle.settings"
)
try
:
from
django.core.management
import
execute_from_command_line
except
ImportError
as
exc
:
...
...
recircle/recircle/settings.py
View file @
a35f2402
...
...
@@ -20,72 +20,69 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY
=
'xhe8=w50lz82gjb6+z
%
(rwk2c+1kd!
%
(iv_s^!tp)*5cnb=-^t'
SECRET_KEY
=
"xhe8=w50lz82gjb6+z
%
(rwk2c+1kd!
%
(iv_s^!tp)*5cnb=-^t"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG
=
True
ALLOWED_HOSTS
=
[
'vm.niif.cloud.bme.hu'
,
'localhost'
,
]
ALLOWED_HOSTS
=
[
"vm.niif.cloud.bme.hu"
,
"localhost"
]
# Application definition
INSTALLED_APPS
=
[
'instance.apps.InstanceConfig'
,
'image.apps.ImageConfig'
,
'django.contrib.admin'
,
'django.contrib.auth'
,
'django.contrib.contenttypes'
,
'django.contrib.sessions'
,
'django.contrib.messages'
,
'django.contrib.staticfiles'
,
'rest_framework'
,
'djoser'
,
'rest_framework_swagger'
,
'corsheaders'
,
"instance.apps.InstanceConfig"
,
"image.apps.ImageConfig"
,
"django.contrib.admin"
,
"django.contrib.auth"
,
"django.contrib.contenttypes"
,
"django.contrib.sessions"
,
"django.contrib.messages"
,
"django.contrib.staticfiles"
,
"rest_framework"
,
"djoser"
,
"rest_framework_swagger"
,
"corsheaders"
,
]
MIDDLEWARE
=
[
'django.middleware.security.SecurityMiddleware'
,
'django.contrib.sessions.middleware.SessionMiddleware'
,
'corsheaders.middleware.CorsMiddleware'
,
'django.middleware.common.CommonMiddleware'
,
'django.middleware.csrf.CsrfViewMiddleware'
,
'django.contrib.auth.middleware.AuthenticationMiddleware'
,
'django.contrib.messages.middleware.MessageMiddleware'
,
'django.middleware.clickjacking.XFrameOptionsMiddleware'
,
"django.middleware.security.SecurityMiddleware"
,
"django.contrib.sessions.middleware.SessionMiddleware"
,
"corsheaders.middleware.CorsMiddleware"
,
"django.middleware.common.CommonMiddleware"
,
"django.middleware.csrf.CsrfViewMiddleware"
,
"django.contrib.auth.middleware.AuthenticationMiddleware"
,
"django.contrib.messages.middleware.MessageMiddleware"
,
"django.middleware.clickjacking.XFrameOptionsMiddleware"
,
]
ROOT_URLCONF
=
'recircle.urls'
ROOT_URLCONF
=
"recircle.urls"
TEMPLATES
=
[
{
'BACKEND'
:
'django.template.backends.django.DjangoTemplates'
,
'DIRS'
:
[],
'APP_DIRS'
:
True
,
'OPTIONS'
:
{
'context_processors'
:
[
'django.template.context_processors.debug'
,
'django.template.context_processors.request'
,
'django.contrib.auth.context_processors.auth'
,
'django.contrib.messages.context_processors.messages'
,
]
,
"BACKEND"
:
"django.template.backends.django.DjangoTemplates"
,
"DIRS"
:
[],
"APP_DIRS"
:
True
,
"OPTIONS"
:
{
"context_processors"
:
[
"django.template.context_processors.debug"
,
"django.template.context_processors.request"
,
"django.contrib.auth.context_processors.auth"
,
"django.contrib.messages.context_processors.messages"
,
]
},
}
,
}
]
WSGI_APPLICATION
=
'recircle.wsgi.application'
WSGI_APPLICATION
=
"recircle.wsgi.application"
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES
=
{
'default'
:
{
'ENGINE'
:
'django.db.backends.sqlite3'
,
'NAME'
:
os
.
path
.
join
(
BASE_DIR
,
'db.sqlite3'
),
"default"
:
{
"ENGINE"
:
"django.db.backends.sqlite3"
,
"NAME"
:
os
.
path
.
join
(
BASE_DIR
,
"db.sqlite3"
),
}
}
...
...
@@ -95,26 +92,20 @@ DATABASES = {
AUTH_PASSWORD_VALIDATORS
=
[
{
'NAME'
:
'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'
,
},
{
'NAME'
:
'django.contrib.auth.password_validation.MinimumLengthValidator'
,
},
{
'NAME'
:
'django.contrib.auth.password_validation.CommonPasswordValidator'
,
},
{
'NAME'
:
'django.contrib.auth.password_validation.NumericPasswordValidator'
,
"NAME"
:
"django.contrib.auth.password_validation.UserAttributeSimilarityValidator"
},
{
"NAME"
:
"django.contrib.auth.password_validation.MinimumLengthValidator"
},
{
"NAME"
:
"django.contrib.auth.password_validation.CommonPasswordValidator"
},
{
"NAME"
:
"django.contrib.auth.password_validation.NumericPasswordValidator"
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/
LANGUAGE_CODE
=
'en-us'
LANGUAGE_CODE
=
"en-us"
TIME_ZONE
=
'UTC'
TIME_ZONE
=
"UTC"
USE_I18N
=
True
...
...
@@ -126,7 +117,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL
=
'/static/'
STATIC_URL
=
"/static/"
###############################################################################
# RECIRCLE CONFIG
...
...
@@ -135,7 +126,7 @@ STATIC_URL = '/static/'
# VM ACCESS PROTOCOLS
VM_ACCESS_PROTOCOLS
=
{
"rdp"
:
[
"Remote Desktop Protocol"
,
3389
,
"tcp"
],
"ssh"
:
[
"Secure Shell"
,
22
,
"tcp"
]
"ssh"
:
[
"Secure Shell"
,
22
,
"tcp"
]
,
}
# LEASE TYPES
...
...
@@ -164,6 +155,4 @@ LEASE_TYPES = [
]
# CORS config for development version only
CORS_ORIGIN_WHITELIST
=
(
'http://localhost:3000'
,
)
CORS_ORIGIN_WHITELIST
=
(
"http://localhost:3000"
,)
recircle/recircle/urls.py
View file @
a35f2402
...
...
@@ -18,13 +18,13 @@ 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'
)
schema_view
=
get_swagger_view
(
title
=
"RECIRCLE API"
)
urlpatterns
=
[
path
(
'images/'
,
include
(
'image.urls'
)),
path
(
'api/v1/'
,
include
(
'instance.urls'
)),
path
(
'admin/'
,
admin
.
site
.
urls
),
re_path
(
r
'^auth/'
,
include
(
'djoser.urls'
)),
re_path
(
r
'^auth/'
,
include
(
'djoser.urls.authtoken'
)),
path
(
r
'swagger'
,
schema_view
)
path
(
"images/"
,
include
(
"image.urls"
)),
path
(
"api/v1/"
,
include
(
"instance.urls"
)),
path
(
"admin/"
,
admin
.
site
.
urls
),
re_path
(
r
"^auth/"
,
include
(
"djoser.urls"
)),
re_path
(
r
"^auth/"
,
include
(
"djoser.urls.authtoken"
)),
path
(
r
"swagger"
,
schema_view
),
]
recircle/recircle/wsgi.py
View file @
a35f2402
...
...
@@ -11,6 +11,6 @@ import os
from
django.core.wsgi
import
get_wsgi_application
os
.
environ
.
setdefault
(
'DJANGO_SETTINGS_MODULE'
,
'recircle.settings'
)
os
.
environ
.
setdefault
(
"DJANGO_SETTINGS_MODULE"
,
"recircle.settings"
)
application
=
get_wsgi_application
()
recircle/storage/admin.py
View file @
a35f2402
from
django.contrib
import
admin
#
from django.contrib import admin
# Register your models here.
recircle/storage/apps.py
View file @
a35f2402
...
...
@@ -2,4 +2,4 @@ from django.apps import AppConfig
class
StorageConfig
(
AppConfig
):
name
=
'storage'
name
=
"storage"
recircle/storage/models.py
View file @
a35f2402
from
django.db
import
models
# Create your models here.
class
DataStore
()
:
class
DataStore
:
"""Collection of virtual disks.
"""
name
=
models
.
CharField
(
max_length
=
100
,
unique
=
True
,
verbose_name
=
"name"
,
help_text
=
"Name of the data store."
)
remote_ID
=
models
.
CharField
(
max_length
=
40
,
unique
=
True
,
verbose_name
=
"remote_ID"
,
help_text
=
"ID, which helps access the data store."
)
#vm
\ No newline at end of file
name
=
models
.
CharField
(
max_length
=
100
,
unique
=
True
,
verbose_name
=
"name"
,
help_text
=
"Name of the data store."
,
)
remote_ID
=
models
.
CharField
(
max_length
=
40
,
unique
=
True
,
verbose_name
=
"remote_ID"
,
help_text
=
"ID, which helps access the data store."
,
)
# vm
recircle/storage/serializers.py
View file @
a35f2402
...
...
@@ -2,7 +2,8 @@ from rest_framework import serializers
from
.models
import
DataStore
class
DataStoreSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
DataStore
fields
=
(
'name'
,
'remote_ID'
,
)
fields
=
(
"name"
,
"remote_ID"
)
recircle/storage/tests.py
View file @
a35f2402
from
django.test
import
TestCase
#
from django.test import TestCase
# Create your tests here.
recircle/storage/views.py
View file @
a35f2402
from
django.shortcuts
import
render
#
from django.shortcuts import render
# Create your views here.
recircle/template/admin.py
View file @
a35f2402
from
django.contrib
import
admin
#
from django.contrib import admin
# Register your models here.
recircle/template/apps.py
View file @
a35f2402
...
...
@@ -2,4 +2,4 @@ from django.apps import AppConfig
class
TemplateConfig
(
AppConfig
):
name
=
'template'
name
=
"template"
recircle/template/models.py
View file @
a35f2402
from
django.db
import
models
class
InstanceTemplate
():
class
InstanceTemplate
:
"""Virtual machine template.
"""
name
=
models
.
CharField
(
max_length
=
100
,
verbose_name
=
"name"
,
help_text
=
"Human readable name of template."
)
description
=
models
.
TextField
(
verbose_name
=
"description"
,
blank
=
True
,
help_text
=
"Description of the template."
)
#owner = models.ForeignKey(User)
remote_ID
=
models
.
CharField
(
max_length
=
40
,
unique
=
True
,
verbose_name
=
"remote_ID"
,
help_text
=
"ID, which helps access the template."
)
\ No newline at end of file
name
=
models
.
CharField
(
max_length
=
100
,
verbose_name
=
"name"
,
help_text
=
"Human readable name of template."
,
)
description
=
models
.
TextField
(
verbose_name
=
"description"
,
blank
=
True
,
help_text
=
"Description of the template."
)
# owner = models.ForeignKey(User)
remote_ID
=
models
.
CharField
(
max_length
=
40
,
unique
=
True
,
verbose_name
=
"remote_ID"
,
help_text
=
"ID, which helps access the template."
,
)
recircle/template/serializers.py
View file @
a35f2402
...
...
@@ -2,7 +2,8 @@ from rest_framework import serializers
from
.models
import
InstanceTemplate
class
InstanceTemplateSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
InstanceTemplate
fields
=
(
'name'
,
'description'
,
'owner'
,
'remote_ID'
,
)
fields
=
(
"name"
,
"description"
,
"owner"
,
"remote_ID"
)
recircle/template/tests.py
View file @
a35f2402
from
django.test
import
TestCase
#
from django.test import TestCase
# Create your tests here.
recircle/template/views.py
View file @
a35f2402
from
django.shortcuts
import
render
#
from django.shortcuts import render
# Create your views here.
recircle/views.py
deleted
100644 → 0
View file @
16394b7c
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
from
rest_framework
import
status
from
implementation.vm.instance
import
OSVirtualMachineManager
import
openstack
conn
=
openstack
.
connect
(
cloud
=
'openstack'
)
class
InstanceList
(
APIView
):
def
get
(
self
,
request
,
format
=
None
):
instances
=
Instance
.
objects
.
all
()
# refresh OpenStack Attribs
interface
=
OSVirtualMachineManager
(
conn
)
return
Response
([
vm
for
vm
in
interface
.
list_all_vm
()])
# create response
serializer
=
InstanceSerializer
(
instances
,
many
=
True
)
return
Response
(
serializer
.
data
)
def
post
(
self
,
request
,
format
=
None
):
data
=
request
.
data
newId
=
0
interface
=
OSVirtualMachineManager
(
conn
)
imageId
=
"da51253f-867c-472d-8ce0-81e7b7126d60"
flavorId
=
{
"name"
:
1
}
networks
=
[{
"uuid"
:
"c03d0d4b-413e-4cc6-9ebe-c0b5ca0dac3a"
}]
interface
.
create_vm_from_template
(
"Integration test vm 1"
,
imageId
,
flavorId
,
networks
)
return
Response
(
newId
)
class
InstanceDetail
(
APIView
):
"""
Retrieve, update or delete a snippet instance.
"""
def
get_object
(
self
,
pk
):
try
:
return
Instance
.
objects
.
get
(
pk
=
pk
)
except
Instance
.
DoesNotExist
:
raise
Http404
def
get
(
self
,
request
,
pk
,
format
=
None
):
instance
=
self
.
get_object
(
pk
)
serializer
=
InstanceSerializer
(
instance
)
return
Response
(
serializer
.
data
)
def
put
(
self
,
request
,
pk
,
format
=
None
):
instance
=
self
.
get_object
(
pk
)
serializer
=
InstanceSerializer
(
instance
,
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
):
instance
=
self
.
get_object
(
pk
)
instance
.
delete
()
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
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