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
...
@@ -6,6 +6,7 @@ verify_ssl = true
[dev-packages]
[dev-packages]
httpie = "*"
httpie = "*"
django-rest-swagger = "*"
django-rest-swagger = "*"
coverage = "*"
[packages]
[packages]
django = "*"
django = "*"
...
...
recircle/instance/admin.py
View file @
15057b46
from
django.contrib
import
admin
from
django.contrib
import
admin
from
instance.models
import
Instance
from
instance.models
import
Instance
,
Flavor
,
Lease
admin
.
site
.
register
(
Instance
)
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
...
@@ -2,8 +2,9 @@ from django.db import models
from
django.conf
import
settings
from
django.conf
import
settings
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.utils
import
timezone
from
django.utils
import
timezone
from
datetime
import
timedelta
from
image.models
import
Disk
from
image.models
import
Disk
from
implementation.vm.instance
import
OSVirtualMachineManager
from
i
nterface_openstack.i
mplementation.vm.instance
import
OSVirtualMachineManager
import
openstack
import
openstack
...
@@ -37,6 +38,19 @@ class Flavor(models.Model):
...
@@ -37,6 +38,19 @@ class Flavor(models.Model):
initial_disk
=
models
.
IntegerField
(
blank
=
True
,
null
=
True
)
initial_disk
=
models
.
IntegerField
(
blank
=
True
,
null
=
True
)
priority
=
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
):
class
Instance
(
models
.
Model
):
"""Virtual machine instance.
"""Virtual machine instance.
...
@@ -84,8 +98,10 @@ class Instance(models.Model):
...
@@ -84,8 +98,10 @@ class Instance(models.Model):
owner
=
models
.
ForeignKey
(
User
,
on_delete
=
"CASCADE"
,
null
=
True
)
owner
=
models
.
ForeignKey
(
User
,
on_delete
=
"CASCADE"
,
null
=
True
)
flavor
=
models
.
ForeignKey
(
Flavor
,
help_text
=
"Reasources given to the vm"
,
flavor
=
models
.
ForeignKey
(
Flavor
,
help_text
=
"Reasources given to the vm"
,
verbose_name
=
"flavor"
,
on_delete
=
"CASCADE"
)
verbose_name
=
"flavor"
,
on_delete
=
"CASCADE"
,
lease
=
models
.
ForeignKey
(
Lease
,
on_delete
=
"CASCADE"
)
related_name
=
'instances'
)
lease
=
models
.
ForeignKey
(
Lease
,
on_delete
=
"CASCADE"
,
related_name
=
'instances'
)
@classmethod
@classmethod
def
create
(
cls
,
lease
,
owner
,
flavor
,
remote_id
,
params
):
def
create
(
cls
,
lease
,
owner
,
flavor
,
remote_id
,
params
):
...
@@ -94,6 +110,8 @@ class Instance(models.Model):
...
@@ -94,6 +110,8 @@ class Instance(models.Model):
inst
.
full_clean
()
inst
.
full_clean
()
inst
.
save
()
inst
.
save
()
return
inst
@classmethod
@classmethod
def
create_instance_from_template
(
cls
,
params
,
template
,
owner
,
lease
,
def
create_instance_from_template
(
cls
,
params
,
template
,
owner
,
lease
,
disks
,
networks
,
flavor
):
disks
,
networks
,
flavor
):
...
@@ -103,7 +121,6 @@ class Instance(models.Model):
...
@@ -103,7 +121,6 @@ class Instance(models.Model):
template
.
remote_ID
,
template
.
remote_ID
,
flavor
.
remote_id
,
flavor
.
remote_id
,
networks
,
networks
,
# disks
)
)
remote_id
=
remote_inst
.
id
remote_id
=
remote_inst
.
id
new_inst
=
cls
.
create
(
lease
,
owner
,
flavor
,
remote_id
,
params
)
new_inst
=
cls
.
create
(
lease
,
owner
,
flavor
,
remote_id
,
params
)
...
@@ -111,7 +128,7 @@ class Instance(models.Model):
...
@@ -111,7 +128,7 @@ class Instance(models.Model):
return
new_inst
return
new_inst
def
clean
(
self
,
*
args
,
**
kwargs
):
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
)
super
(
Instance
,
self
)
.
clean
(
*
args
,
**
kwargs
)
def
get_renew_times
(
self
,
lease
=
None
):
def
get_renew_times
(
self
,
lease
=
None
):
...
@@ -120,5 +137,8 @@ class Instance(models.Model):
...
@@ -120,5 +137,8 @@ class Instance(models.Model):
if
lease
is
None
:
if
lease
is
None
:
lease
=
self
.
lease
lease
=
self
.
lease
return
(
return
(
timezone
.
now
()
+
lease
.
suspend_interval_in_sec
,
timezone
.
now
()
+
timedelta
(
timezone
.
now
()
+
lease
.
delete_interval_in_sec
)
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