1 ##############################################################################
2 # Copyright (c) 2020 Sawyer Bergeron, Sean Smith, and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 from django.core.exceptions import ValidationError
11 from django import forms
13 from resource_inventory.models import Network, InterfaceConfiguration
16 class InterfaceConfigurationForm(forms.ModelForm):
18 model = InterfaceConfiguration
19 fields = ['profile', 'resource_config', 'connections']
22 connections = self.cleaned_data.get('connections')
23 resource_config = self.cleaned_data.get('resource_config')
25 valid_nets = set(Network.objects.filter(bundle=resource_config.template))
26 curr_nets = set([conn.network for conn in connections])
28 if not curr_nets.issubset(valid_nets):
29 raise ValidationError("Cannot have network connection to network outside pod")
31 return self.cleaned_data