Commit 1616b560 by Szabolcs Gelencser

Add default subnet pool creation on login

parent 1e204ec1
...@@ -572,3 +572,8 @@ POLICY_DIRS = { ...@@ -572,3 +572,8 @@ POLICY_DIRS = {
DEFAULT_USERNET_VLAN_NAME = ( DEFAULT_USERNET_VLAN_NAME = (
get_env_variable("DEFAULT_USERNET_VLAN_NAME", "usernet")) get_env_variable("DEFAULT_USERNET_VLAN_NAME", "usernet"))
USERNET_MAX = 2 ** 12 USERNET_MAX = 2 ** 12
DEFAULT_SUBNETPOOL_NAME_FOR_USER = "default"
DEFAULT_SUBNETPOOL_PREFIXES = (
"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"
)
\ No newline at end of file
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with CIRCLE. If not, see <http://www.gnu.org/licenses/>. # with CIRCLE. If not, see <http://www.gnu.org/licenses/>.
import openstack_api import openstack_api
from django.conf import settings
from django.contrib.auth import user_logged_in
from django.db import models from django.db import models
from django.core.validators import MinValueValidator, MaxValueValidator from django.core.validators import MinValueValidator, MaxValueValidator
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
...@@ -77,3 +79,15 @@ class Vxlan(models.Model): ...@@ -77,3 +79,15 @@ class Vxlan(models.Model):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('network.vxlan', kwargs={'vni': self.vni}) return reverse('network.vxlan', kwargs={'vni': self.vni})
def create_subnet_pool(sender, user, request, **kwargs):
subnet_pools = openstack_api.neutron.subnetpool_list(request)
subnet_pools = [sp for sp in subnet_pools if sp.name == settings.DEFAULT_SUBNETPOOL_NAME_FOR_USER]
if(len(subnet_pools) == 0):
openstack_api.neutron.subnetpool_create(
request,
settings.DEFAULT_SUBNETPOOL_NAME_FOR_USER,
settings.DEFAULT_SUBNETPOOL_PREFIXES,
)
user_logged_in.connect(create_subnet_pool)
\ No newline at end of file
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 sign in to comment