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
e28c1606
authored
Jul 22, 2019
by
Chif Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create flavor serializer, add delete methods to models
parent
83f92285
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
5 deletions
+35
-5
recircle/instance/models.py
+20
-2
recircle/instance/serializers.py
+7
-1
recircle/instance/urls.py
+1
-0
recircle/instance/views.py
+7
-2
No files found.
recircle/instance/models.py
View file @
e28c1606
...
@@ -55,7 +55,16 @@ class Flavor(models.Model):
...
@@ -55,7 +55,16 @@ class Flavor(models.Model):
return
flavor
return
flavor
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
error
(
str
(
e
))
logger
.
error
(
str
(
e
))
raise
ValueError
(
"Couldn't create Flavor in remote cloud."
)
raise
ValueError
(
"Can't create Flavor in remote cloud."
)
def
delete
(
self
):
interface
=
OSVirtualMachineManager
(
settings
.
CONNECTION
)
try
:
interface
.
delete_flavor
(
self
.
remote_id
)
super
(
Flavor
,
self
)
.
delete
()
except
Exception
as
e
:
if
e
.
OpenStackError
:
logger
.
error
(
"Can not delete the flavor in remote cloud"
)
class
Instance
(
models
.
Model
):
class
Instance
(
models
.
Model
):
...
@@ -135,7 +144,7 @@ class Instance(models.Model):
...
@@ -135,7 +144,7 @@ class Instance(models.Model):
return
new_inst
return
new_inst
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
error
(
str
(
e
))
logger
.
error
(
str
(
e
))
raise
ValueError
(
"C
ouldn't create Flavor
in remote cloud."
raise
ValueError
(
"C
an't create Instance
in remote cloud."
"Search the logs for more detail."
)
"Search the logs for more detail."
)
def
clean
(
self
,
*
args
,
**
kwargs
):
def
clean
(
self
,
*
args
,
**
kwargs
):
...
@@ -153,3 +162,12 @@ class Instance(models.Model):
...
@@ -153,3 +162,12 @@ class Instance(models.Model):
timezone
.
now
()
+
timedelta
(
timezone
.
now
()
+
timedelta
(
seconds
=
lease
.
delete_interval_in_sec
)
seconds
=
lease
.
delete_interval_in_sec
)
)
)
def
delete
(
self
):
interface
=
OSVirtualMachineManager
(
settings
.
CONNECTION
)
try
:
interface
.
destroy_vm
(
self
.
remote_id
)
super
(
Instance
,
self
)
.
delete
()
except
Exception
as
e
:
if
e
.
OpenStackError
:
logger
.
error
(
"Can not delete the instance in remote cloud"
)
recircle/instance/serializers.py
View file @
e28c1606
from
rest_framework
import
serializers
from
rest_framework
import
serializers
from
.models
import
Flavor
,
Instance
from
.models
import
Flavor
,
Instance
,
Lease
class
InstanceSerializer
(
serializers
.
ModelSerializer
):
class
InstanceSerializer
(
serializers
.
ModelSerializer
):
...
@@ -15,3 +15,9 @@ class FlavorSerializer(serializers.ModelSerializer):
...
@@ -15,3 +15,9 @@ class FlavorSerializer(serializers.ModelSerializer):
class
Meta
:
class
Meta
:
model
=
Flavor
model
=
Flavor
fields
=
"__all__"
fields
=
"__all__"
class
LeaseSerializer
(
serializers
.
ModelSerializer
):
class
Meta
:
model
=
Lease
fields
=
'__all__'
recircle/instance/urls.py
View file @
e28c1606
...
@@ -4,6 +4,7 @@ from rest_framework import routers
...
@@ -4,6 +4,7 @@ from rest_framework import routers
router
=
routers
.
SimpleRouter
()
router
=
routers
.
SimpleRouter
()
router
.
register
(
r'instances'
,
views
.
InstanceViewSet
,
basename
=
'instance'
)
router
.
register
(
r'instances'
,
views
.
InstanceViewSet
,
basename
=
'instance'
)
router
.
register
(
r'flavors'
,
views
.
FlavorViewSet
,
basename
=
'flavor'
)
router
.
register
(
r'flavors'
,
views
.
FlavorViewSet
,
basename
=
'flavor'
)
router
.
register
(
r'leases'
,
views
.
LeaseViewSet
,
basename
=
'lease'
)
urlpatterns
=
router
.
urls
urlpatterns
=
router
.
urls
recircle/instance/views.py
View file @
e28c1606
from
instance.serializers
import
InstanceSerializer
,
FlavorSerializer
from
instance.serializers
import
InstanceSerializer
,
FlavorSerializer
,
LeaseSerializer
from
django.http
import
Http404
from
django.http
import
Http404
from
django.conf
import
settings
from
django.conf
import
settings
from
rest_framework.viewsets
import
ViewSet
from
rest_framework.viewsets
import
ViewSet
,
ModelViewSet
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework
import
status
from
rest_framework
import
status
from
interface_openstack.implementation.vm.instance
import
(
from
interface_openstack.implementation.vm.instance
import
(
...
@@ -106,3 +106,8 @@ class FlavorViewSet(ViewSet):
...
@@ -106,3 +106,8 @@ class FlavorViewSet(ViewSet):
flavor
=
self
.
get_object
(
pk
)
flavor
=
self
.
get_object
(
pk
)
flavor
.
delete
()
flavor
.
delete
()
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
class
LeaseViewSet
(
ModelViewSet
):
queryset
=
Lease
.
objects
.
all
()
serializer_class
=
LeaseSerializer
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