mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-17 12:28:07 +00:00
Delete NSG if no resources associated with it (#1358)
Co-authored-by: stas <statis@microsoft.com>
This commit is contained in:
@ -5,7 +5,7 @@
|
||||
|
||||
import logging
|
||||
import os
|
||||
from typing import Dict, List, Optional, Union, cast
|
||||
from typing import Dict, List, Optional, Set, Union, cast
|
||||
|
||||
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
|
||||
from azure.mgmt.network.models import (
|
||||
@ -72,6 +72,12 @@ def create_nsg(name: str, location: Region) -> Union[None, Error]:
|
||||
return None
|
||||
|
||||
|
||||
def list_nsgs() -> List[NetworkSecurityGroup]:
|
||||
resource_group = get_base_resource_group()
|
||||
network_client = get_network_client()
|
||||
return list(network_client.network_security_groups.list(resource_group))
|
||||
|
||||
|
||||
def update_nsg(nsg: NetworkSecurityGroup) -> Union[None, Error]:
|
||||
resource_group = get_base_resource_group()
|
||||
|
||||
@ -95,6 +101,10 @@ def update_nsg(nsg: NetworkSecurityGroup) -> Union[None, Error]:
|
||||
return None
|
||||
|
||||
|
||||
def ok_to_delete(active_regions: Set[Region], nsg_region: str, nsg_name: str) -> bool:
|
||||
return nsg_region not in active_regions and nsg_region == nsg_name
|
||||
|
||||
|
||||
def delete_nsg(name: str) -> bool:
|
||||
# NSG can be only deleted if no other resource is associated with it
|
||||
resource_group = get_base_resource_group()
|
||||
|
Reference in New Issue
Block a user