diff --git a/azure-mgmt-samples/src/main/java/com/microsoft/azure/samples/compute/ListVMsExample.java b/azure-mgmt-samples/src/main/java/com/microsoft/azure/samples/compute/ListVMsExample.java new file mode 100644 index 000000000000..0493772526da --- /dev/null +++ b/azure-mgmt-samples/src/main/java/com/microsoft/azure/samples/compute/ListVMsExample.java @@ -0,0 +1,113 @@ +package com.microsoft.azure.samples.compute; + +import com.microsoft.azure.management.compute.ComputeManagementClient; +import com.microsoft.azure.management.compute.ComputeManagementService; +import com.microsoft.azure.management.compute.models.NetworkInterfaceReference; +import com.microsoft.azure.management.compute.models.VirtualMachine; +import com.microsoft.azure.management.network.NetworkResourceProviderClient; +import com.microsoft.azure.management.network.NetworkResourceProviderService; +import com.microsoft.azure.management.network.models.NetworkInterface; +import com.microsoft.azure.management.network.models.NetworkInterfaceIpConfiguration; +import com.microsoft.azure.management.network.models.PublicIpAddress; +import com.microsoft.azure.management.resources.ResourceManagementClient; +import com.microsoft.azure.management.resources.ResourceManagementService; +import com.microsoft.azure.management.resources.models.ResourceGroupExtended; +import com.microsoft.azure.utility.AuthHelper; +import com.microsoft.windowsazure.Configuration; +import com.microsoft.windowsazure.management.configuration.ManagementConfiguration; + +import java.net.URI; +import java.util.ArrayList; + +/** + * Copyright (c) Microsoft and contributors. All rights reserved. + *
+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + *
+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+public class ListVMsExample {
+
+ /**
+ * List all virtual machines within each resource group in the subscription.
+ * For each VM list all network interfaces (nics) and associated IP addresses.
+ * To use the sample please set following environment variable or simply replace the getenv call
+ * here and in ConfigurationHelper.java with actual values:
+ *
+ management.uri=https://management.core.windows.net/
+ arm.url=https://management.azure.com/
+ arm.aad.url=https://login.windows.net/
+ arm.clientid=[your service principal client id]
+ arm.clientkey=[your service principal client key]
+ arm.tenant=[your service principal tenant]
+ management.subscription.id=[your subscription id (GUID)]
+ *
+ * @param args arguments supplied at the command line (they are not used)
+ * @throws Exception all of the exceptions!!
+ */
+ public static void main(String args[]) throws Exception {
+ Configuration config = createConfiguration();
+ ResourceManagementClient resourceManagementClient = ResourceManagementService.create(config);
+ ComputeManagementClient computeManagementClient = ComputeManagementService.create(config);
+ NetworkResourceProviderClient networkResourceProviderClient = NetworkResourceProviderService.create(config);
+
+ ArrayList