Commit f7557707 authored by Christos Stavrakakis's avatar Christos Stavrakakis

cyclades: Remove PUBLIC_USE_POOL setting

Remove PUBLIC_USE_POOL setting, since in order to use floating IPs, the
cyclades must be responsible for managing all IP pools.
parent 31d9b58d
......@@ -6,6 +6,21 @@ Unified Changelog file for Synnefo versions >= 0.13
Since v0.13 most of the Synnefo components have been merged into a single
repository and have aligned versions.
.. _Changelog-0.14next:
v0.14next
=========
Released: UNRELEASED
Cyclades
--------
* Obsolete PUBLIC_USE_POOL setting, since Cyclades manages IP pool for all
type of networks.
Synnefo-wide
------------
.. _Changelog-0.14:
......
......@@ -42,7 +42,6 @@ In `/etc/synnefo/cyclades.conf` add:
.. code-block:: console
MAX_CIDR_BLOCK = 21
PUBLIC_USE_POOL = True
CPU_BAR_GRAPH_URL = 'https://cyclades.example.com/stats/%s/cpu-bar.png'
CPU_TIMESERIES_GRAPH_URL = 'https://cyclades.example.com/stats/%s/cpu-ts.png'
......
......@@ -24,12 +24,6 @@
#DEFAULT_MAC_PREFIX = 'aa:00:0'
#DEFAULT_BRIDGE = 'br0'
#
## Boolean value indicating whether synnefo would hold a Pool and allocate IP
## addresses. If this setting is set to False, IP pool management will be
## delegated to Ganeti. If machines have been created with this option as False,
## you must run network reconciliation after turning it to True.
#PUBLIC_USE_POOL = True
#
## Network flavors that users are allowed to create through API requests
#API_ENABLED_NETWORK_FLAVORS = ['MAC_FILTERED']
#
......
......@@ -135,7 +135,7 @@ def allocate_floating_ip(request):
try:
if pool is None:
# User did not specified a pool. Choose a random public IP
network, address = util.allocate_public_ip(net_objects)
network, address = util.get_free_ip(net_objects)
else:
try:
network = Network.objects.select_for_update()\
......
......@@ -146,10 +146,10 @@ def import_server(instance_name, backend_id, flavor_id, image_id, user_id,
if new_public_nic:
remove_instance_nics(instance, backend_client,
stream=stream)
(network, address) = allocate_public_address(backend)
if address is None:
raise CommandError("Can not allocate a public address."
" No available public network.")
try:
(network, address) = allocate_public_address(backend)
except Exception as e:
raise CommandError(e)
nic = {'ip': address, 'network': network.backend_id}
add_public_nic(instance_name, nic, backend_client,
stream=stream)
......
......@@ -284,44 +284,13 @@ def validate_network_size(cidr_block):
def allocate_public_address(backend):
"""Allocate a public IP for a vm."""
for network in backend_public_networks(backend):
try:
address = get_network_free_address(network)
except faults.OverLimit:
pass
else:
return (network, address)
return (None, None)
def get_public_ip(backend):
"""Reserve an IP from a public network.
This method should run inside a transaction.
"""
"""Get a public IP for any available network of a backend."""
# Guarantee exclusive access to backend, because accessing the IP pools of
# the backend networks may result in a deadlock with backend allocator
# which also checks that backend networks have a free IP.
backend = Backend.objects.select_for_update().get(id=backend.id)
address = None
if settings.PUBLIC_USE_POOL:
(network, address) = allocate_public_address(backend)
else:
for net in list(backend_public_networks(backend)):
pool = net.get_pool()
if not pool.empty():
address = 'pool'
network = net
break
if address is None:
log.error("Public networks of backend %s are full", backend)
raise faults.OverLimit("Can not allocate IP for new machine."
" Public networks are full.")
return (network, address)
public_networks = backend_public_networks(backend)
return get_free_ip(public_networks)
def backend_public_networks(backend):
......@@ -331,11 +300,23 @@ def backend_public_networks(backend):
to the specified backend.
"""
for network in Network.objects.filter(public=True, deleted=False,
drained=False):
if BackendNetwork.objects.filter(network=network,
backend=backend).exists():
yield network
bnets = BackendNetwork.objects.filter(backend=backend,
network__public=True,
network__deleted=False,
network__drained=False)
return [b.network for b in bnets]
def get_free_ip(networks):
for network in networks:
try:
address = get_network_free_address(network)
return network, address
except faults.OverLimit:
pass
msg = "Can not allocate public IP. Public networks are full."
log.error(msg)
raise faults.OverLimit(msg)
def get_network_free_address(network):
......@@ -346,28 +327,10 @@ def get_network_free_address(network):
address = pool.get()
except EmptyPool:
raise faults.OverLimit("Network %s is full." % network.backend_id)
address = None
pool.save()
return address
def allocate_public_ip(networks=None):
"""Allocate an IP address from public networks."""
if networks is None:
networks = Network.objects.select_for_update().filter(public=True,
deleted=False)
for network in networks:
try:
address = get_network_free_address(network)
except:
pass
else:
return network, address
msg = "Can not allocate public IP. Public networks are full."
log.error(msg)
raise faults.OverLimit(msg)
def get_nic(machine, network):
try:
return NetworkInterface.objects.get(machine=machine, network=network)
......
......@@ -24,12 +24,6 @@ MAX_CIDR_BLOCK = 22
DEFAULT_MAC_PREFIX = 'aa:00:0'
DEFAULT_BRIDGE = 'br0'
# Boolean value indicating whether synnefo would hold a Pool and allocate IP
# addresses. If this setting is set to False, IP pool management will be
# delegated to Ganeti. If machines have been created with this option as False,
# you must run network reconciliation after turning it to True.
PUBLIC_USE_POOL = True
# Network flavors that users are allowed to create through API requests
API_ENABLED_NETWORK_FLAVORS = ['MAC_FILTERED']
......
......@@ -40,7 +40,6 @@ import bitarray
from optparse import make_option
from synnefo.settings import PUBLIC_USE_POOL
from django.core.management.base import BaseCommand
from django.db import transaction
......@@ -105,7 +104,6 @@ def reconcile_networks(conflicting_ips=False):
for network in networks:
ip_available_maps = []
ip_reserved_maps = []
uses_pool = not network.public or PUBLIC_USE_POOL
for bend in backends:
bnet = get_backend_network(network, bend)
gnet = ganeti_networks[bend].get(network.id)
......@@ -150,13 +148,12 @@ def reconcile_networks(conflicting_ips=False):
# exists and is connected to all nodes so is must be active!
reconcile_unsynced_network(network, bend, bnet)
if uses_pool:
# Get ganeti IP Pools
available_map, reserved_map = get_network_pool(gnet)
ip_available_maps.append(available_map)
ip_reserved_maps.append(reserved_map)
# Get ganeti IP Pools
available_map, reserved_map = get_network_pool(gnet)
ip_available_maps.append(available_map)
ip_reserved_maps.append(reserved_map)
if uses_pool and (ip_available_maps or ip_reserved_maps):
if ip_available_maps or ip_reserved_maps:
# CASE-5: Unsynced IP Pools
reconcile_ip_pools(network, ip_available_maps, ip_reserved_maps)
......
......@@ -235,7 +235,7 @@ def create_instance_nics(vm, userid, private_networks=[], floating_ips=[]):
for network_id in settings.DEFAULT_INSTANCE_NETWORKS:
network, address = None, None
if network_id == "public":
network, address = util.get_public_ip(backend=vm.backend)
network, address = util.allocate_public_address(backend=vm.backend)
else:
try:
network = Network.objects.get(id=network_id, deleted=False)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment