Share via


VMSubnets Collection [SPFSDK][VMMREF]

 

Applies To: Windows Azure Pack

The VMSubnets collection gets, creates, updates, or deletes virtual subnets for Virtual Machine Manager (VMM).

For more information about the placeholders used in the URI, see URL placeholders.

Namespace

OData Collection URI

VMM

https://{server-name}:{auth-port}/{subscription-id}/services/systemcenter/vmm/VMSubnets

Supported HTTP Verbs

Create (POST)

Read (GET)

Update (PUT)

Delete (DELETE)

True

True

False

True

Operations

Examples

Each of the four operation topics linked above contain basic code examples.

The following example demonstrates how to delete a subnet, and any related static IP address pools.

  1. Search for the VMSubnet [SPFSDK][VMMREF] that you want to delete.

  2. Get all of the StaticIPAddressPool [SPFSDK][VMMREF] objects associated with the VMSubnet.

  3. Flag each StaticIPAddressPool object for deletion by passing it to the DeleteObject method.

  4. Flag the VMSubnet for deletion by passing it to the DeleteObject method.

  5. Call the SaveChanges method to send all deletion requests to the server.

Guid stampId = new Guid("56ebc6dc-f63c-46e2-8438-2967e0ad83bc");
Guid networkId = new Guid("42deec47-f225-4377-855c-b9553056fe60");

// Find subnets of the network we want to clear.
var subnets = vmmService.VMSubnets.Where(v => v.StampId == stampId && v.VMNetworkId == networkId).ToList();
if (subnets.Count != 0)
{
    foreach (var subnetObj in subnets)
    {
        // Get the static IP address pools associated with the network.
        var ipPools = vmmService.StaticIPAddressPools.Where(v => v.StampId == stampId && v.VMSubnetId == subnetObj.ID).ToList();
        if (ipPools.Count != 0)
        {
            // Flag each ip pool to be deleted.
            ipPools.ForEach(s => vmmService.DeleteObject(s));
        }

        // Flag the subnet to be deleted.
        vmmService.DeleteObject(subnetObj);

        // Commit the delete operations.
        vmmService.SaveChanges();
    }
}

See Also

Resource Collections
StaticIPAddressPools Collection [SPFSDK][VMMREF]