diff options
Diffstat (limited to 'src/booking')
-rw-r--r-- | src/booking/forms.py | 14 | ||||
-rw-r--r-- | src/booking/quick_deployer.py | 33 |
2 files changed, 25 insertions, 22 deletions
diff --git a/src/booking/forms.py b/src/booking/forms.py index 7ba5af0..9349ac1 100644 --- a/src/booking/forms.py +++ b/src/booking/forms.py @@ -8,7 +8,6 @@ ############################################################################## import django.forms as forms from django.forms.widgets import NumberInput -from django.db.models import Q from workflow.forms import ( SearchableSelectMultipleWidget, @@ -22,7 +21,6 @@ from resource_inventory.models import Image, Installer, Scenario class QuickBookingForm(forms.Form): purpose = forms.CharField(max_length=1000) project = forms.CharField(max_length=400) - image = forms.ModelChoiceField(queryset=Image.objects.all()) hostname = forms.CharField(max_length=400) installer = forms.ModelChoiceField(queryset=Installer.objects.all(), required=False) @@ -40,14 +38,14 @@ class QuickBookingForm(forms.Form): elif data and "users" in data: chosen_users = data.getlist("users") - if user: - self.image = forms.ModelChoiceField(queryset=Image.objects.filter( - Q(public=True) | Q(owner=user)), required=False) - else: - self.image = forms.ModelChoiceField(queryset=Image.objects.all(), required=False) - super(QuickBookingForm, self).__init__(data=data, **kwargs) + self.fields["image"] = forms.ModelChoiceField( + queryset=Image.objects.difference( + Image.objects.filter(public=False).difference(Image.objects.filter(owner=user)) + ) + ) + self.fields['users'] = forms.CharField( widget=SearchableSelectMultipleWidget( attrs=self.build_search_widget_attrs(chosen_users, default_user=default_user) diff --git a/src/booking/quick_deployer.py b/src/booking/quick_deployer.py index 7059313..640ded9 100644 --- a/src/booking/quick_deployer.py +++ b/src/booking/quick_deployer.py @@ -22,7 +22,6 @@ from resource_inventory.models import ( Image, GenericResourceBundle, ConfigBundle, - Vlan, Host, HostProfile, HostConfiguration, @@ -30,7 +29,10 @@ from resource_inventory.models import ( GenericHost, GenericInterface, OPNFVRole, - OPNFVConfig + OPNFVConfig, + Network, + NetworkConnection, + NetworkRole ) from resource_inventory.resource_manager import ResourceManager from resource_inventory.pdf_templater import PDFTemplater @@ -230,6 +232,20 @@ def check_invariants(request, **kwargs): raise BookingLengthException("Booking must be between 1 and 21 days long") +def configure_networking(grb, config): + # create network + net = Network.objects.create(name="public", bundle=grb, is_public=True) + # connect network to generic host + grb.getHosts()[0].generic_interfaces.first().connections.add( + NetworkConnection.objects.create(network=net, vlan_is_tagged=False) + ) + # asign network role + role = NetworkRole.objects.create(name="public", network=net) + opnfv_config = config.opnfv_config.first() + if opnfv_config: + opnfv_config.networks.add(role) + + def create_from_form(form, request): quick_booking_id = str(uuid.uuid4()) @@ -275,18 +291,7 @@ def create_from_form(form, request): generic_interface = GenericInterface.objects.create(profile=interface_profile, host=ghost) generic_interface.save() - # get vlan, assign to first interface - publicnetwork = lab.vlan_manager.get_public_vlan() - if not publicnetwork: - raise NoRemainingPublicNetwork("No public networks were available for your pod") - publicvlan = publicnetwork.vlan - lab.vlan_manager.reserve_public_vlan(publicvlan) - - vlan = Vlan.objects.create(vlan_id=publicvlan, tagged=False, public=True) - vlan.save() - - ghost.generic_interfaces.first().vlans.add(vlan) - ghost.generic_interfaces.first().save() + configure_networking(grbundle, cbundle) # generate resource bundle resource_bundle = generate_resource_bundle(grbundle, cbundle) |