Skip to content

Commit

Permalink
Filter to Imported/Running Subnets
Browse files Browse the repository at this point in the history
  • Loading branch information
Branden Moore committed Mar 8, 2022
1 parent c8aa1df commit 9747d02
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
7 changes: 4 additions & 3 deletions frontend/website/ghpcfe/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions frontend/website/ghpcfe/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion frontend/website/ghpcfe/views/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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())
Expand Down
5 changes: 3 additions & 2 deletions frontend/website/ghpcfe/views/gcpfilestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit 9747d02

Please sign in to comment.