diff --git a/frontend/website/ghpcfe/forms.py b/frontend/website/ghpcfe/forms.py index 9adca30d44..20d6702ee9 100644 --- a/frontend/website/ghpcfe/forms.py +++ b/frontend/website/ghpcfe/forms.py @@ -16,6 +16,7 @@ from django import forms from django.forms import ValidationError, modelformset_factory, inlineformset_factory +from django.db.models import Q from django.contrib.auth.forms import UserCreationForm, UserChangeForm from django.utils.safestring import mark_safe from .cluster_manager import validate_credential, cloud_info @@ -100,7 +101,7 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) credential = self._get_creds(kwargs) - self.fields['subnet'].queryset = VirtualSubnet.objects.filter(cloud_credential=credential) + self.fields['subnet'].queryset = VirtualSubnet.objects.filter(cloud_credential=credential).filter(Q(cloud_state="i")|Q(cloud_state="m")) if zone_choices: # We set this on the widget, because we will be changing the # widget's field in the template via javascript @@ -183,7 +184,7 @@ def __init__(self, user, *args, **kwargs): super().__init__(*args, **kwargs) if not has_creds: credential = self.instance.cloud_credential - self.fields['subnet'].queryset = VirtualSubnet.objects.filter(cloud_credential=credential) + self.fields['subnet'].queryset = VirtualSubnet.objects.filter(cloud_credential=credential).filter(Q(cloud_state="i")|Q(cloud_state="m")) self.workbench_zones = cloud_info.get_gcp_workbench_region_zone_info(credential.detail) if 'n' not in self.instance.cloud_state: #Need to disable certain widgets @@ -457,7 +458,7 @@ def __init__(self, *args, **kwargs): creds = self._get_creds(kwargs) - self.fields['subnet'].queryset = VirtualSubnet.objects.filter(cloud_credential=creds) + self.fields['subnet'].queryset = VirtualSubnet.objects.filter(cloud_credential=creds).filter(Q(cloud_state="i")|Q(cloud_state="m")) if zone_choices: # We set this on the widget, because we will be changing the # widget's field in the template via javascript diff --git a/frontend/website/ghpcfe/signals.py b/frontend/website/ghpcfe/signals.py index 6a4be33671..817755363c 100644 --- a/frontend/website/ghpcfe/signals.py +++ b/frontend/website/ghpcfe/signals.py @@ -15,8 +15,17 @@ from django.db.models.signals import * from django.dispatch import receiver from .models import Cluster, Filesystem, FilesystemExport, MountPoint +from .models import VirtualNetwork, VirtualSubnet +@receiver(pre_save, sender=VirtualNetwork) +def sync_VN_subnet_state(sender, **kwargs): + vpc = kwargs['instance'] + for sn in vpc.subnets.all(): + sn.cloud_state = vpc.cloud_state + sn.save() + + @receiver(post_delete, sender=Cluster) def delete_cluster_extras(sender, **kwargs): diff --git a/frontend/website/ghpcfe/views/clusters.py b/frontend/website/ghpcfe/views/clusters.py index ce6274e733..7af6b7acfc 100644 --- a/frontend/website/ghpcfe/views/clusters.py +++ b/frontend/website/ghpcfe/views/clusters.py @@ -24,6 +24,7 @@ from rest_framework.response import Response from django.shortcuts import render, redirect, get_object_or_404 from django.db import transaction +from django.db.models import Q from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin from django.contrib.auth.views import redirect_to_login from django.http import HttpResponseRedirect, JsonResponse, \ @@ -188,7 +189,7 @@ def get_context_data(self, **kwargs): """ Perform extra query to populate instance types data """ context = super().get_context_data(**kwargs) region_info = cloud_info.get_region_zone_info("GCP", self.cloud_credential.detail) - subnet_regions = {sn.id: sn.cloud_region for sn in VirtualSubnet.objects.filter(cloud_credential=self.cloud_credential).all()} + subnet_regions = {sn.id: sn.cloud_region for sn in VirtualSubnet.objects.filter(cloud_credential=self.cloud_credential).filter(Q(cloud_state="i") | Q(cloud_state="m")).all()} context['subnet_regions'] = json.dumps(subnet_regions) context['region_info'] = json.dumps(region_info) context['navtab'] = 'cluster' @@ -266,6 +267,7 @@ def get_context_data(self, **kwargs): """ Perform extra query to populate instance types data """ context = super().get_context_data(**kwargs) subnet_regions = {sn.id: sn.cloud_region for sn in VirtualSubnet.objects.filter(cloud_credential=self.get_object().cloud_credential).all()} + subnet_regions = {sn.id: sn.cloud_region for sn in VirtualSubnet.objects.filter(cloud_credential=self.get_object().cloud_credential).filter(Q(cloud_state="i") | Q(cloud_state="m")).all()} context['subnet_regions'] = json.dumps(subnet_regions) context['object'] = self.object context['region_info'] = json.dumps(self._get_region_info()) diff --git a/frontend/website/ghpcfe/views/gcpfilestore.py b/frontend/website/ghpcfe/views/gcpfilestore.py index 2b6c059074..d02fb575d1 100644 --- a/frontend/website/ghpcfe/views/gcpfilestore.py +++ b/frontend/website/ghpcfe/views/gcpfilestore.py @@ -22,6 +22,7 @@ from rest_framework.decorators import action from rest_framework.response import Response from django.shortcuts import render, redirect, get_object_or_404 +from django.db.models import Q from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin from django.contrib.auth.views import redirect_to_login from django.http import HttpResponseRedirect, JsonResponse, \ @@ -79,7 +80,7 @@ def get_form_kwargs(self): def get_context_data(self, **kwargs): """ Perform extra query to populate instance types data """ - subnet_regions = {sn.id: sn.cloud_region for sn in VirtualSubnet.objects.filter(cloud_credential=self.get_object().cloud_credential).all()} + subnet_regions = {sn.id: sn.cloud_region for sn in VirtualSubnet.objects.filter(cloud_credential=self.get_object().cloud_credential).filter(Q(cloud_state="i") | Q(cloud_state="m")).all()} context = super().get_context_data(**kwargs) @@ -99,7 +100,7 @@ def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) self.region_info = cloud_info.get_region_zone_info("GCP", self.cloud_credential.detail) - subnet_regions = {sn.id: sn.cloud_region for sn in VirtualSubnet.objects.filter(cloud_credential=self.cloud_credential).all()} + subnet_regions = {sn.id: sn.cloud_region for sn in VirtualSubnet.objects.filter(cloud_credential=self.cloud_credential).filter(Q(cloud_state="i") | Q(cloud_state="m")).all()} context['subnet_regions'] = json.dumps(subnet_regions) context['region_info'] = json.dumps(self.region_info)