Source code for idem_azure.exec.azure.network.subnets
"""Exec module for managing subnets."""fromcollectionsimportOrderedDictfromtypingimportAnyfromtypingimportDict__func_alias__={"list_":"list"}
[docs]asyncdefget(hub,ctx,resource_id:str,name:str=None,raw:bool=False)->Dict[str,Any]:"""Get subnet resource from resource_id. Args: resource_id(str): The resource_id of subnet name(str, Optional): The name of the resource raw(bool, Optional): Returns raw response if True. Defaults to False Returns: Dict[str, Any] Examples: Calling this exec module function from the cli with resource_id: .. code-block:: bash idem exec azure.network.subnets.get resource_id="value" raw="False" Using in a state: .. code-block:: yaml my_unmanaged_resource: exec.run: - path: azure.network.subnets.get - kwargs: resource_id: "/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Network/virtualNetworks/{virtual_network_name}/subnets/{subnet_name}" raw: False """result=dict(comment=[],result=True,ret=None)uri_parameters=OrderedDict({"subscriptions":"subscription_id","resourceGroups":"resource_group_name","virtualNetworks":"virtual_network_name","subnets":"subnet_name",})response_get=awaithub.exec.request.json.get(ctx,url=f"{ctx.acct.endpoint_url}{resource_id}?api-version=2021-06-01",success_codes=[200,201],)ifnotresponse_get["result"]:ifresponse_get["status"]!=404:result["result"]=Falseresult["comment"].extend(hub.tool.azure.result_utils.extract_error_comments(response_get))returnresulturi_parameter_values=hub.tool.azure.uri.get_parameter_value_in_dict(resource_id,uri_parameters)ifraw:result["ret"]=response_get["ret"]else:result["ret"]=hub.tool.azure.network.subnets.convert_raw_subnets_to_present(resource=response_get["ret"],idem_resource_name=resource_id,resource_id=resource_id,**uri_parameter_values,)returnresult
[docs]asyncdeflist_(hub,ctx)->Dict:"""List of subnets Returns: Dict[str, Any] Examples: Calling this exec module function from the cli with resource_id: .. code-block:: bash idem exec azure.network.subnets.list Using in a state: .. code-block:: yaml my_unmanaged_resource: exec.run: - path: azure.network.subnets.list """result=dict(comment=[],result=True,ret=[])subscription_id=ctx.acct.subscription_iduri_parameters=OrderedDict({"resourceGroups":"resource_group_name","virtualNetworks":"virtual_network_name","subnets":"subnet_name",})asyncforpage_resultinhub.tool.azure.request.paginate(ctx,url=f"{ctx.acct.endpoint_url}/subscriptions/{subscription_id}"f"/providers/Microsoft.Network/virtualNetworks?api-version=2021-03-01",success_codes=[200],):resource_list=page_result.get("value")ifresource_list:forvnetinresource_list:ifvnet.get("properties")andvnet.get("properties").get("subnets"):subnet_list=vnet["properties"]["subnets"]forresourceinsubnet_list:resource_id=resource["id"]uri_parameter_values=(hub.tool.azure.uri.get_parameter_value_in_dict(resource_id,uri_parameters))result["ret"].append(hub.tool.azure.network.subnets.convert_raw_subnets_to_present(resource=resource,idem_resource_name=resource_id,subscription_id=subscription_id,resource_id=resource_id,**uri_parameter_values,))returnresult