Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
synnefo
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
itminedu
synnefo
Commits
a4fe3238
Commit
a4fe3238
authored
13 years ago
by
Christos Stavrakakis
Browse files
Options
Downloads
Patches
Plain Diff
Release IP addresses when nics are destroyed
parent
b124b12d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
snf-cyclades-app/synnefo/logic/backend.py
+24
-16
24 additions, 16 deletions
snf-cyclades-app/synnefo/logic/backend.py
with
24 additions
and
16 deletions
snf-cyclades-app/synnefo/logic/backend.py
+
24
−
16
View file @
a4fe3238
...
...
@@ -84,6 +84,7 @@ def process_op_status(vm, etime, jobid, opcode, status, logmsg):
utils
.
update_state
(
vm
,
state_for_success
)
# Set the deleted flag explicitly, cater for admin-initiated removals
if
opcode
==
'
OP_INSTANCE_REMOVE
'
:
release_instance_nics
(
vm
)
vm
.
deleted
=
True
vm
.
nics
.
all
().
delete
()
...
...
@@ -115,23 +116,12 @@ def process_net_status(vm, etime, nics):
Update the state of the VM in the DB accordingly.
"""
old_nics
=
vm
.
nics
.
order_by
(
'
index
'
)
new_nics
=
enumerate
(
nics
)
networks
=
{}
for
old_nic
in
old_nics
:
pk
=
old_nic
.
network
.
pk
# Get the cached Network or get it from DB
if
pk
in
networks
:
net
=
networks
[
pk
]
else
:
# Get the network object in exclusive mode in order
# to guarantee consistency of the address pool
net
=
Network
.
objects
.
select_for_update
().
get
(
pk
=
pk
)
net
.
release_address
(
old_nic
.
ipv4
)
old_nic
.
delete
()
# Release the ips of the old nics. Get back the networks as multiple
# changes in the same network, must happen in the same Network object,
# because transaction will be commited only on exit of the function.
networks
=
release_instance_nics
(
vm
)
new_nics
=
enumerate
(
nics
)
for
i
,
new_nic
in
new_nics
:
network
=
new_nic
.
get
(
'
network
'
,
''
)
n
=
str
(
network
)
...
...
@@ -169,6 +159,24 @@ def process_net_status(vm, etime, nics):
vm
.
save
()
def
release_instance_nics
(
vm
):
networks
=
{}
for
nic
in
vm
.
nics
.
all
():
pk
=
nic
.
network
.
pk
# Get the cached Network or get it from DB
if
pk
in
networks
:
net
=
networks
[
pk
]
else
:
# Get the network object in exclusive mode in order
# to guarantee consistency of the address pool
net
=
Network
.
objects
.
select_for_update
().
get
(
pk
=
pk
)
net
.
release_address
(
nic
.
ipv4
)
nic
.
delete
()
return
networks
@transaction.commit_on_success
def
process_network_status
(
back_network
,
etime
,
jobid
,
opcode
,
status
,
logmsg
):
if
status
not
in
[
x
[
0
]
for
x
in
BACKEND_STATUSES
]:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment