use of com.microsoft.azure.management.storage.StorageAccount in project azure-sdk-for-java by Azure.
the class TestResourceStreaming method createResource.
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
final String vmName = "vm" + this.testId;
System.out.println("In createResource \n\n\n");
Creatable<ResourceGroup> rgCreatable = virtualMachines.manager().resourceManager().resourceGroups().define(SdkContext.randomResourceName("rg" + vmName, 20)).withRegion(Region.US_EAST);
Creatable<StorageAccount> storageCreatable = this.storageAccounts.define(SdkContext.randomResourceName("stg", 20)).withRegion(Region.US_EAST).withNewResourceGroup(rgCreatable);
final AtomicInteger resourceCount = new AtomicInteger(0);
VirtualMachine virtualMachine = (VirtualMachine) virtualMachines.define(vmName).withRegion(Region.US_EAST).withNewResourceGroup(rgCreatable).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withNewPrimaryPublicIPAddress(SdkContext.randomResourceName("pip", 20)).withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER).withAdminUsername("testuser").withAdminPassword("12NewPA$$w0rd!").withSize(VirtualMachineSizeTypes.STANDARD_D1_V2).withNewStorageAccount(storageCreatable).withNewAvailabilitySet(SdkContext.randomResourceName("avset", 10)).createAsync().map(new Func1<Indexable, Resource>() {
@Override
public Resource call(Indexable resource) {
resourceCount.incrementAndGet();
Resource createdResource = (Resource) resource;
System.out.println("Created :" + createdResource.id());
return createdResource;
}
}).toBlocking().last();
Assert.assertTrue(resourceCount.get() == 7);
return virtualMachine;
}
use of com.microsoft.azure.management.storage.StorageAccount in project azure-sdk-for-java by Azure.
the class AzureTests method createStorageAccount.
@Test
public void createStorageAccount() throws Exception {
String storageAccountName = generateRandomResourceName("testsa", 12);
StorageAccount storageAccount = azure.storageAccounts().define(storageAccountName).withRegion(Region.ASIA_EAST).withNewResourceGroup().withSku(SkuName.PREMIUM_LRS).create();
Assert.assertEquals(storageAccount.name(), storageAccountName);
azure.resourceGroups().beginDeleteByName(storageAccount.resourceGroupName());
}
use of com.microsoft.azure.management.storage.StorageAccount in project azure-sdk-for-java by Azure.
the class VirtualMachineScaleSetImpl method handleOSDiskContainersAsync.
private Observable<Void> handleOSDiskContainersAsync() {
final VirtualMachineScaleSetStorageProfile storageProfile = inner().virtualMachineProfile().storageProfile();
if (isManagedDiskEnabled()) {
storageProfile.osDisk().withVhdContainers(null);
return Observable.just(null);
}
if (isOSDiskFromStoredImage(storageProfile)) {
// There is a restriction currently that virtual machine's disk cannot be stored in multiple storage
// accounts if scale set is based on stored image. Remove this check once azure start supporting it.
//
storageProfile.osDisk().vhdContainers().clear();
return Observable.just(null);
}
if (this.isInCreateMode() && this.creatableStorageAccountKeys.isEmpty() && this.existingStorageAccountsToAssociate.isEmpty()) {
//
return Utils.<StorageAccount>rootResource(this.storageManager.storageAccounts().define(this.namer.randomName("stg", 24).replace("-", "")).withRegion(this.regionName()).withExistingResourceGroup(this.resourceGroupName()).createAsync()).map(new Func1<StorageAccount, Void>() {
@Override
public Void call(StorageAccount storageAccount) {
String containerName = vhdContainerName;
if (containerName == null) {
containerName = "vhds";
}
storageProfile.osDisk().vhdContainers().add(mergePath(storageAccount.endPoints().primary().blob(), containerName));
vhdContainerName = null;
creatableStorageAccountKeys.clear();
existingStorageAccountsToAssociate.clear();
return null;
}
});
} else {
String containerName = this.vhdContainerName;
if (containerName == null) {
for (String containerUrl : storageProfile.osDisk().vhdContainers()) {
containerName = containerUrl.substring(containerUrl.lastIndexOf("/") + 1);
break;
}
}
if (containerName == null) {
containerName = "vhds";
}
for (String storageAccountKey : this.creatableStorageAccountKeys) {
StorageAccount storageAccount = (StorageAccount) createdResource(storageAccountKey);
storageProfile.osDisk().vhdContainers().add(mergePath(storageAccount.endPoints().primary().blob(), containerName));
}
for (StorageAccount storageAccount : this.existingStorageAccountsToAssociate) {
storageProfile.osDisk().vhdContainers().add(mergePath(storageAccount.endPoints().primary().blob(), containerName));
}
this.vhdContainerName = null;
this.creatableStorageAccountKeys.clear();
this.existingStorageAccountsToAssociate.clear();
return Observable.just(null);
}
}
use of com.microsoft.azure.management.storage.StorageAccount in project azure-sdk-for-java by Azure.
the class ManageApplicationGateway 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 rgName = SdkContext.randomResourceName("rgNEAG", 15);
final String pipName = SdkContext.randomResourceName("pip" + "-", 18);
final String userName = "tirekicker";
final String sshKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCfSPC2K7LZcFKEO+/t3dzmQYtrJFZNxOsbVgOVKietqHyvmYGHEC0J2wPdAqQ/63g/hhAEFRoyehM+rbeDri4txB3YFfnOK58jqdkyXzupWqXzOrlKY4Wz9SKjjN765+dqUITjKRIaAip1Ri137szRg71WnrmdP3SphTRlCx1Bk2nXqWPsclbRDCiZeF8QOTi4JqbmJyK5+0UqhqYRduun8ylAwKKQJ1NJt85sYIHn9f1Rfr6Tq2zS0wZ7DHbZL+zB5rSlAr8QyUdg/GQD+cmSs6LvPJKL78d6hMGk84ARtFo4A79ovwX/Fj01znDQkU6nJildfkaolH2rWFG/qttD azjava@javalib.com";
int backendPools = 2;
int vmCountInAPool = 4;
Region[] regions = { Region.US_EAST, Region.UK_WEST };
String[] addressSpaces = { "172.16.0.0/16", "172.17.0.0/16" };
String[][] publicIpCreatableKeys = new String[backendPools][vmCountInAPool];
String[][] ipAddresses = new String[backendPools][vmCountInAPool];
try {
//=============================================================
// Create a resource group (Where all resources gets created)
//
ResourceGroup resourceGroup = azure.resourceGroups().define(rgName).withRegion(Region.US_EAST).create();
System.out.println("Created a new resource group - " + resourceGroup.id());
//=============================================================
// Create a public IP address for the Application Gateway
System.out.println("Creating a public IP address for the application gateway ...");
PublicIPAddress publicIPAddress = azure.publicIPAddresses().define(pipName).withRegion(Region.US_EAST).withExistingResourceGroup(rgName).create();
System.out.println("Created a public IP address");
// Print the virtual network details
Utils.print(publicIPAddress);
//=============================================================
// Create backend pools
// Prepare a batch of Creatable definitions
List<Creatable<VirtualMachine>> creatableVirtualMachines = new ArrayList<>();
for (int i = 0; i < backendPools; i++) {
//=============================================================
// Create 1 network creatable per region
// Prepare Creatable Network definition (Where all the virtual machines get added to)
String networkName = SdkContext.randomResourceName("vnetNEAG-", 20);
Creatable<Network> networkCreatable = azure.networks().define(networkName).withRegion(regions[i]).withExistingResourceGroup(resourceGroup).withAddressSpace(addressSpaces[i]);
//=============================================================
// Create 1 storage creatable per region (For storing VMs disk)
String storageAccountName = SdkContext.randomResourceName("stgneag", 20);
Creatable<StorageAccount> storageAccountCreatable = azure.storageAccounts().define(storageAccountName).withRegion(regions[i]).withExistingResourceGroup(resourceGroup);
String linuxVMNamePrefix = SdkContext.randomResourceName("vm-", 15);
for (int j = 0; j < vmCountInAPool; j++) {
//=============================================================
// Create 1 public IP address creatable
Creatable<PublicIPAddress> publicIPAddressCreatable = azure.publicIPAddresses().define(String.format("%s-%d", linuxVMNamePrefix, j)).withRegion(regions[i]).withExistingResourceGroup(resourceGroup).withLeafDomainLabel(String.format("%s-%d", linuxVMNamePrefix, j));
publicIpCreatableKeys[i][j] = publicIPAddressCreatable.key();
//=============================================================
// Create 1 virtual machine creatable
Creatable<VirtualMachine> virtualMachineCreatable = azure.virtualMachines().define(String.format("%s-%d", linuxVMNamePrefix, j)).withRegion(regions[i]).withExistingResourceGroup(resourceGroup).withNewPrimaryNetwork(networkCreatable).withPrimaryPrivateIPAddressDynamic().withNewPrimaryPublicIPAddress(publicIPAddressCreatable).withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS).withRootUsername(userName).withSsh(sshKey).withSize(VirtualMachineSizeTypes.STANDARD_DS3_V2).withNewStorageAccount(storageAccountCreatable);
creatableVirtualMachines.add(virtualMachineCreatable);
}
}
//=============================================================
// Create two backend pools of virtual machines
StopWatch stopwatch = new StopWatch();
System.out.println("Creating virtual machines (two backend pools)");
stopwatch.start();
CreatedResources<VirtualMachine> virtualMachines = azure.virtualMachines().create(creatableVirtualMachines);
stopwatch.stop();
System.out.println("Created virtual machines (two backend pools)");
for (VirtualMachine virtualMachine : virtualMachines.values()) {
System.out.println(virtualMachine.id());
}
System.out.println("Virtual machines created: (took " + (stopwatch.getTime() / 1000) + " seconds) to create == " + virtualMachines.size() + " == virtual machines (4 virtual machines per backend pool)");
//=======================================================================
// Get IP addresses from created resources
System.out.println("IP Addresses in the backend pools are - ");
for (int i = 0; i < backendPools; i++) {
for (int j = 0; j < vmCountInAPool; j++) {
PublicIPAddress pip = (PublicIPAddress) virtualMachines.createdRelatedResource(publicIpCreatableKeys[i][j]);
pip.refresh();
ipAddresses[i][j] = pip.ipAddress();
System.out.println(String.format("[backend pool = %d][vm = %d] = %s", i, j, ipAddresses[i][j]));
}
System.out.println("======");
}
//=======================================================================
// Create an application gateway
System.out.println("================= CREATE ======================");
System.out.println("Creating an application gateway");
stopwatch.reset();
stopwatch.start();
final String sslCertificatePfxPath = ManageApplicationGateway.class.getClassLoader().getResource("myTest._pfx").getPath();
final String sslCertificatePfxPath2 = ManageApplicationGateway.class.getClassLoader().getResource("myTest2._pfx").getPath();
ApplicationGateway applicationGateway = azure.applicationGateways().define("myFirstAppGateway").withRegion(Region.US_EAST).withExistingResourceGroup(resourceGroup).defineRequestRoutingRule("HTTP-80-to-8080").fromPublicFrontend().fromFrontendHttpPort(80).toBackendHttpPort(8080).toBackendIPAddress(ipAddresses[0][0]).toBackendIPAddress(ipAddresses[0][1]).toBackendIPAddress(ipAddresses[0][2]).toBackendIPAddress(ipAddresses[0][3]).attach().defineRequestRoutingRule("HTTPs-443-to-8080").fromPublicFrontend().fromFrontendHttpsPort(443).withSslCertificateFromPfxFile(new File(sslCertificatePfxPath)).withSslCertificatePassword("Abc123").toBackendHttpPort(8080).toBackendIPAddress(ipAddresses[1][0]).toBackendIPAddress(ipAddresses[1][1]).toBackendIPAddress(ipAddresses[1][2]).toBackendIPAddress(ipAddresses[1][3]).attach().withExistingPublicIPAddress(publicIPAddress).create();
stopwatch.stop();
System.out.println("Application gateway created: (took " + (stopwatch.getTime() / 1000) + " seconds)");
Utils.print(applicationGateway);
//=======================================================================
// Update an application gateway
// configure the first routing rule for SSL offload
System.out.println("================= UPDATE ======================");
System.out.println("Updating the application gateway");
stopwatch.reset();
stopwatch.start();
applicationGateway.update().withoutRequestRoutingRule("HTTP-80-to-8080").defineRequestRoutingRule("HTTPs-1443-to-8080").fromPublicFrontend().fromFrontendHttpsPort(1443).withSslCertificateFromPfxFile(new File(sslCertificatePfxPath2)).withSslCertificatePassword("Abc123").toBackendHttpPort(8080).toBackendIPAddress(ipAddresses[0][0]).toBackendIPAddress(ipAddresses[0][1]).toBackendIPAddress(ipAddresses[0][2]).toBackendIPAddress(ipAddresses[0][3]).withHostName("www.contoso.com").withCookieBasedAffinity().attach().apply();
stopwatch.stop();
System.out.println("Application gateway updated: (took " + (stopwatch.getTime() / 1000) + " seconds)");
Utils.print(applicationGateway);
return true;
} catch (Exception f) {
System.out.println(f.getMessage());
f.printStackTrace();
} finally {
try {
System.out.println("Deleting Resource Group: " + rgName);
azure.resourceGroups().deleteByName(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.storage.StorageAccount in project azure-sdk-for-java by Azure.
the class VirtualMachineExtensionOperationsTests method canEnableDiagnosticsExtension.
@Test
public void canEnableDiagnosticsExtension() throws Exception {
final String STORAGEACCOUNTNAME = generateRandomResourceName("stg", 15);
final String VMNAME = "javavm1";
// Creates a storage account
StorageAccount storageAccount = storageManager.storageAccounts().define(STORAGEACCOUNTNAME).withRegion(REGION).withNewResourceGroup(RG_NAME).create();
// Create a Linux VM
//
VirtualMachine vm = computeManager.virtualMachines().define(VMNAME).withRegion(REGION).withExistingResourceGroup(RG_NAME).withNewPrimaryNetwork("10.0.0.0/28").withPrimaryPrivateIPAddressDynamic().withoutPrimaryPublicIPAddress().withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_14_04_LTS).withRootUsername("Foo12").withRootPassword("BaR@12abc!").withSize(VirtualMachineSizeTypes.STANDARD_D3).withExistingStorageAccount(storageAccount).create();
final InputStream embeddedJsonConfig = VirtualMachineExtensionOperationsTests.class.getResourceAsStream("/linux_diagnostics_public_config.json");
String jsonConfig = ((new ObjectMapper()).readTree(embeddedJsonConfig)).toString();
jsonConfig = jsonConfig.replace("%VirtualMachineResourceId%", vm.id());
// Update Linux VM to enable Diagnostics
vm.update().defineNewExtension("LinuxDiagnostic").withPublisher("Microsoft.OSTCExtensions").withType("LinuxDiagnostic").withVersion("2.3").withPublicSetting("ladCfg", new String(Base64.encodeBase64(jsonConfig.getBytes()))).withPublicSetting("storageAccount", storageAccount.name()).withProtectedSetting("storageAccountName", storageAccount.name()).withProtectedSetting("storageAccountKey", storageAccount.getKeys().get(0).value()).withProtectedSetting("storageAccountEndPoint", "https://core.windows.net:443/").attach().apply();
}
Aggregations