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
15057b46
authored
Jul 11, 2019
by
Chif Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Flavor create method, fix instance create
parent
2b3c0497
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
8 deletions
+31
-8
Pipfile
+1
-0
recircle/instance/admin.py
+3
-1
recircle/instance/models.py
+27
-7
No files found.
Pipfile
View file @
15057b46
...
...
@@ -6,6 +6,7 @@ verify_ssl = true
[dev-packages]
httpie = "*"
django-rest-swagger = "*"
coverage = "*"
[packages]
django = "*"
...
...
recircle/instance/admin.py
View file @
15057b46
from
django.contrib
import
admin
from
instance.models
import
Instance
from
instance.models
import
Instance
,
Flavor
,
Lease
admin
.
site
.
register
(
Instance
)
admin
.
site
.
register
(
Flavor
)
admin
.
site
.
register
(
Lease
)
recircle/instance/models.py
View file @
15057b46
...
...
@@ -2,8 +2,9 @@ from django.db import models
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.utils
import
timezone
from
datetime
import
timedelta
from
image.models
import
Disk
from
implementation.vm.instance
import
OSVirtualMachineManager
from
i
nterface_openstack.i
mplementation.vm.instance
import
OSVirtualMachineManager
import
openstack
...
...
@@ -37,6 +38,19 @@ class Flavor(models.Model):
initial_disk
=
models
.
IntegerField
(
blank
=
True
,
null
=
True
)
priority
=
models
.
IntegerField
(
blank
=
True
,
null
=
True
)
@classmethod
def
create
(
cls
,
name
,
description
,
ram
=
0
,
vcpu
=
0
,
initial_disk
=
0
,
priority
=
0
):
conn
=
openstack
.
connect
(
cloud
=
"openstack"
)
interface
=
OSVirtualMachineManager
(
conn
)
remote_flavor
=
interface
.
create_flavor
(
name
,
ram
,
vcpu
,
initial_disk
)
flavor
=
cls
(
name
=
name
,
description
=
description
,
remote_id
=
remote_flavor
.
id
,
ram
=
ram
,
vcpu
=
vcpu
,
initial_disk
=
initial_disk
,
priority
=
priority
)
flavor
.
save
()
return
flavor
class
Instance
(
models
.
Model
):
"""Virtual machine instance.
...
...
@@ -84,8 +98,10 @@ class Instance(models.Model):
owner
=
models
.
ForeignKey
(
User
,
on_delete
=
"CASCADE"
,
null
=
True
)
flavor
=
models
.
ForeignKey
(
Flavor
,
help_text
=
"Reasources given to the vm"
,
verbose_name
=
"flavor"
,
on_delete
=
"CASCADE"
)
lease
=
models
.
ForeignKey
(
Lease
,
on_delete
=
"CASCADE"
)
verbose_name
=
"flavor"
,
on_delete
=
"CASCADE"
,
related_name
=
'instances'
)
lease
=
models
.
ForeignKey
(
Lease
,
on_delete
=
"CASCADE"
,
related_name
=
'instances'
)
@classmethod
def
create
(
cls
,
lease
,
owner
,
flavor
,
remote_id
,
params
):
...
...
@@ -94,6 +110,8 @@ class Instance(models.Model):
inst
.
full_clean
()
inst
.
save
()
return
inst
@classmethod
def
create_instance_from_template
(
cls
,
params
,
template
,
owner
,
lease
,
disks
,
networks
,
flavor
):
...
...
@@ -103,7 +121,6 @@ class Instance(models.Model):
template
.
remote_ID
,
flavor
.
remote_id
,
networks
,
# disks
)
remote_id
=
remote_inst
.
id
new_inst
=
cls
.
create
(
lease
,
owner
,
flavor
,
remote_id
,
params
)
...
...
@@ -111,7 +128,7 @@ class Instance(models.Model):
return
new_inst
def
clean
(
self
,
*
args
,
**
kwargs
):
#
self.time_of_suspend, self.time_of_delete = self.get_renew_times()
self
.
time_of_suspend
,
self
.
time_of_delete
=
self
.
get_renew_times
()
super
(
Instance
,
self
)
.
clean
(
*
args
,
**
kwargs
)
def
get_renew_times
(
self
,
lease
=
None
):
...
...
@@ -120,5 +137,8 @@ class Instance(models.Model):
if
lease
is
None
:
lease
=
self
.
lease
return
(
timezone
.
now
()
+
lease
.
suspend_interval_in_sec
,
timezone
.
now
()
+
lease
.
delete_interval_in_sec
)
timezone
.
now
()
+
timedelta
(
milliseconds
=
lease
.
suspend_interval_in_sec
),
timezone
.
now
()
+
timedelta
(
milliseconds
=
lease
.
delete_interval_in_sec
)
)
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