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
ccb52b46
authored
Jul 15, 2019
by
Chif Gergő
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
instance: Import logging, handle eexceptions
parent
2772d615
Pipeline
#780
failed with stages
in 2 minutes 16 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
15 deletions
+49
-15
recircle/instance/migrations/0009_auto_20190715_0929.py
+23
-0
recircle/instance/models.py
+26
-15
No files found.
recircle/instance/migrations/0009_auto_20190715_0929.py
0 → 100644
View file @
ccb52b46
# 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/models.py
View file @
ccb52b46
...
@@ -7,7 +7,9 @@ from image.models import Disk
...
@@ -7,7 +7,9 @@ from image.models import Disk
from
interface_openstack.implementation.vm.instance
import
(
from
interface_openstack.implementation.vm.instance
import
(
OSVirtualMachineManager
OSVirtualMachineManager
)
)
import
logging
logger
=
logging
.
getLogger
(
__name__
)
ACCESS_METHODS
=
tuple
(
ACCESS_METHODS
=
tuple
(
[(
key
,
val
[
0
])
for
key
,
val
in
settings
.
VM_ACCESS_PROTOCOLS
.
items
()]
[(
key
,
val
[
0
])
for
key
,
val
in
settings
.
VM_ACCESS_PROTOCOLS
.
items
()]
...
@@ -43,13 +45,17 @@ class Flavor(models.Model):
...
@@ -43,13 +45,17 @@ class Flavor(models.Model):
def
create
(
cls
,
name
,
description
,
ram
=
0
,
vcpu
=
0
,
def
create
(
cls
,
name
,
description
,
ram
=
0
,
vcpu
=
0
,
initial_disk
=
0
,
priority
=
0
):
initial_disk
=
0
,
priority
=
0
):
interface
=
OSVirtualMachineManager
(
settings
.
CONNECTION
)
interface
=
OSVirtualMachineManager
(
settings
.
CONNECTION
)
remote_flavor
=
interface
.
create_flavor
(
name
,
ram
,
vcpu
,
initial_disk
)
try
:
flavor
=
cls
(
name
=
name
,
description
=
description
,
remote_flavor
=
interface
.
create_flavor
(
name
,
ram
,
vcpu
,
initial_disk
)
remote_id
=
remote_flavor
.
id
,
ram
=
ram
,
vcpu
=
vcpu
,
initial_disk
=
initial_disk
,
priority
=
priority
)
flavor
.
save
()
return
flavor
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
except
Exception
as
e
:
logger
.
error
(
str
(
e
))
raise
ValueError
(
"Couldn't create Flavor in remote cloud."
)
class
Instance
(
models
.
Model
):
class
Instance
(
models
.
Model
):
...
@@ -110,6 +116,7 @@ class Instance(models.Model):
...
@@ -110,6 +116,7 @@ class Instance(models.Model):
inst
.
full_clean
()
inst
.
full_clean
()
inst
.
save
()
inst
.
save
()
logger
.
info
(
"New instance created"
)
return
inst
return
inst
@classmethod
@classmethod
...
@@ -117,15 +124,19 @@ class Instance(models.Model):
...
@@ -117,15 +124,19 @@ class Instance(models.Model):
disks
,
networks
,
flavor
):
disks
,
networks
,
flavor
):
# TODO: attach disks when the remote instance created
# TODO: attach disks when the remote instance created
interface
=
OSVirtualMachineManager
(
settings
.
CONNECTION
)
interface
=
OSVirtualMachineManager
(
settings
.
CONNECTION
)
remote_inst
=
interface
.
create_vm_from_template
(
params
[
"name"
],
try
:
template
.
remote_ID
,
remote_inst
=
interface
.
create_vm_from_template
(
params
[
"name"
],
flavor
.
remote_id
,
template
.
remote_ID
,
networks
,
flavor
.
remote_id
,
)
networks
,
remote_id
=
remote_inst
.
id
)
new_inst
=
cls
.
create
(
lease
,
owner
,
flavor
,
remote_id
,
params
)
remote_id
=
remote_inst
.
id
new_inst
=
cls
.
create
(
lease
,
owner
,
flavor
,
remote_id
,
params
)
return
new_inst
return
new_inst
except
Exception
as
e
:
logger
.
error
(
str
(
e
))
raise
ValueError
(
"Couldn't create Flavor in remote cloud."
"Search the logs for more detail."
)
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
()
...
...
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