Skip to content

Instantly share code, notes, and snippets.

@kevinhillinger
Last active November 13, 2023 00:12
Show Gist options
  • Save kevinhillinger/6432ee4d0f6274e76d5e9aed53013e22 to your computer and use it in GitHub Desktop.
Save kevinhillinger/6432ee4d0f6274e76d5e9aed53013e22 to your computer and use it in GitHub Desktop.
Azure Python SDK - Networking - Network Interface - updating nic
import os
from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.network import NetworkManagementClient
subscription_id = os.environ.get(
'AZURE_SUBSCRIPTION_ID',
'11111111-1111-1111-1111-111111111111') # your Azure Subscription Id
credentials = ServicePrincipalCredentials(
client_id=os.environ['AZURE_CLIENT_ID'],
secret=os.environ['AZURE_CLIENT_SECRET'],
tenant=os.environ['AZURE_TENANT_ID']
)
network_client = NetworkManagementClient(credentials, subscription_id)
# Info can be found here https://github.com/Azure/azure-sdk-for-python/blob/master/azure-mgmt-network/azure/mgmt/network/v2017_06_01/models/network_interface.py
def modify_nic(nic):
#make changes to <azure.mgmt.network.v2017_06_01.models.NetworkInterface> type
return nic
# Get interface card
resource_group_name = "[resource group name]"
nic_name ="[name of the nic]"
nic = network_client.network_interfaces.get(resource_group_name, nic_name)
if nic:
modify_nic(nic)
async_nic_update = network_client.network_interfaces.create_or_update(
resource_group_name,
nic_name,
nic
)
nic_info = async_nic_update.result()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment