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
f99a7459
authored
Jul 12, 2019
by
Chif Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modify serializers add delete signal to instances
parent
407d7029
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
23 deletions
+41
-23
recircle/instance/models.py
+7
-5
recircle/instance/serializers.py
+17
-16
recircle/instance/signals.py
+13
-0
recircle/instance/views.py
+3
-1
recircle/interface_openstack
+1
-1
No files found.
recircle/instance/models.py
View file @
f99a7459
...
...
@@ -4,7 +4,9 @@ from django.contrib.auth.models import User
from
django.utils
import
timezone
from
datetime
import
timedelta
from
image.models
import
Disk
from
interface_openstack.implementation.vm.instance
import
OSVirtualMachineManager
from
interface_openstack.implementation.vm.instance
import
(
OSVirtualMachineManager
)
import
openstack
...
...
@@ -115,8 +117,8 @@ class Instance(models.Model):
@classmethod
def
create_instance_from_template
(
cls
,
params
,
template
,
owner
,
lease
,
disks
,
networks
,
flavor
):
conn
=
openstack
.
connect
(
cloud
=
"openstack"
)
interface
=
OSVirtualMachineManager
(
conn
)
# TODO: attach disks when the remote instance created
interface
=
OSVirtualMachineManager
(
settings
.
CONNECTION
)
remote_inst
=
interface
.
create_vm_from_template
(
params
[
"name"
],
template
.
remote_ID
,
flavor
.
remote_id
,
...
...
@@ -138,7 +140,7 @@ class Instance(models.Model):
lease
=
self
.
lease
return
(
timezone
.
now
()
+
timedelta
(
milli
seconds
=
lease
.
suspend_interval_in_sec
),
seconds
=
lease
.
suspend_interval_in_sec
),
timezone
.
now
()
+
timedelta
(
milli
seconds
=
lease
.
delete_interval_in_sec
)
seconds
=
lease
.
delete_interval_in_sec
)
)
recircle/instance/serializers.py
View file @
f99a7459
from
rest_framework
import
serializers
from
.models
import
Flavor
class
InstanceSerializer
(
serializers
.
Serializer
):
name
=
serializers
.
CharField
()
description
=
serializers
.
CharField
()
system
=
serializers
.
CharField
()
lease
=
serializers
.
RelatedField
(
read_only
=
True
)
flavor
=
serializers
.
RelatedField
(
read_only
=
True
)
class
FlavorSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Flavor
fields
=
'__all__'
from
rest_framework
import
serializers
from
.models
import
Flavor
,
Instance
class
InstanceSerializer
(
serializers
.
ModelSerializer
):
lease
=
serializers
.
PrimaryKeyRelatedField
(
read_only
=
True
)
flavor
=
serializers
.
PrimaryKeyRelatedField
(
read_only
=
True
)
class
Meta
:
model
=
Instance
fields
=
(
"name"
,
"description"
,
"system"
,
"lease"
,
"flavor"
)
class
FlavorSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Flavor
fields
=
"__all__"
recircle/instance/signals.py
0 → 100644
View file @
f99a7459
from
django.dispatch
import
receiver
from
django.db.models.signals
import
pre_delete
from
django.conf
import
settings
from
.models
import
Instance
from
interface_openstack.implementation.vm.instance
import
(
OSVirtualMachineManager
)
@receiver
(
pre_delete
,
sender
=
Instance
)
def
delete_remote_instance
(
sender
,
instance
,
**
kwargs
):
interface
=
OSVirtualMachineManager
(
settings
.
CONNECTION
)
interface
.
destroy_vm
(
instance
.
remote_id
)
recircle/instance/views.py
View file @
f99a7459
...
...
@@ -4,7 +4,9 @@ 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
from
interface_openstack.implementation.vm.instance
import
(
OSVirtualMachineManager
)
from
template.models
import
InstanceTemplate
from
instance.models
import
Instance
,
Flavor
,
Lease
from
django.contrib.auth.models
import
User
...
...
interface_openstack
@
068a7155
Subproject commit
e01d873c78ac17fed0438936f979de3cbaca6a5e
Subproject commit
068a7155cd97ba5c6d0a06b9c0a6274b22fe8d3c
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