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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
2 deletions
+36
-2
recircle/instance/migrations/0009_auto_20190715_0929.py
+23
-0
recircle/instance/models.py
+13
-2
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
from
interface_openstack.implementation.vm.instance
import
(
OSVirtualMachineManager
)
import
logging
logger
=
logging
.
getLogger
(
__name__
)
ACCESS_METHODS
=
tuple
(
[(
key
,
val
[
0
])
for
key
,
val
in
settings
.
VM_ACCESS_PROTOCOLS
.
items
()]
...
...
@@ -43,13 +45,17 @@ class Flavor(models.Model):
def
create
(
cls
,
name
,
description
,
ram
=
0
,
vcpu
=
0
,
initial_disk
=
0
,
priority
=
0
):
interface
=
OSVirtualMachineManager
(
settings
.
CONNECTION
)
try
:
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
except
Exception
as
e
:
logger
.
error
(
str
(
e
))
raise
ValueError
(
"Couldn't create Flavor in remote cloud."
)
class
Instance
(
models
.
Model
):
...
...
@@ -110,6 +116,7 @@ class Instance(models.Model):
inst
.
full_clean
()
inst
.
save
()
logger
.
info
(
"New instance created"
)
return
inst
@classmethod
...
...
@@ -117,6 +124,7 @@ class Instance(models.Model):
disks
,
networks
,
flavor
):
# TODO: attach disks when the remote instance created
interface
=
OSVirtualMachineManager
(
settings
.
CONNECTION
)
try
:
remote_inst
=
interface
.
create_vm_from_template
(
params
[
"name"
],
template
.
remote_ID
,
flavor
.
remote_id
,
...
...
@@ -124,8 +132,11 @@ class Instance(models.Model):
)
remote_id
=
remote_inst
.
id
new_inst
=
cls
.
create
(
lease
,
owner
,
flavor
,
remote_id
,
params
)
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
):
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