Skip to content

Commit fd43e2c

Browse files
author
Ovi Timpanariu
committed
add privateDNS Sample
1 parent 250e63d commit fd43e2c

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

azure-mgmt-network/.factorypath

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
11
<factorypath>
2-
<factorypathentry kind="PLUGIN" id="org.eclipse.jst.ws.annotations.core" enabled="true" runInBatchMode="false"/>
3-
<factorypathentry kind="WKSPJAR" id="/api-annotations/target/api-annotations-0.0.1.jar" enabled="true" runInBatchMode="false"/>
2+
<factorypathentry kind="VARJAR" id="M2_REPO/com/microsoft/azure/azure-client-runtime/1.6.10/azure-client-runtime-1.6.10.jar" enabled="true" runInBatchMode="false"/>
3+
<factorypathentry kind="VARJAR" id="M2_REPO/com/microsoft/rest/client-runtime/1.6.10/client-runtime-1.6.10.jar" enabled="true" runInBatchMode="false"/>
4+
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/guava/20.0/guava-20.0.jar" enabled="true" runInBatchMode="false"/>
5+
<factorypathentry kind="VARJAR" id="M2_REPO/com/squareup/retrofit2/retrofit/2.5.0/retrofit-2.5.0.jar" enabled="true" runInBatchMode="false"/>
6+
<factorypathentry kind="VARJAR" id="M2_REPO/com/squareup/okhttp3/okhttp/3.11.0/okhttp-3.11.0.jar" enabled="true" runInBatchMode="false"/>
7+
<factorypathentry kind="VARJAR" id="M2_REPO/com/squareup/okio/okio/1.14.0/okio-1.14.0.jar" enabled="true" runInBatchMode="false"/>
8+
<factorypathentry kind="VARJAR" id="M2_REPO/com/squareup/okhttp3/logging-interceptor/3.11.0/logging-interceptor-3.11.0.jar" enabled="true" runInBatchMode="false"/>
9+
<factorypathentry kind="VARJAR" id="M2_REPO/com/squareup/okhttp3/okhttp-urlconnection/3.11.0/okhttp-urlconnection-3.11.0.jar" enabled="true" runInBatchMode="false"/>
10+
<factorypathentry kind="VARJAR" id="M2_REPO/com/squareup/retrofit2/converter-jackson/2.5.0/converter-jackson-2.5.0.jar" enabled="true" runInBatchMode="false"/>
11+
<factorypathentry kind="VARJAR" id="M2_REPO/com/fasterxml/jackson/core/jackson-databind/2.9.4/jackson-databind-2.9.4.jar" enabled="true" runInBatchMode="false"/>
12+
<factorypathentry kind="VARJAR" id="M2_REPO/com/fasterxml/jackson/datatype/jackson-datatype-joda/2.9.8/jackson-datatype-joda-2.9.8.jar" enabled="true" runInBatchMode="false"/>
13+
<factorypathentry kind="VARJAR" id="M2_REPO/com/fasterxml/jackson/core/jackson-annotations/2.9.0/jackson-annotations-2.9.0.jar" enabled="true" runInBatchMode="false"/>
14+
<factorypathentry kind="VARJAR" id="M2_REPO/com/fasterxml/jackson/core/jackson-core/2.9.4/jackson-core-2.9.4.jar" enabled="true" runInBatchMode="false"/>
15+
<factorypathentry kind="VARJAR" id="M2_REPO/joda-time/joda-time/2.7/joda-time-2.7.jar" enabled="true" runInBatchMode="false"/>
16+
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar" enabled="true" runInBatchMode="false"/>
17+
<factorypathentry kind="VARJAR" id="M2_REPO/com/squareup/retrofit2/adapter-rxjava/2.4.0/adapter-rxjava-2.4.0.jar" enabled="true" runInBatchMode="false"/>
18+
<factorypathentry kind="VARJAR" id="M2_REPO/io/reactivex/rxjava/1.3.8/rxjava-1.3.8.jar" enabled="true" runInBatchMode="false"/>
19+
<factorypathentry kind="VARJAR" id="M2_REPO/com/microsoft/azure/azure-annotations/1.8.0/azure-annotations-1.8.0.jar" enabled="true" runInBatchMode="false"/>
20+
<factorypathentry kind="VARJAR" id="M2_REPO/org/apache/httpcomponents/httpcore/4.4.5/httpcore-4.4.5.jar" enabled="true" runInBatchMode="false"/>
21+
<factorypathentry kind="VARJAR" id="M2_REPO/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar" enabled="true" runInBatchMode="false"/>
422
</factorypath>

azure-samples/src/main/java/com/microsoft/azure/management/network/samples/ManagePrivateDns.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010
import com.microsoft.azure.management.Azure;
1111
import com.microsoft.azure.management.network.Network;
1212
import com.microsoft.azure.management.privatedns.v2018_09_01.implementation.privatednsManager;
13+
import com.microsoft.azure.management.privatedns.v2018_09_01.implementation.RecordSetInner;
14+
import com.microsoft.azure.management.privatedns.v2018_09_01.ARecord;
15+
import com.microsoft.azure.management.privatedns.v2018_09_01.RecordType;
1316
import com.microsoft.azure.management.resources.fluentcore.arm.Region;
1417
import com.microsoft.azure.management.resources.fluentcore.utils.SdkContext;
1518
import com.microsoft.rest.LogLevel;
1619

1720
import java.io.File;
21+
import java.util.ArrayList;
22+
import java.util.List;
1823

1924
public class ManagePrivateDns {
2025
/**
@@ -27,6 +32,8 @@ public static boolean runSample(Azure azure, privatednsManager prDnsManager) {
2732
final Region region = Region.US_EAST;
2833
final String rgName = SdkContext.randomResourceName("rg", 24);
2934
final String nwName = SdkContext.randomResourceName("nw", 24);
35+
final String regionDNS = "global"; // location always 'global' for privateDNS
36+
final String privateDNSName = "private.contoso.com"; // private DNS name
3037

3138
try {
3239
Network network = azure.networks().define(nwName)
@@ -38,6 +45,34 @@ public static boolean runSample(Azure azure, privatednsManager prDnsManager) {
3845
//
3946
// Private DNS hybrid sample
4047
//
48+
prDnsManager.privateZones().define(privateDNSName)
49+
.withRegion(regionDNS)
50+
.withExistingResourceGroup(rgName)
51+
.withIfMatch(null)
52+
.withIfNoneMatch(null)
53+
.create();
54+
prDnsManager.virtualNetworkLinks().define("linkToVnet")
55+
.withExistingPrivateDnsZone(rgName, privateDNSName)
56+
.withIfMatch(null)
57+
.withIfNoneMatch(null)
58+
.withLocation(regionDNS)
59+
.withRegistrationEnabled(true)
60+
.withVirtualNetwork(new SubResource().withId(network.id()))
61+
.create();
62+
RecordSetInner recordSetInner = new RecordSetInner();
63+
ARecord arecord = new ARecord();
64+
arecord.withIpv4Address("10.0.0.10"); // IP Address for record
65+
List<ARecord> list = new ArrayList<ARecord>();
66+
list.add(arecord);
67+
recordSetInner.withARecords(list);
68+
recordSetInner.withTtl(1L);
69+
String alias = "db"; //alias for IP
70+
prDnsManager.recordSets().inner().createOrUpdate(
71+
rgName,
72+
privateDNSName,
73+
RecordType.A,
74+
alias,
75+
recordSetInner);
4176
return true;
4277
} catch (Exception e) {
4378
System.err.println(e.getMessage());

0 commit comments

Comments
 (0)