26
26
import com .microsoft .azure .management .batch .BatchAccountKeys ;
27
27
import com .microsoft .azure .management .compute .AvailabilitySet ;
28
28
import com .microsoft .azure .management .compute .ContainerService ;
29
- import com .microsoft .azure .management .compute .ContainerServiceOchestratorTypes ;
29
+ import com .microsoft .azure .management .compute .ContainerServiceOrchestratorTypes ;
30
30
import com .microsoft .azure .management .compute .DataDisk ;
31
31
import com .microsoft .azure .management .compute .ImageDataDisk ;
32
32
import com .microsoft .azure .management .compute .VirtualMachine ;
33
33
import com .microsoft .azure .management .compute .VirtualMachineCustomImage ;
34
34
import com .microsoft .azure .management .compute .VirtualMachineExtension ;
35
+ import com .microsoft .azure .management .containerinstance .Container ;
36
+ import com .microsoft .azure .management .containerinstance .ContainerGroup ;
37
+ import com .microsoft .azure .management .containerinstance .ContainerPort ;
38
+ import com .microsoft .azure .management .containerinstance .EnvironmentVariable ;
39
+ import com .microsoft .azure .management .containerinstance .Volume ;
40
+ import com .microsoft .azure .management .containerinstance .VolumeMount ;
35
41
import com .microsoft .azure .management .containerregistry .Registry ;
36
42
import com .microsoft .azure .management .containerregistry .implementation .RegistryListCredentials ;
37
43
import com .microsoft .azure .management .cosmosdb .CosmosDBAccount ;
84
90
import com .microsoft .azure .management .network .LoadBalancingRule ;
85
91
import com .microsoft .azure .management .network .Network ;
86
92
import com .microsoft .azure .management .network .NetworkInterface ;
93
+ import com .microsoft .azure .management .network .NetworkPeering ;
87
94
import com .microsoft .azure .management .network .NetworkSecurityGroup ;
88
95
import com .microsoft .azure .management .network .NetworkSecurityRule ;
89
96
import com .microsoft .azure .management .network .NetworkWatcher ;
90
97
import com .microsoft .azure .management .network .NextHop ;
91
98
import com .microsoft .azure .management .network .PacketCapture ;
92
99
import com .microsoft .azure .management .network .PacketCaptureFilter ;
93
100
import com .microsoft .azure .management .network .PublicIPAddress ;
101
+ import com .microsoft .azure .management .network .RouteTable ;
94
102
import com .microsoft .azure .management .network .SecurityGroupNetworkInterface ;
95
103
import com .microsoft .azure .management .network .SecurityGroupView ;
96
104
import com .microsoft .azure .management .network .Subnet ;
128
136
import com .microsoft .azure .management .trafficmanager .TrafficManagerExternalEndpoint ;
129
137
import com .microsoft .azure .management .trafficmanager .TrafficManagerNestedProfileEndpoint ;
130
138
import com .microsoft .azure .management .trafficmanager .TrafficManagerProfile ;
139
+ import okhttp3 .OkHttpClient ;
140
+ import okhttp3 .Request ;
131
141
import org .apache .commons .lang3 .StringUtils ;
132
142
import org .apache .commons .net .ftp .FTP ;
133
143
import org .apache .commons .net .ftp .FTPClient ;
144
154
import java .util .Map ;
145
155
import java .util .Properties ;
146
156
import java .util .Set ;
157
+ import java .util .concurrent .TimeUnit ;
147
158
148
159
/**
149
160
* Common utils for Azure management samples.
@@ -267,6 +278,9 @@ public static void print(VirtualMachine resource) {
267
278
msi .append ("\n \t \t \t MSI Active Directory Service Principal Id:" ).append (resource .managedServiceIdentityPrincipalId ());
268
279
msi .append ("\n \t \t \t MSI Active Directory Tenant Id:" ).append (resource .managedServiceIdentityTenantId ());
269
280
281
+ StringBuilder zones = new StringBuilder ().append ("\n \t Zones: " );
282
+ zones .append (resource .availabilityZones ());
283
+
270
284
System .out .println (new StringBuilder ().append ("Virtual Machine: " ).append (resource .id ())
271
285
.append ("Name: " ).append (resource .name ())
272
286
.append ("\n \t Resource group: " ).append (resource .resourceGroupName ())
@@ -279,6 +293,7 @@ public static void print(VirtualMachine resource) {
279
293
.append (networkProfile )
280
294
.append (extensions )
281
295
.append (msi )
296
+ .append (zones )
282
297
.toString ());
283
298
}
284
299
@@ -320,12 +335,29 @@ public static void print(Network resource) {
320
335
for (Subnet subnet : resource .subnets ().values ()) {
321
336
info .append ("\n \t Subnet: " ).append (subnet .name ())
322
337
.append ("\n \t \t Address prefix: " ).append (subnet .addressPrefix ());
338
+
339
+ // Output associated NSG
323
340
NetworkSecurityGroup subnetNsg = subnet .getNetworkSecurityGroup ();
324
341
if (subnetNsg != null ) {
325
- info .append ("\n \t \t Network security group: " ).append (subnetNsg .id ());
342
+ info .append ("\n \t \t Network security group ID: " ).append (subnetNsg .id ());
343
+ }
344
+
345
+ // Output associated route table
346
+ RouteTable routeTable = subnet .getRouteTable ();
347
+ if (routeTable != null ) {
348
+ info .append ("\n \t Route table ID: " ).append (routeTable .id ());
326
349
}
327
350
}
328
351
352
+ // Output peerings
353
+ for (NetworkPeering peering : resource .peerings ().list ()) {
354
+ info .append ("\n \t Peering: " ).append (peering .name ())
355
+ .append ("\n \t \t Remote network ID: " ).append (peering .remoteNetworkId ())
356
+ .append ("\n \t \t Peering state: " ).append (peering .state ())
357
+ .append ("\n \t \t Is traffic forwarded from remote network allowed? " ).append (peering .isTrafficForwardingFromRemoteNetworkAllowed ())
358
+ //TODO .append("\n\t\tIs access from remote network allowed? ").append(peering.isAccessFromRemoteNetworkAllowed())
359
+ .append ("\n \t \t Gateway use: " ).append (peering .gatewayUse ());
360
+ }
329
361
System .out .println (info .toString ());
330
362
}
331
363
@@ -410,6 +442,7 @@ public static void print(PublicIPAddress resource) {
410
442
.append ("\n \t Reverse FQDN: " ).append (resource .reverseFqdn ())
411
443
.append ("\n \t Idle timeout (minutes): " ).append (resource .idleTimeoutInMinutes ())
412
444
.append ("\n \t IP allocation method: " ).append (resource .ipAllocationMethod ())
445
+ .append ("\n \t Zones: " ).append (resource .availabilityZones ())
413
446
.toString ());
414
447
}
415
448
@@ -1097,7 +1130,7 @@ public static void print(ContainerService containerService) {
1097
1130
.append ("\n \t \t Agent pool leaf domain label: " ).append (containerService .agentPoolLeafDomainLabel ())
1098
1131
.append ("\n \t Linux user name: " ).append (containerService .linuxRootUsername ())
1099
1132
.append ("\n \t SSH key: " ).append (containerService .sshKey ());
1100
- if (containerService .orchestratorType () == ContainerServiceOchestratorTypes .KUBERNETES ) {
1133
+ if (containerService .orchestratorType () == ContainerServiceOrchestratorTypes .KUBERNETES ) {
1101
1134
info .append ("\n \t Name: " ).append (containerService .servicePrincipalClientId ());
1102
1135
}
1103
1136
@@ -1933,7 +1966,7 @@ public static void print(CosmosDBAccount cosmosDBAccount) {
1933
1966
.append ("\n \t \t \t Name :" ).append (readReplica .locationName ());
1934
1967
}
1935
1968
}
1936
-
1969
+
1937
1970
/**
1938
1971
* Print Active Directory User info.
1939
1972
* @param user active directory user
@@ -2211,4 +2244,109 @@ public static void print(NextHop resource) {
2211
2244
.append ("\n \t Route table id: " ).append (resource .routeTableId ())
2212
2245
.toString ());
2213
2246
}
2247
+
2248
+ /**
2249
+ * Print container group info.
2250
+ *
2251
+ * @param resource a container group
2252
+ */
2253
+ public static void print (ContainerGroup resource ) {
2254
+ StringBuilder info = new StringBuilder ().append ("Container Group: " ).append (resource .id ())
2255
+ .append ("Name: " ).append (resource .name ())
2256
+ .append ("\n \t Resource group: " ).append (resource .resourceGroupName ())
2257
+ .append ("\n \t Region: " ).append (resource .region ())
2258
+ .append ("\n \t Tags: " ).append (resource .tags ())
2259
+ .append ("\n \t OS type: " ).append (resource .osType ());
2260
+
2261
+ if (resource .ipAddress () != null ) {
2262
+ info .append ("\n \t Public IP address: " ).append (resource .ipAddress ());
2263
+ }
2264
+ if (resource .externalTcpPorts () != null ) {
2265
+ info .append ("\n \t External TCP ports:" );
2266
+ for (int port : resource .externalTcpPorts ()) {
2267
+ info .append (" " ).append (port );
2268
+ }
2269
+ }
2270
+ if (resource .externalUdpPorts () != null ) {
2271
+ info .append ("\n \t External UDP ports:" );
2272
+ for (int port : resource .externalUdpPorts ()) {
2273
+ info .append (" " ).append (port );
2274
+ }
2275
+ }
2276
+ if (resource .imageRegistryServers () != null ) {
2277
+ info .append ("\n \t Private Docker image registries:" );
2278
+ for (String server : resource .imageRegistryServers ()) {
2279
+ info .append (" " ).append (server );
2280
+ }
2281
+ }
2282
+ if (resource .volumes () != null ) {
2283
+ info .append ("\n \t Volume mapping: " );
2284
+ for (Map .Entry <String , Volume > entry : resource .volumes ().entrySet ()) {
2285
+ info .append ("\n \t \t Name: " ).append (entry .getKey ()).append (" -> " ).append (entry .getValue ().azureFile ().shareName ());
2286
+ }
2287
+ }
2288
+ if (resource .containers () != null ) {
2289
+ info .append ("\n \t Container instances: " );
2290
+ for (Map .Entry <String , Container > entry : resource .containers ().entrySet ()) {
2291
+ Container container = entry .getValue ();
2292
+ info .append ("\n \t \t Name: " ).append (entry .getKey ()).append (" -> " ).append (container .image ());
2293
+ info .append ("\n \t \t \t Resources: " );
2294
+ info .append (container .resources ().requests ().cpu ()).append ("CPUs " );
2295
+ info .append (container .resources ().requests ().memoryInGB ()).append ("GB" );
2296
+ info .append ("\n \t \t \t Ports:" );
2297
+ for (ContainerPort port : container .ports ()) {
2298
+ info .append (" " ).append (port .port ());
2299
+ }
2300
+ if (container .volumeMounts () != null ) {
2301
+ info .append ("\n \t \t \t Volume mounts:" );
2302
+ for (VolumeMount volumeMount : container .volumeMounts ()) {
2303
+ info .append (" " ).append (volumeMount .name ()).append ("->" ).append (volumeMount .mountPath ());
2304
+ }
2305
+ }
2306
+ if (container .command () != null ) {
2307
+ info .append ("\n \t \t \t Start commands:" );
2308
+ for (String command : container .command ()) {
2309
+ info .append ("\n \t \t \t \t " ).append (command );
2310
+ }
2311
+ }
2312
+ if (container .environmentVariables () != null ) {
2313
+ info .append ("\n \t \t \t ENV vars:" );
2314
+ for (EnvironmentVariable envVar : container .environmentVariables ()) {
2315
+ info .append ("\n \t \t \t \t " ).append (envVar .name ()).append ("=" ).append (envVar .value ());
2316
+ }
2317
+ }
2318
+ }
2319
+ }
2320
+
2321
+ System .out .println (info .toString ());
2322
+ }
2323
+
2324
+ private static OkHttpClient httpClient ;
2325
+
2326
+ /**
2327
+ * Ensure the HTTP client is valid.
2328
+ *
2329
+ */
2330
+ private static OkHttpClient ensureValidHttpClient () {
2331
+ if (httpClient == null ) {
2332
+ httpClient = new OkHttpClient .Builder ().readTimeout (1 , TimeUnit .MINUTES ).build ();
2333
+ }
2334
+
2335
+ return httpClient ;
2336
+ }
2337
+
2338
+ /**
2339
+ * Connect to a specified URL using "curl" like HTTP GET client.
2340
+ *
2341
+ * @param url URL to be tested
2342
+ * @return the HTTP GET response content
2343
+ */
2344
+ public static String curl (String url ) {
2345
+ Request request = new Request .Builder ().url (url ).get ().build ();
2346
+ try {
2347
+ return ensureValidHttpClient ().newCall (request ).execute ().body ().string ();
2348
+ } catch (IOException e ) {
2349
+ return null ;
2350
+ }
2351
+ }
2214
2352
}
0 commit comments