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
22dbafd0
authored
Aug 08, 2019
by
Belákovics Ádám
Browse files
Options
Browse Files
Download
Plain Diff
Merge instance_auth with DEV
parents
2e64ae8a
3a808815
Pipeline
#823
failed with stage
in 1 minute 20 seconds
Changes
21
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
165 additions
and
101 deletions
+165
-101
.gitignore
+0
-4
.gitlab-ci.yml
+4
-8
Pipfile
+2
-1
Pipfile.lock
+23
-7
recircle/image/models.py
+24
-2
recircle/image/serializers.py
+10
-2
recircle/image/tests.py
+5
-2
recircle/image/views.py
+38
-14
recircle/instance/migrations/0009_auto_20190715_0929.py
+0
-23
recircle/instance/migrations/0010_instance_template.py
+3
-3
recircle/instance/migrations/0010_merge_20190722_1216.py
+0
-14
recircle/instance/models.py
+5
-6
recircle/instance/tests.py
+5
-2
recircle/instance/views.py
+5
-8
recircle/interface_openstack
+1
-1
recircle/recircle/settings/base.py
+1
-0
recircle/recircle/settings/local.py
+4
-0
recircle/storage/tests.py
+5
-2
recircle/template/migrations/0007_basetemplate_network_id.py
+18
-0
recircle/template/models.py
+7
-0
recircle/template/tests.py
+5
-2
No files found.
.gitignore
View file @
22dbafd0
# IDEs
.vscode/
.idea/
...
...
@@ -84,6 +83,3 @@ environment.sh
# Cloud configure
clouds.yaml
.gitlab-ci.yml
View file @
22dbafd0
image
:
python:3.6
stages
:
-
lint
-
test
before_script
:
-
pip install pipenv
-
pipenv install -d
-
git submodule sync --recursive
-
git submodule update --init --recursive
flake8
:
stage
:
lint
script
:
-
pipenv run flake8
-
pip install flake8
-
flake8
test
:
script
:
-
pip install pipenv
-
pipenv install -d
-
cd recircle
-
pipenv run python manage.py test
Pipfile
View file @
22dbafd0
...
...
@@ -8,16 +8,17 @@ httpie = "*"
flake8 = "*"
django-rest-swagger = "*"
coverage = "*"
django-nose = "*"
[packages]
django = "*"
djangorestframework = "*"
djoser = "*"
django-cors-headers = "*"
openstacksdk = "*"
python-novaclient = "*"
keystoneauth1 = "*"
django-guardian = "*"
djoser = "*"
[requires]
python_version = "3.6"
Pipfile.lock
View file @
22dbafd0
{
"_meta": {
"hash": {
"sha256": "
88d304c135bc5ea2cf22f54d5512de3aa8433ebd185ab2bcb50bc3b8c746d010
"
"sha256": "
dd7bfbb33d07cbcc96d1f3b1f838538dba41f3eb0bf5279381714b4b9abf90d7
"
},
"pipfile-spec": 6,
"requires": {
...
...
@@ -280,11 +280,11 @@
},
"openstacksdk": {
"hashes": [
"sha256:
dc1232a58e30876ed6b28ee7bf5fee281b70048b187e88acd8a53cc3b63f9d8a
",
"sha256:
f6e045d2e0a111d3a8dd157d111a04f1354ad6cc7819f6c1db073426bea7734f
"
"sha256:
ae521b4083ecc3395e27b6a7d0f119a737cefb2f76277f16dc5b626a3c4d5c52
",
"sha256:
e3a1346a238d57d4f398f345a79d03b6705e229a4453f8b73acdcd00d04e6328
"
],
"index": "pypi",
"version": "==0.3
1.2
"
"version": "==0.3
2.0
"
},
"os-service-types": {
"hashes": [
...
...
@@ -316,10 +316,10 @@
},
"pbr": {
"hashes": [
"sha256:
0ca44dc9fd3b04a22297c2a91082d8df2894862e8f4c86a49dac69eae9e85ca0
",
"sha256:
4aed6c1b1fa5020def0f22aed663d87b81bb3235f112490b07d2643d7a98c5b5
"
"sha256:
56e52299170b9492513c64be44736d27a512fa7e606f21942160b68ce510b4bc
",
"sha256:
9b321c204a88d8ab5082699469f52cc94c5da45c51f114113d01b3d993c24cdf
"
],
"version": "==5.4.
1
"
"version": "==5.4.
2
"
},
"prettytable": {
"hashes": [
...
...
@@ -508,6 +508,14 @@
"index": "pypi",
"version": "==4.5.4"
},
"django-nose": {
"hashes": [
"sha256:58934a06a6932696e54c9e8af3fab49bf67ca9e9c840ad668cb7f51219808a07",
"sha256:f515d903cfaeda52c7a9198e0c8ed51563e82802b62a4e5fbd056fd830095318"
],
"index": "pypi",
"version": "==1.4.6"
},
"django-rest-swagger": {
"hashes": [
"sha256:48f6aded9937e90ae7cbe9e6c932b9744b8af80cc4e010088b3278c700e0685b",
...
...
@@ -607,6 +615,14 @@
],
"version": "==0.6.1"
},
"nose": {
"hashes": [
"sha256:9ff7c6cc443f8c51994b34a667bbcf45afd6d945be7477b52e97516fd17c53ac",
"sha256:dadcddc0aefbf99eea214e0f1232b94f2fa9bd98fa8353711dacb112bfcbbb2a",
"sha256:f1bffef9cbc82628f6e7d7b40d7e255aefaa1adb6a1b1d26c69a8b79e6208a98"
],
"version": "==1.3.7"
},
"openapi-codec": {
"hashes": [
"sha256:1bce63289edf53c601ea3683120641407ff6b708803b8954c8a876fe778d2145"
...
...
recircle/image/models.py
View file @
22dbafd0
...
...
@@ -82,7 +82,9 @@ class Image(models.Model):
uploaded_by_user
=
False
,
description
=
description
)
return
new_image
for
attr
,
value
in
new_image
.
__dict__
.
items
():
setattr
(
remote_image
,
attr
,
value
)
return
remote_image
@classmethod
def
create_from_user
(
cls
,
description
,
file_format
,
image_file
,
name
,
user
):
...
...
@@ -96,4 +98,24 @@ class Image(models.Model):
uploaded_by_user
=
True
,
description
=
description
)
return
new_image
for
attr
,
value
in
new_image
.
__dict__
.
items
():
setattr
(
remote_image
,
attr
,
value
)
return
remote_image
def
delete
(
self
):
interface
=
OpenstackImageManager
(
settings
.
CONNECTION
)
if
interface
.
delete
(
self
.
remote_id
):
super
()
.
delete
()
def
get
(
self
):
interface
=
OpenstackImageManager
(
settings
.
CONNECTION
)
image
=
interface
.
get
(
self
.
remote_id
)
for
attr
,
value
in
self
.
__dict__
.
items
():
setattr
(
image
,
attr
,
value
)
return
image
def
update
(
self
,
data
):
for
(
key
,
value
)
in
data
.
items
():
setattr
(
self
,
key
,
value
)
self
.
save
()
return
self
.
get
()
recircle/image/serializers.py
View file @
22dbafd0
...
...
@@ -3,9 +3,15 @@ from rest_framework import serializers
from
.models
import
Image
class
ImageUpdateSerializer
(
serializers
.
Serializer
):
name
=
serializers
.
CharField
(
required
=
False
)
description
=
serializers
.
CharField
(
required
=
False
)
class
ImageSerializer
(
serializers
.
ModelSerializer
):
image_file
=
serializers
.
FileField
(
write_only
=
True
)
file_format
=
serializers
.
CharField
(
max_length
=
10
,
write_only
=
True
)
file_format
=
serializers
.
CharField
(
max_length
=
10
)
size
=
serializers
.
IntegerField
()
class
Meta
:
model
=
Image
...
...
@@ -18,5 +24,7 @@ class ImageSerializer(serializers.ModelSerializer):
"created_at"
,
"uploaded_by_user"
,
"created_by"
,
"id"
,
"size"
,
)
read_only_fields
=
(
"created_at"
,
"uploaded_by_user"
,
"created_by"
,
"remote_id"
,
)
read_only_fields
=
(
"created_at"
,
"uploaded_by_user"
,
"created_by"
,
"remote_id"
,
"size"
,
)
recircle/image/tests.py
View file @
22dbafd0
#
from django.test import TestCase
from
django.test
import
TestCase
# Create your tests here.
class
ImageTest
(
TestCase
):
def
test_test
(
self
):
self
.
assertEqual
(
""
,
""
)
recircle/image/views.py
View file @
22dbafd0
# from django.shortcuts import render
from
rest_framework.viewsets
import
Model
ViewSet
from
rest_framework.viewsets
import
ViewSet
from
rest_framework.response
import
Response
from
django.shortcuts
import
get_object_or_404
from
rest_framework
import
status
from
django.core.exceptions
import
ObjectDoesNotExist
from
image.models
import
Image
from
image.serializers
import
ImageSerializer
from
image.serializers
import
ImageUpdateSerializer
class
ImageViewSet
(
ModelViewSet
):
serializer_class
=
ImageSerializer
queryset
=
Image
.
objects
.
all
()
# def list(self, request):
# return HttpResponse("list")
class
ImageViewSet
(
ViewSet
):
def
list
(
self
,
request
):
image_list
=
[]
images
=
Image
.
objects
.
all
()
for
image
in
images
:
image_list
.
append
(
image
.
get
())
serializer
=
ImageSerializer
(
image_list
,
many
=
True
)
return
Response
(
serializer
.
data
)
def
create
(
self
,
request
):
serializer
=
ImageSerializer
(
data
=
request
.
data
)
...
...
@@ -26,14 +34,30 @@ class ImageViewSet(ModelViewSet):
serializer
=
ImageSerializer
(
instance
=
new_image
)
return
Response
(
serializer
.
data
)
# def retrieve(self, request, pk=None):
# return HttpResponse("retrive")
def
retrieve
(
self
,
request
,
pk
=
None
):
queryset
=
Image
.
objects
.
all
()
image
=
get_object_or_404
(
queryset
,
pk
=
pk
)
serializer
=
ImageSerializer
(
instance
=
image
)
image
=
image
.
get
()
serializer
=
ImageSerializer
(
instance
=
image
)
return
Response
(
serializer
.
data
)
# def update(self, request, pk=None):
# return HttpResponse("update")
def
update
(
self
,
request
,
pk
=
None
):
serializer
=
ImageUpdateSerializer
(
data
=
request
.
data
)
serializer
.
is_valid
(
raise_exception
=
True
)
queryset
=
Image
.
objects
.
all
()
image
=
get_object_or_404
(
queryset
,
pk
=
pk
)
image
=
image
.
update
(
serializer
.
validated_data
)
serializer
=
ImageSerializer
(
instance
=
image
)
return
Response
(
serializer
.
data
)
#
def partial_update(self, request, pk=None):
# return HttpResponse("patch"
)
def
partial_update
(
self
,
request
,
pk
=
None
):
return
self
.
update
(
request
,
pk
)
# def destroy(self, request, pk=None):
# return HttpResponse("delete")
def
destroy
(
self
,
request
,
pk
=
None
):
try
:
image
=
Image
.
objects
.
get
(
id
=
pk
)
image
.
delete
()
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
except
ObjectDoesNotExist
:
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
recircle/instance/migrations/0009_auto_20190715_0929.py
deleted
100644 → 0
View file @
2e64ae8a
# Generated by Django 2.2.3 on 2019-07-15 09:29
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'instance'
,
'0008_auto_20190704_1310'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'instance'
,
name
=
'flavor'
,
field
=
models
.
ForeignKey
(
help_text
=
'Reasources given to the vm'
,
on_delete
=
'CASCADE'
,
related_name
=
'instances'
,
to
=
'instance.Flavor'
,
verbose_name
=
'flavor'
),
),
migrations
.
AlterField
(
model_name
=
'instance'
,
name
=
'lease'
,
field
=
models
.
ForeignKey
(
on_delete
=
'CASCADE'
,
related_name
=
'instances'
,
to
=
'instance.Lease'
),
),
]
recircle/instance/migrations/001
1
_instance_template.py
→
recircle/instance/migrations/001
0
_instance_template.py
View file @
22dbafd0
# Generated by Django 2.2.
3 on 2019-07-22 12:17
# Generated by Django 2.2.
4 on 2019-08-08 10:41
from
django.db
import
migrations
,
models
...
...
@@ -6,8 +6,8 @@ from django.db import migrations, models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'template'
,
'000
6_auto_20190719_1416
'
),
(
'instance'
,
'00
10_merge_20190722_1216
'
),
(
'template'
,
'000
7_basetemplate_network_id
'
),
(
'instance'
,
'00
09_auto_20190715_1354
'
),
]
operations
=
[
...
...
recircle/instance/migrations/0010_merge_20190722_1216.py
deleted
100644 → 0
View file @
2e64ae8a
# Generated by Django 2.2.3 on 2019-07-22 12:16
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'instance'
,
'0009_auto_20190715_1354'
),
(
'instance'
,
'0009_auto_20190715_0929'
),
]
operations
=
[
]
recircle/instance/models.py
View file @
22dbafd0
...
...
@@ -155,12 +155,11 @@ class Instance(models.Model):
disks
,
networks
,
flavor
):
# TODO: attach disks when the remote instance created
try
:
remote_inst
=
interface
.
create_vm_from_template
(
params
[
"name"
],
template
.
image
.
remote_id
,
flavor
.
remote_id
,
networks
,
)
remote_id
=
remote_inst
.
id
remote_id
=
interface
.
create_vm_from_template
(
params
[
"name"
],
template
.
image
.
remote_id
,
flavor
.
remote_id
,
networks
,
)
new_inst
=
cls
.
create
(
lease
,
owner
,
flavor
,
template
,
remote_id
,
params
)
return
new_inst
...
...
recircle/instance/tests.py
View file @
22dbafd0
#
from django.test import TestCase
from
django.test
import
TestCase
# Create your tests here.
class
InstanceTest
(
TestCase
):
def
test_test
(
self
):
self
.
assertEqual
(
""
,
""
)
recircle/instance/views.py
View file @
22dbafd0
from
instance.serializers
import
InstanceSerializer
,
FlavorSerializer
,
LeaseSerializer
from
django.http
import
Http404
from
django.conf
import
settings
from
rest_framework.viewsets
import
ViewSet
,
ModelViewSet
from
rest_framework.response
import
Response
from
rest_framework
import
status
from
rest_framework.decorators
import
action
from
template.serializers
import
InstanceFromTemplateSerializer
from
interface_openstack.implementation.vm.instance
import
(
OSVirtualMachineManager
)
from
instance.models
import
Instance
,
Flavor
,
Lease
from
instance.serializers
import
InstanceSerializer
,
FlavorSerializer
from
template.models
import
ImageTemplate
from
template.serializers
import
ImageTemplateModelSerializer
from
authorization.mixins
import
AuthorizationMixin
...
...
@@ -49,6 +44,10 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
def
create
(
self
,
request
):
data
=
request
.
data
template
=
ImageTemplate
.
objects
.
get
(
pk
=
data
[
"template"
])
# TODO: if the user can select anouther lease and flavor
# That will be applied, not from the template
# flavor = Flavor.objects.get(pk=data["flavor"])
# lease = Lease.objects.get(pk=data["lease"])
...
...
@@ -61,7 +60,7 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
"system"
:
data
[
"system"
],
},
lease
=
template
.
lease
,
networks
=
[{
"uuid"
:
"7485b41f-2524-4399-a20b-4b2c7ee9fd01"
}],
networks
=
[{
"uuid"
:
template
.
network_id
}],
template
=
template
,
flavor
=
template
.
flavor
,
owner
=
request
.
user
,
...
...
@@ -72,8 +71,6 @@ class InstanceViewSet(AuthorizationMixin, ViewSet):
def
retrieve
(
self
,
request
,
pk
):
instance
=
self
.
get_object
(
pk
)
instanceDict
=
InstanceSerializer
(
instance
)
.
data
print
(
instanceDict
)
remoteInstance
=
instance
.
get_remote_instance
()
remoteInstanceDict
=
remoteInstance
.
__dict__
...
...
interface_openstack
@
1a19e435
Subproject commit
e01d873c78ac17fed0438936f979de3cbaca6a5e
Subproject commit
1a19e4355f4af1abb49a3f6e07dc3a6c3f8bdf47
recircle/recircle/settings/base.py
View file @
22dbafd0
...
...
@@ -42,6 +42,7 @@ INSTALLED_APPS = [
"rest_framework_swagger"
,
"corsheaders"
,
"guardian"
,
"django_nose"
,
]
LOCAL_APPS
=
[
...
...
recircle/recircle/settings/local.py
View file @
22dbafd0
...
...
@@ -13,3 +13,7 @@ ADMIN_ENABLED = True
ALLOWED_HOSTS
=
[
'*'
]
AUTH_PASSWORD_VALIDATORS
=
[]
TEST_RUNNER
=
'django_nose.NoseTestSuiteRunner'
NOSE_ARGS
=
LOCAL_APPS
recircle/storage/tests.py
View file @
22dbafd0
#
from django.test import TestCase
from
django.test
import
TestCase
# Create your tests here.
class
StorageTest
(
TestCase
):
def
test_test
(
self
):
self
.
assertEqual
(
""
,
""
)
recircle/template/migrations/0007_basetemplate_network_id.py
0 → 100644
View file @
22dbafd0
# Generated by Django 2.2.3 on 2019-08-07 12:19
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'template'
,
'0006_auto_20190719_1416'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'basetemplate'
,
name
=
'network_id'
,
field
=
models
.
CharField
(
blank
=
True
,
help_text
=
'The new instance will be in this network.'
,
max_length
=
100
,
null
=
True
,
verbose_name
=
'network_id'
),
),
]
recircle/template/models.py
View file @
22dbafd0
...
...
@@ -44,6 +44,13 @@ class BaseTemplate(models.Model):
related_name
=
'templates'
)
lease
=
models
.
ForeignKey
(
Lease
,
on_delete
=
"CASCADE"
,
related_name
=
'templates'
)
network_id
=
models
.
CharField
(
max_length
=
100
,
verbose_name
=
"network_id"
,
help_text
=
"The new instance will be in this network."
,
null
=
True
,
blank
=
True
)
class
DiskTemplate
(
BaseTemplate
):
...
...
recircle/template/tests.py
View file @
22dbafd0
#
from django.test import TestCase
from
django.test
import
TestCase
# Create your tests here.
class
TemplateTest
(
TestCase
):
def
test_test
(
self
):
self
.
assertEqual
(
""
,
""
)
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