mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-15 11:28:09 +00:00
enable configurable virtual network ranges (#1268)
This commit is contained in:
@ -10,21 +10,23 @@ from typing import Any, Optional, Union, cast
|
||||
from azure.core.exceptions import ResourceNotFoundError
|
||||
from msrestazure.azure_exceptions import CloudError
|
||||
from onefuzztypes.enums import ErrorCode
|
||||
from onefuzztypes.models import Error
|
||||
from onefuzztypes.models import Error, NetworkConfig
|
||||
from onefuzztypes.primitives import Region
|
||||
|
||||
from .network_mgmt_client import get_network_client
|
||||
|
||||
|
||||
def get_subnet_id(resource_group: str, name: str) -> Optional[str]:
|
||||
def get_subnet_id(resource_group: str, name: str, subnet_name: str) -> Optional[str]:
|
||||
network_client = get_network_client()
|
||||
try:
|
||||
subnet = network_client.subnets.get(resource_group, name, name)
|
||||
subnet = network_client.subnets.get(resource_group, name, subnet_name)
|
||||
return cast(str, subnet.id)
|
||||
except (CloudError, ResourceNotFoundError):
|
||||
logging.info(
|
||||
"subnet missing: resource group: %s name: %s",
|
||||
"subnet missing: resource group:%s name:%s subnet_name:%s",
|
||||
resource_group,
|
||||
name,
|
||||
subnet_name,
|
||||
)
|
||||
return None
|
||||
|
||||
@ -43,20 +45,23 @@ def delete_subnet(resource_group: str, name: str) -> Union[None, CloudError, Any
|
||||
|
||||
|
||||
def create_virtual_network(
|
||||
resource_group: str, name: str, location: str
|
||||
resource_group: str,
|
||||
name: str,
|
||||
region: Region,
|
||||
network_config: NetworkConfig,
|
||||
) -> Optional[Error]:
|
||||
logging.info(
|
||||
"creating subnet - resource group: %s name: %s location: %s",
|
||||
"creating subnet - resource group:%s name:%s region:%s",
|
||||
resource_group,
|
||||
name,
|
||||
location,
|
||||
region,
|
||||
)
|
||||
|
||||
network_client = get_network_client()
|
||||
params = {
|
||||
"location": location,
|
||||
"address_space": {"address_prefixes": ["10.0.0.0/8"]},
|
||||
"subnets": [{"name": name, "address_prefix": "10.0.0.0/16"}],
|
||||
"location": region,
|
||||
"address_space": {"address_prefixes": [network_config.address_space]},
|
||||
"subnets": [{"name": name, "address_prefix": network_config.subnet}],
|
||||
}
|
||||
if "ONEFUZZ_OWNER" in os.environ:
|
||||
params["tags"] = {"OWNER": os.environ["ONEFUZZ_OWNER"]}
|
||||
|
Reference in New Issue
Block a user