Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
362e8c15
Commit
362e8c15
authored
Jun 11, 2013
by
Christos Stavrakakis
Browse files
cyclades: Various fixes regarding floating IPs
Fix some issues regarding floating ips introduced by rebasing branch.
parent
ab65a62f
Changes
7
Hide whitespace changes
Inline
Side-by-side
snf-cyclades-app/synnefo/api/floating_ips.py
View file @
362e8c15
...
...
@@ -143,7 +143,7 @@ def allocate_floating_ip(request):
deleted
=
False
,
floating_ip_pool
=
True
)
except
IndexError
:
except
Network
.
DoesNotExist
:
raise
faults
.
ItemNotFound
(
"Pool '%s' does not exist."
%
pool
)
if
address
is
None
:
# User did not specified an IP address. Choose a random one
...
...
snf-cyclades-app/synnefo/api/servers.py
View file @
362e8c15
...
...
@@ -827,7 +827,7 @@ def remove(request, net, args):
return
HttpResponse
(
status
=
202
)
@
server_action
(
"add
f
loating
i
p"
)
@
server_action
(
"add
F
loating
I
p"
)
def
add_floating_ip
(
request
,
vm
,
args
):
address
=
args
.
get
(
"address"
)
if
address
is
None
:
...
...
@@ -837,7 +837,7 @@ def add_floating_ip(request, vm, args):
return
HttpResponse
(
status
=
202
)
@
server_action
(
"remove
f
loating
i
p"
)
@
server_action
(
"remove
F
loating
I
p"
)
def
remove_floating_ip
(
request
,
vm
,
args
):
address
=
args
.
get
(
"address"
)
if
address
is
None
:
...
...
snf-cyclades-app/synnefo/api/test/floating_ips.py
View file @
362e8c15
...
...
@@ -287,6 +287,7 @@ class FloatingIPActionsTest(BaseAPITest):
BackendNetworkFactory
(
network
=
ip1
.
network
,
backend
=
self
.
vm
.
backend
,
operstate
=
'ACTIVE'
)
request
=
{
"addFloatingIp"
:
{
"address"
:
ip1
.
ipv4
}}
mock
().
ModifyInstance
.
return_value
=
1
response
=
self
.
post
(
url
,
self
.
vm
.
userid
,
json
.
dumps
(
request
),
"json"
)
self
.
assertEqual
(
response
.
status_code
,
202
)
ip1_after
=
FloatingIP
.
objects
.
get
(
id
=
ip1
.
id
)
...
...
@@ -309,6 +310,7 @@ class FloatingIPActionsTest(BaseAPITest):
ip1
=
FloatingIPFactory
(
userid
=
self
.
vm
.
userid
,
machine
=
self
.
vm
)
NetworkInterfaceFactory
(
machine
=
self
.
vm
,
ipv4
=
ip1
.
ipv4
)
request
=
{
"removeFloatingIp"
:
{
"address"
:
ip1
.
ipv4
}}
mock
().
ModifyInstance
.
return_value
=
2
response
=
self
.
post
(
url
,
self
.
vm
.
userid
,
json
.
dumps
(
request
),
"json"
)
self
.
assertEqual
(
response
.
status_code
,
202
)
# Yet used. Wait for the callbacks
...
...
snf-cyclades-app/synnefo/api/test/servers.py
View file @
362e8c15
...
...
@@ -296,7 +296,7 @@ class ServerCreateAPITest(ComputeAPITest):
self
.
network
.
save
()
with
mocked_quotaholder
():
response
=
self
.
mypost
(
'servers'
,
'test_user'
,
json
.
dumps
(
self
.
request
),
'json'
)
json
.
dumps
(
self
.
request
),
'json'
)
self
.
assertEqual
(
response
.
status_code
,
503
,
"serviceUnavailable"
)
def
test_create_network_settings
(
self
,
mrapi
):
...
...
snf-cyclades-app/synnefo/api/util.py
View file @
362e8c15
...
...
@@ -59,7 +59,8 @@ from django.db.models import Q
from
snf_django.lib.api
import
faults
from
synnefo.db.models
import
(
Flavor
,
VirtualMachine
,
VirtualMachineMetadata
,
Network
,
BackendNetwork
,
NetworkInterface
,
BridgePoolTable
,
MacPrefixPoolTable
,
Backend
)
BridgePoolTable
,
MacPrefixPoolTable
,
Backend
,
FloatingIP
)
from
synnefo.db.pools
import
EmptyPool
from
snf_django.lib.astakos
import
get_user
...
...
@@ -224,12 +225,22 @@ def get_network(network_id, user_id, for_update=False, non_deleted=False):
network
=
objects
.
get
(
Q
(
userid
=
user_id
)
|
Q
(
public
=
True
),
id
=
network_id
)
if
non_deleted
and
network
.
deleted
:
raise
faults
.
BadRequest
(
"Networkhas been deleted."
)
raise
faults
.
BadRequest
(
"Network
has been deleted."
)
return
network
except
(
ValueError
,
Network
.
DoesNotExist
):
raise
faults
.
ItemNotFound
(
'Network not found.'
)
def
get_floating_ip
(
user_id
,
ipv4
,
for_update
=
False
):
try
:
objects
=
FloatingIP
.
objects
if
for_update
:
objects
=
objects
.
select_for_update
()
return
objects
.
get
(
userid
=
user_id
,
ipv4
=
ipv4
,
deleted
=
False
)
except
FloatingIP
.
DoesNotExist
:
raise
faults
.
ItemNotFound
(
"Floating IP does not exist."
)
def
validate_network_params
(
subnet
,
gateway
=
None
,
subnet6
=
None
,
gateway6
=
None
):
try
:
# Use strict option to not all subnets with host bits set
...
...
snf-cyclades-app/synnefo/logic/backend.py
View file @
362e8c15
...
...
@@ -295,7 +295,7 @@ def nics_changed(old_nics, new_nics):
def
release_instance_ips
(
vm
,
ganeti_nics
):
old_addresses
=
set
(
vm
.
nics
.
values_list
(
"network"
,
"ipv4"
))
new_addresses
=
set
(
map
(
lambda
nic
:
(
nic
[
"network"
],
nic
[
"ipv4"
]),
new_addresses
=
set
(
map
(
lambda
nic
:
(
nic
[
"network"
]
.
id
,
nic
[
"ipv4"
]),
ganeti_nics
))
to_release
=
old_addresses
-
new_addresses
for
(
network_id
,
ipv4
)
in
to_release
:
...
...
snf-cyclades-app/synnefo/logic/servers.py
View file @
362e8c15
...
...
@@ -202,7 +202,7 @@ def create(userid, name, password, flavor, image, metadata={},
vm
.
task_job_id
=
jobID
vm
.
save
()
transaction
.
commit
()
log
.
info
(
"User %s created VM %s, NIC %s, Backend %s, JobID %s"
,
log
.
info
(
"User %s created VM %s, NIC
s
%s, Backend %s, JobID %s"
,
userid
,
vm
,
nics
,
backend
,
str
(
jobID
))
except
GanetiApiError
as
e
:
log
.
exception
(
"Can not communicate to backend %s: %s."
,
...
...
@@ -249,9 +249,7 @@ def create_instance_nics(vm, userid, private_networks=[], floating_ips=[]):
address
=
util
.
get_network_free_address
(
network
)
attachments
.
append
((
network
,
address
))
for
address
in
floating_ips
:
floating_ip
=
add_floating_ip_to_vm
(
address
=
address
,
user_id
=
userid
,
vm
=
vm
)
floating_ip
=
add_floating_ip_to_vm
(
vm
=
vm
,
address
=
address
)
network
=
floating_ip
.
network
attachments
.
append
((
network
,
address
))
for
network_id
in
private_networks
:
...
...
@@ -423,7 +421,7 @@ def console(vm, console_type):
return
console
@
server_command
(
"CONNECT
ING
"
)
@
server_command
(
"CONNECT"
)
def
add_floating_ip
(
vm
,
address
):
floating_ip
=
add_floating_ip_to_vm
(
vm
,
address
)
log
.
info
(
"Connecting VM %s to floating IP %s"
,
vm
,
floating_ip
)
...
...
@@ -464,7 +462,7 @@ def add_floating_ip_to_vm(vm, address):
return
floating_ip
@
server_command
(
"DISCONNECT
ING
"
)
@
server_command
(
"DISCONNECT"
)
def
remove_floating_ip
(
vm
,
address
):
user_id
=
vm
.
userid
try
:
...
...
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