use of com.microsoft.azure.management.network.PublicIPAddress in project azure-sdk-for-java by Azure.
the class ManageDns method runSample.
/**
* Main function which runs the actual sample.
* @param azure instance of the azure client
* @return true if sample runs successfully
*/
public static boolean runSample(Azure azure) {
final String customDomainName = "THE CUSTOM DOMAIN THAT YOU OWN (e.g. contoso.com)";
final String rgName = SdkContext.randomResourceName("rgNEMV_", 24);
final String appServicePlanName = SdkContext.randomResourceName("jplan1_", 15);
final String webAppName = SdkContext.randomResourceName("webapp1-", 20);
try {
ResourceGroup resourceGroup = azure.resourceGroups().define(rgName).withRegion(Region.US_EAST2).create();
//============================================================
// Creates root DNS Zone
System.out.println("Creating root DNS zone " + customDomainName + "...");
DnsZone rootDnsZone = azure.dnsZones().define(customDomainName).withExistingResourceGroup(resourceGroup).create();
System.out.println("Created root DNS zone " + rootDnsZone.name());
Utils.print(rootDnsZone);
//============================================================
// Sets NS records in the parent zone (hosting custom domain) to make Azure DNS the authoritative
// source for name resolution for the zone
System.out.println("Go to your registrar portal and configure your domain " + customDomainName + " with following name server addresses");
for (String nameServer : rootDnsZone.nameServers()) {
System.out.println(" " + nameServer);
}
System.out.println("Press a key after finishing above step");
System.in.read();
//============================================================
// Creates a web App
System.out.println("Creating Web App " + webAppName + "...");
WebApp webApp = azure.webApps().define(webAppName).withRegion(Region.US_EAST2).withExistingResourceGroup(rgName).withNewWindowsPlan(PricingTier.BASIC_B1).defineSourceControl().withPublicGitRepository("https://github.com/jianghaolu/azure-site-test").withBranch("master").attach().create();
System.out.println("Created web app " + webAppName);
Utils.print(webApp);
//============================================================
// Creates a CName record and bind it with the web app
// Step 1: Adds CName Dns record to root DNS zone that specify web app host domain as an
// alias for www.[customDomainName]
System.out.println("Updating DNS zone by adding a CName record...");
rootDnsZone = rootDnsZone.update().withCNameRecordSet("www", webApp.defaultHostName()).apply();
System.out.println("DNS zone updated");
Utils.print(rootDnsZone);
// Waiting for a minute for DNS CName entry to propagate
System.out.println("Waiting a minute for CName record entry to propagate...");
Thread.sleep(60 * 1000);
// Step 2: Adds a web app host name binding for www.[customDomainName]
// This binding action will fail if the CName record propagation is not yet completed
System.out.println("Updating Web app with host name binding...");
webApp.update().defineHostnameBinding().withThirdPartyDomain(customDomainName).withSubDomain("www").withDnsRecordType(CustomHostNameDnsRecordType.CNAME).attach().apply();
System.out.println("Web app updated");
Utils.print(webApp);
//============================================================
// Creates a virtual machine with public IP
System.out.println("Creating a virtual machine with public IP...");
VirtualMachine virtualMachine1 = azure.virtualMachines().define(SdkContext.randomResourceName("employeesvm-", 20)).withRegion(Region.US_EAST).withExistingResourceGroup(resourceGroup).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withNewPrimaryPublicIPAddress(SdkContext.randomResourceName("empip-", 20)).withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER).withAdminUsername("testuser").withAdminPassword("12NewPA$$w0rd!").withSize(VirtualMachineSizeTypes.STANDARD_D1_V2).create();
System.out.println("Virtual machine created");
//============================================================
// Update DNS zone by adding a A record in root DNS zone pointing to virtual machine IPv4 address
PublicIPAddress vm1PublicIPAddress = virtualMachine1.getPrimaryPublicIPAddress();
System.out.println("Updating root DNS zone " + customDomainName + "...");
rootDnsZone = rootDnsZone.update().defineARecordSet("employees").withIPv4Address(vm1PublicIPAddress.ipAddress()).attach().apply();
System.out.println("Updated root DNS zone " + rootDnsZone.name());
Utils.print(rootDnsZone);
// Prints the CName and A Records in the root DNS zone
//
System.out.println("Getting CName record set in the root DNS zone " + customDomainName + "...");
PagedList<CNameRecordSet> cnameRecordSets = rootDnsZone.cNameRecordSets().list();
for (CNameRecordSet cnameRecordSet : cnameRecordSets) {
System.out.println("Name: " + cnameRecordSet.name() + " Canonical Name: " + cnameRecordSet.canonicalName());
}
System.out.println("Getting ARecord record set in the root DNS zone " + customDomainName + "...");
PagedList<ARecordSet> aRecordSets = rootDnsZone.aRecordSets().list();
for (ARecordSet aRecordSet : aRecordSets) {
System.out.println("Name: " + aRecordSet.name());
for (String ipv4Address : aRecordSet.ipv4Addresses()) {
System.out.println(" " + ipv4Address);
}
}
//============================================================
// Creates a child DNS zone
String partnerSubDomainName = "partners." + customDomainName;
System.out.println("Creating child DNS zone " + partnerSubDomainName + "...");
DnsZone partnersDnsZone = azure.dnsZones().define(partnerSubDomainName).withExistingResourceGroup(resourceGroup).create();
System.out.println("Created child DNS zone " + partnersDnsZone.name());
Utils.print(partnersDnsZone);
//============================================================
// Adds NS records in the root dns zone to delegate partners.[customDomainName] to child dns zone
System.out.println("Updating root DNS zone " + rootDnsZone + "...");
DnsRecordSet.UpdateDefinitionStages.WithNSRecordNameServerOrAttachable<DnsZone.Update> nsRecordStage = rootDnsZone.update().defineNSRecordSet("partners").withNameServer(partnersDnsZone.nameServers().get(0));
for (int i = 1; i < partnersDnsZone.nameServers().size(); i++) {
nsRecordStage = nsRecordStage.withNameServer(partnersDnsZone.nameServers().get(i));
}
nsRecordStage.attach().apply();
System.out.println("Root DNS zone updated");
Utils.print(rootDnsZone);
//============================================================
// Creates a virtual machine with public IP
System.out.println("Creating a virtual machine with public IP...");
VirtualMachine virtualMachine2 = azure.virtualMachines().define(SdkContext.randomResourceName("partnersvm-", 20)).withRegion(Region.US_EAST).withExistingResourceGroup(resourceGroup).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withNewPrimaryPublicIPAddress(SdkContext.randomResourceName("ptnerpip-", 20)).withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER).withAdminUsername("testuser").withAdminPassword("12NewPA$$w0rd!").withSize(VirtualMachineSizeTypes.STANDARD_D1_V2).create();
System.out.println("Virtual machine created");
//============================================================
// Update child DNS zone by adding a A record pointing to virtual machine IPv4 address
PublicIPAddress vm2PublicIPAddress = virtualMachine2.getPrimaryPublicIPAddress();
System.out.println("Updating child DNS zone " + partnerSubDomainName + "...");
partnersDnsZone = partnersDnsZone.update().defineARecordSet("@").withIPv4Address(vm2PublicIPAddress.ipAddress()).attach().apply();
System.out.println("Updated child DNS zone " + partnersDnsZone.name());
Utils.print(partnersDnsZone);
//============================================================
// Removes A record entry from the root DNS zone
System.out.println("Removing A Record from root DNS zone " + rootDnsZone.name() + "...");
rootDnsZone = rootDnsZone.update().withoutARecordSet("employees").apply();
System.out.println("Removed A Record from root DNS zone");
Utils.print(rootDnsZone);
//============================================================
// Deletes the DNS zone
System.out.println("Deleting child DNS zone " + partnersDnsZone.name() + "...");
azure.dnsZones().deleteById(partnersDnsZone.id());
System.out.println("Deleted child DNS zone " + partnersDnsZone.name());
return true;
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
azure.resourceGroups().beginDeleteByName(rgName);
System.out.println("Deleted Resource Group: " + rgName);
} catch (NullPointerException npe) {
System.out.println("Did not create any resources in Azure. No clean up is necessary");
} catch (Exception g) {
g.printStackTrace();
}
}
return false;
}
use of com.microsoft.azure.management.network.PublicIPAddress in project photon-model by vmware.
the class AzureComputeEnumerationAdapterService method processCreateUpdateNicRequest.
/**
* Processes request for creating and updating Network interface resources.
*/
private void processCreateUpdateNicRequest(NetworkInterfaceState nic, NetworkInterfaceInner remoteNic, EnumerationContext ctx, List<DeferredResult<NetworkInterfaceState>> ops, Map<String, String> subnetPerNicId, boolean isCreate) {
nic.name = remoteNic.name();
nic.subnetLink = subnetPerNicId.get(remoteNic.id());
NicMetadata nicMeta = new NicMetadata();
nicMeta.state = nic;
nicMeta.macAddress = remoteNic.macAddress();
// else will default to original ID for PATCH requests
if (isCreate) {
nic.id = remoteNic.id();
nic.endpointLink = ctx.request.endpointLink;
AdapterUtils.addToEndpointLinks(nic, ctx.request.endpointLink);
nic.tenantLinks = ctx.parentCompute.tenantLinks;
nic.regionId = remoteNic.location();
nic.computeHostLink = ctx.parentCompute.documentSelfLink;
} else {
if (StringUtils.isEmpty(nic.endpointLink)) {
nic.endpointLink = ctx.request.endpointLink;
}
nic.endpointLinks.add(ctx.request.endpointLink);
}
List<NetworkInterfaceIPConfigurationInner> ipConfigurations = remoteNic.ipConfigurations();
if (ipConfigurations == null || ipConfigurations.isEmpty()) {
executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
return;
}
NetworkInterfaceIPConfigurationInner nicIPConf = ipConfigurations.get(0);
nic.address = nicIPConf.privateIPAddress();
if (nicIPConf.publicIPAddress() == null) {
executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
return;
}
// IP address is not directly available in NetworkInterfaceIPConfigurationInner.
// It is available as a SubResource, We use the SubResource ID of IP address from
// NetworkInterfaceIPConfigurationInner to obtain the IP address.
Consumer<Throwable> failure = e -> {
logWarning("Error getting public IP address from Azure [endpointLink:%s], [Exception:%s]", ctx.request.endpointLink, e.getMessage());
handleError(ctx, e);
};
PhotonModelUtils.runInExecutor(this.executorService, () -> {
Azure azure = ctx.azureSdkClients.getAzureClient();
azure.publicIPAddresses().getByIdAsync(nicIPConf.publicIPAddress().id()).subscribe(injectOperationContext(new Action1<PublicIPAddress>() {
@Override
public void call(PublicIPAddress publicIPAddress) {
nicMeta.publicIp = publicIPAddress.ipAddress();
if (publicIPAddress.inner().dnsSettings() != null) {
nicMeta.publicDnsName = publicIPAddress.inner().dnsSettings().fqdn();
}
executeNicCreateUpdateRequest(nic, remoteNic, ctx, ops, nicMeta, isCreate);
}
}));
}, failure);
}
use of com.microsoft.azure.management.network.PublicIPAddress in project azure-tools-for-java by Microsoft.
the class SettingsStep method retrievePublicIpAddresses.
private void retrievePublicIpAddresses() {
AzureTaskManager.getInstance().runInBackground("Loading public ip addresses...", new Runnable() {
@Override
public void run() {
if (publicIpAddresses == null) {
publicIpAddresses = wizard.getAzure().publicIPAddresses().list();
}
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
pipCombo.removeAll();
pipCombo.add(NONE);
pipCombo.add(CREATE_NEW);
for (PublicIPAddress pip : filterPip()) {
pipCombo.add(pip.name());
pipCombo.setData(pip.name(), pip);
}
pipCombo.select(0);
}
});
}
});
pipCombo.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (NONE.equals(pipCombo.getText())) {
wizard.setPublicIpAddress(null);
wizard.setWithNewPip(false);
} else if (CREATE_NEW.equals(pipCombo.getText())) {
wizard.setWithNewPip(true);
wizard.setPublicIpAddress(null);
// showNewPipForm();
} else if (pipCombo.getData(pipCombo.getText()) instanceof PublicIPAddress) {
wizard.setPublicIpAddress((PublicIPAddress) pipCombo.getData(pipCombo.getText()));
wizard.setWithNewPip(false);
}
}
});
if (publicIpAddresses == null) {
DefaultLoader.getIdeHelper().invokeAndWait(new Runnable() {
@Override
public void run() {
pipCombo.setItems(new String[] { NONE, CREATE_NEW, LOADING });
pipCombo.select(0);
wizard.setPublicIpAddress(null);
wizard.setWithNewPip(false);
}
});
}
}
use of com.microsoft.azure.management.network.PublicIPAddress in project cloudbreak by hortonworks.
the class AzureClient method getLoadBalancerIps.
public List<String> getLoadBalancerIps(String name, String loadBalancerName) {
List<String> ipList = new ArrayList<>();
List<String> publicIpAddressIds = getLoadBalancer(name, loadBalancerName).publicIPAddressIds();
for (String publicIpAddressId : publicIpAddressIds) {
PublicIPAddress publicIpAddress = getPublicIpAddressById(publicIpAddressId);
ipList.add(publicIpAddress.ipAddress());
}
return ipList;
}
Aggregations