Azure / azure-sdk-for-rust

This repository is for the active development of the Azure SDK for Rust. For consumers of the SDK we recommend visiting Docs.rs and looking up the docs for any of libraries in the SDK.
MIT License
710 stars 246 forks source link

azure_mgmt_compute: network_interface_configurations is empty, this is proper in python #1686

Open huskercane opened 4 months ago

huskercane commented 4 months ago

Hello

following code does not work

/*
prints information about network addresses used for each Azure Service

$ cargo run --release --example list_network_configuration <resource_group> <vm_name>
$

*/

use azure_identity::AzureCliCredential;
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let resource_group_name = std::env::args().nth(1).expect("please specify resource group name");
    let vm_name = std::env::args().nth(2).expect("please specify vm group name");

    let credential = Arc::new(AzureCliCredential::new());
    let subscription_id = AzureCliCredential::get_subscription().await?;
    let compute_client = azure_mgmt_compute::Client::builder(credential.clone()).build()?;

    // Get the VM
    let vm = compute_client.virtual_machines_client().get(resource_group_name, vm_name, subscription_id).await?;

    // Get the VM
    let properties = vm.properties.unwrap();
    let profile = properties.network_profile.unwrap();
    let vec1 = profile.network_interface_configurations;
    let interface_name = vec1.first().unwrap().name.clone();
    println!("Name for first NetworkInterface Configuration is {:?}", interface_name);

    Ok(())
}

it fails because network_interface_configurations returns a empty vector

Equivalent code does work on Python SDK

>>> from azure.identity import DefaultAzureCredential
>>> from azure.mgmt.compute import ComputeManagementClient
>>> credentials = DefaultAzureCredential()
>>> compute_client = ComputeManagementClient(credentials, subscription_id)
>>> vm = compute_client.virtual_machines.get(resource_group, vm_name)
>>> 
>>> nics = vm.network_profile.network_interfaces
>>> nic = nics[0]
>>> nic.id
'/subscriptions/9XXX-XXX-XXX-XXX-XXXXe/resourceGroups/XXXXXXXXXX/providers/Microsoft.Network/networkInterfaces/xxxxYYYY_z1'
>>> 

Thank You

huskercane commented 4 months ago

I think I have to network_interfaces instead of network_interface_configurations

Here is the updated example

/*
prints information about network addresses used for each Azure Service

$ cargo run --release --example list_network_configuration <resource_group> <vm_name>
$

*/

use azure_identity::AzureCliCredential;
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let resource_group_name = std::env::args().nth(1).expect("please specify resource group name");
    let vm_name = std::env::args().nth(2).expect("please specify vm group name");

    let credential = Arc::new(AzureCliCredential::new());
    let subscription_id = AzureCliCredential::get_subscription().await?;
    let compute_client = azure_mgmt_compute::Client::builder(credential.clone()).build()?;

    // Get the VM
    let vm = compute_client.virtual_machines_client().get(resource_group_name, vm_name, subscription_id).await?;

    let interface_name = vm.properties.unwrap().network_profile.unwrap().network_interfaces[0].clone().id.unwrap();

    let last_part = interface_name.split('/').last().unwrap_or("");
    println!("Interface Name is: {}", last_part);

    Ok(())
}

id property does not exist for NetworkInterfaceReference

so we need this patch

Index: services/mgmt/compute/src/package_2023_10_02/models.rs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/services/mgmt/compute/src/package_2023_10_02/models.rs b/services/mgmt/compute/src/package_2023_10_02/models.rs
--- a/services/mgmt/compute/src/package_2023_10_02/models.rs    (revision 8c4caa251c3903d5eae848b41bb1d02a4d65231c)
+++ b/services/mgmt/compute/src/package_2023_10_02/models.rs    (date 1719279566813)
@@ -7095,6 +7095,9 @@
 #[doc = "Describes a network interface reference."]
 #[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Default)]
 pub struct NetworkInterfaceReference {
+    #[doc = "Resource Id."]
+    #[serde(default, skip_serializing_if = "Option::is_none")]
+    pub id: Option<String>,
     #[serde(flatten)]
     pub sub_resource: SubResource,
     #[doc = "Describes a network interface reference properties."]