com.microsoft.azure.management.resources.fluentcore.arm.Region Java Examples

The following examples show how to use com.microsoft.azure.management.resources.fluentcore.arm.Region. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CosmosDBTests.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Test
public void CanCreateCosmosDbMongoDBAccount() {
    final String cosmosDbAccountName = SdkContext.randomResourceName("cosmosdb", 22);

    CosmosDBAccount cosmosDBAccount = cosmosDBManager.databaseAccounts()
        .define(cosmosDbAccountName)
        .withRegion(Region.US_WEST_CENTRAL)
        .withNewResourceGroup(RG_NAME)
        .withDataModelMongoDB()
        .withEventualConsistency()
        .withWriteReplication(Region.US_EAST)
        .withReadReplication(Region.US_CENTRAL)
        .withIpRangeFilter("")
        .withTag("tag1", "value1")
        .create();

    Assert.assertEquals(cosmosDBAccount.name(), cosmosDbAccountName.toLowerCase());
    Assert.assertEquals(cosmosDBAccount.kind(), DatabaseAccountKind.MONGO_DB);
    Assert.assertEquals(cosmosDBAccount.writableReplications().size(), 1);
    Assert.assertEquals(cosmosDBAccount.readableReplications().size(), 2);
    Assert.assertEquals(cosmosDBAccount.defaultConsistencyLevel(), DefaultConsistencyLevel.EVENTUAL);
}
 
Example #2
Source File: CosmosDBTests.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Test
public void CanCreateCosmosDbSqlAccount() {
    final String cosmosDbAccountName = SdkContext.randomResourceName("cosmosdb", 22);

    CosmosDBAccount cosmosDBAccount = cosmosDBManager.databaseAccounts()
        .define(cosmosDbAccountName)
        .withRegion(Region.US_WEST_CENTRAL)
        .withNewResourceGroup(RG_NAME)
        .withDataModelSql()
        .withEventualConsistency()
        .withWriteReplication(Region.US_EAST)
        .withReadReplication(Region.US_CENTRAL)
        .withIpRangeFilter("")
        .withMultipleWriteLocationsEnabled(true)
        .withTag("tag1", "value1")
        .create();

    Assert.assertEquals(cosmosDBAccount.name(), cosmosDbAccountName.toLowerCase());
    Assert.assertEquals(cosmosDBAccount.kind(), DatabaseAccountKind.GLOBAL_DOCUMENT_DB);
    Assert.assertEquals(cosmosDBAccount.writableReplications().size(), 2);
    Assert.assertEquals(cosmosDBAccount.readableReplications().size(), 2);
    Assert.assertEquals(cosmosDBAccount.defaultConsistencyLevel(), DefaultConsistencyLevel.EVENTUAL);
    Assert.assertTrue(cosmosDBAccount.multipleWriteLocationsEnabled());


}
 
Example #3
Source File: GalleryImageVersionImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public Update withoutRegionAvailability(Region region) {
    if (this.inner().publishingProfile() != null && this.inner().publishingProfile().targetRegions() != null) {
        int foundIndex = -1;
        int i = 0;
        String regionNameToRemove = region.toString();
        String regionNameToRemoveTrimmed = regionNameToRemove.replaceAll("\\s", "");

        for (TargetRegion targetRegion : this.inner().publishingProfile().targetRegions()) {
            String regionStr = targetRegion.name();
            String regionStrTrimmed = regionStr.replaceAll("\\s", "");
            if (regionStrTrimmed.equalsIgnoreCase(regionNameToRemoveTrimmed)) {
                foundIndex = i;
                break;
            }
            i++;
        }
        if (foundIndex != -1) {
            this.inner().publishingProfile().targetRegions().remove(foundIndex);
        }
    }
    return this;
}
 
Example #4
Source File: TestBatch.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public BatchAccount createResource(BatchAccounts resources) throws Exception {
    final String batchAccountName = "batch" + this.testId;
    final BatchAccount[] batchAccounts = new BatchAccount[1];
    final SettableFuture<BatchAccount> future = SettableFuture.create();


    Observable<Indexable> resourceStream = resources.define(batchAccountName)
            .withRegion(Region.INDIA_CENTRAL)
            .withNewResourceGroup()
            .withTag("mytag", "testtag")
            .createAsync();

    Utils.<BatchAccount>rootResource(resourceStream)
            .subscribe(new Action1<BatchAccount>() {
                @Override
                public void call(BatchAccount batchAccount) {
                    future.set(batchAccount);
                }
            });

    batchAccounts[0] = future.get();
    Assert.assertNull(batchAccounts[0].autoStorage());

    return batchAccounts[0];
}
 
Example #5
Source File: DnsZoneRecordSetETagTests.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Test
public void canDeleteZoneWithExplicitETag() throws Exception {
    final Region region = Region.US_EAST;
    final String topLevelDomain = "www.contoso" + generateRandomResourceName("z", 10) + ".com";

    final DnsZone dnsZone = zoneManager.zones().define(topLevelDomain)
            .withNewResourceGroup(RG_NAME, region)
            .withETagCheck()
            .create();
    Assert.assertNotNull(dnsZone.eTag());
    Action0 action = new Action0() {
        @Override
        public void call() {
            zoneManager.zones().deleteById(dnsZone.id(), dnsZone.eTag() + "-foo");
        }
    };
    ensureETagExceptionIsThrown(action);
    zoneManager.zones().deleteById(dnsZone.id(), dnsZone.eTag());
}
 
Example #6
Source File: SqlServersImpl.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public Observable<SqlSubscriptionUsageMetric> listUsageByRegionAsync(final Region region) {
    Objects.requireNonNull(region);
    final SqlServers self = this;
    return this.manager().inner().subscriptionUsages()
        .listByLocationAsync(region.name())
        .flatMap(new Func1<Page<SubscriptionUsageInner>, Observable<SubscriptionUsageInner>>() {
            @Override
            public Observable<SubscriptionUsageInner> call(Page<SubscriptionUsageInner> subscriptionUsageInnerPage) {
                return Observable.from(subscriptionUsageInnerPage.items());
            }
        })
        .map(new Func1<SubscriptionUsageInner, SqlSubscriptionUsageMetric>() {
            @Override
            public SqlSubscriptionUsageMetric call(SubscriptionUsageInner subscriptionUsageInner) {
                return new SqlSubscriptionUsageMetricImpl(region.name(), subscriptionUsageInner, self.manager());
            }
        });
}
 
Example #7
Source File: TestVirtualMachineSizes.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
    List<VirtualMachineSize> availableSizes = virtualMachines.sizes().listByRegion(Region.US_EAST);
    Assert.assertTrue(availableSizes.size() > 0);
    System.out.println("VM Sizes: " + availableSizes);
    final String vmName = "vm" + this.testId;
    VirtualMachine vm = virtualMachines.define(vmName)
            .withRegion(Region.US_EAST)
            .withNewResourceGroup()
            .withNewPrimaryNetwork("10.0.0.0/28")
            .withPrimaryPrivateIPAddressDynamic()
            .withoutPrimaryPublicIPAddress()
            .withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER)
            .withAdminUsername("testuser")
            .withAdminPassword("12NewPA$$w0rd!")
            .withSize(availableSizes.get(0).name()) // Use the first size
            .create();

    Assert.assertTrue(vm.size().toString().equalsIgnoreCase(availableSizes.get(0).name()));
    return vm;
}
 
Example #8
Source File: StorageBlobServicesTests.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Test
public void canCreateBlobServices() {
    String SA_NAME = generateRandomResourceName("javacsmsa", 15);

    StorageAccount storageAccount = storageManager.storageAccounts()
            .define(SA_NAME)
            .withRegion(Region.US_EAST)
            .withNewResourceGroup(RG_NAME)
            .create();

    BlobServices blobServices = this.storageManager.blobServices();
    BlobServiceProperties blobService = blobServices.define("blobServicesTest")
            .withExistingStorageAccount(storageAccount.resourceGroupName(), storageAccount.name())
            .withDeleteRetentionPolicyEnabled(5)
            .create();

    Assert.assertTrue(blobService.deleteRetentionPolicy().enabled());
    Assert.assertEquals(5, blobService.deleteRetentionPolicy().days().intValue());

}
 
Example #9
Source File: VirtualMachineExtensionImageOperationsTests.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
@Test
public void canListExtensionImages() throws Exception {
    final int maxListing = 20;
    int count = 0;
    List<VirtualMachineExtensionImage> extensionImages =
            computeManager.virtualMachineExtensionImages()
                    .listByRegion(Region.US_EAST);
    // Lazy listing
    for (VirtualMachineExtensionImage extensionImage : extensionImages) {
        Assert.assertNotNull(extensionImage);
        count++;
        if (count >= maxListing) {
            break;
        }
    }
    Assert.assertTrue(count == maxListing);
}
 
Example #10
Source File: TestSql.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public SqlServer createResource(SqlServers resources) throws Exception {
    final String sqlServerName = "sql" + this.testId;
    final SqlServer[] sqlServers = new SqlServer[1];
    final SettableFuture<SqlServer> future = SettableFuture.create();
    Observable<Indexable> resourceStream = resources.define(sqlServerName)
            .withRegion(Region.US_EAST)
            .withNewResourceGroup()
            .withAdministratorLogin("admin32")
            .withAdministratorPassword("Password~1")
            .withNewDatabase("database1")
            .withNewElasticPool("elasticPool1", ElasticPoolEdition.STANDARD, "databaseInEP")
            .withNewFirewallRule("10.10.10.10")
            .withTag("mytag", "testtag")
            .createAsync();

    Utils.<SqlServer>rootResource(resourceStream)
            .subscribe(new Action1<SqlServer>() {
                @Override
                public void call(SqlServer sqlServer) {
                    future.set(sqlServer);
                }
            });

    sqlServers[0] = future.get();

    Assert.assertNotNull(sqlServers[0].inner());

    Assert.assertNotNull(sqlServers[0].inner());
    // Including master database
    Assert.assertEquals(sqlServers[0].databases().list().size(), 3);
    Assert.assertEquals(sqlServers[0].elasticPools().list().size(), 1);
    Assert.assertEquals(sqlServers[0].firewallRules().list().size(), 2);

    return sqlServers[0];
}
 
Example #11
Source File: ApplicationGatewayTests.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Test
public void testAppGatewaysStartStop() throws Exception {
    String rgName = SdkContext.randomResourceName("rg", 13);
    Region region = Region.US_EAST;
    String name = SdkContext.randomResourceName("ag", 15);
    ApplicationGateway appGateway = azure.applicationGateways().define(name)
            .withRegion(region)
            .withNewResourceGroup(rgName)

            // Request routing rules
            .defineRequestRoutingRule("rule1")
            .fromPrivateFrontend()
            .fromFrontendHttpPort(80)
            .toBackendHttpPort(8080)
            .toBackendIPAddress("11.1.1.1")
            .toBackendIPAddress("11.1.1.2")
            .attach()
            .create();

    // Test stop/start
    appGateway.stop();
    Assert.assertEquals(ApplicationGatewayOperationalState.STOPPED, appGateway.operationalState());
    appGateway.start();
    Assert.assertEquals(ApplicationGatewayOperationalState.RUNNING, appGateway.operationalState());

    azure.resourceGroups().beginDeleteByName(rgName);
}
 
Example #12
Source File: DeploymentsTests.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
protected void initializeClients(RestClient restClient, String defaultSubscription, String domain) {
    super.initializeClients(restClient, defaultSubscription, domain);
    testId = SdkContext.randomResourceName("", 9);
    resourceGroups = resourceClient.resourceGroups();
    rgName = "rg" + testId;
    resourceGroup = resourceGroups.define(rgName)
            .withRegion(Region.US_SOUTH_CENTRAL)
            .create();
}
 
Example #13
Source File: TestPublicIPAddress.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public PublicIPAddress createResource(PublicIPAddresses pips) throws Exception {
    final String newPipName = "pip" + this.testId;
    PublicIPAddress pip = pips.define(newPipName)
            .withRegion(Region.US_WEST)
            .withNewResourceGroup()
            .withDynamicIP()
            .withLeafDomainLabel(newPipName)
            .withIdleTimeoutInMinutes(10)
            .create();
    return pip;
}
 
Example #14
Source File: WebAppsWebDeployTests.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Test
public void canDeployWarFile() throws Exception {
    // Create with new app service plan
    WebApp webApp1 = appServiceManager.webApps().define(WEBAPP_NAME_1)
            .withRegion(Region.US_WEST)
            .withNewResourceGroup(RG_NAME_1)
            .withNewWindowsPlan(PricingTier.BASIC_B1)
            .withJavaVersion(JavaVersion.JAVA_8_NEWEST)
            .withWebContainer(WebContainer.TOMCAT_8_0_NEWEST)
            .create();
    Assert.assertNotNull(webApp1);
    Assert.assertEquals(Region.US_WEST, webApp1.region());
    AppServicePlan plan1 = appServiceManager.appServicePlans().getById(webApp1.appServicePlanId());
    Assert.assertNotNull(plan1);
    Assert.assertEquals(Region.US_WEST, plan1.region());
    Assert.assertEquals(PricingTier.BASIC_B1, plan1.pricingTier());

    WebDeployment deployment = webApp1.deploy()
            .withPackageUri("https://github.com/Azure/azure-libraries-for-java/raw/master/azure-mgmt-appservice/src/test/resources/webapps.zip")
            .withExistingDeploymentsDeleted(true)
            .execute();

    Assert.assertNotNull(deployment);
    if (!isPlaybackMode()) {
        SdkContext.sleep(10000);
        Response response = curl("http://" + webApp1.defaultHostName() + "/helloworld");
        Assert.assertEquals(200, response.code());
        String body = response.body().string();
        Assert.assertNotNull(body);
        Assert.assertTrue(body.contains("Current time:"));
    }
}
 
Example #15
Source File: AppServiceTest.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private static void createNewDomainAndCertificate() {
    domain = appServiceManager.domains().define(System.getenv("appservice-domain"))
            .withExistingResourceGroup(System.getenv("appservice-group"))
            .defineRegistrantContact()
                .withFirstName("Jon")
                .withLastName("Doe")
                .withEmail("[email protected]")
                .withAddressLine1("123 4th Ave")
                .withCity("Redmond")
                .withStateOrProvince("WA")
                .withCountry(CountryIsoCode.UNITED_STATES)
                .withPostalCode("98052")
                .withPhoneCountryCode(CountryPhoneCode.UNITED_STATES)
                .withPhoneNumber("4258828080")
                .attach()
            .withDomainPrivacyEnabled(true)
            .withAutoRenewEnabled(true)
            .create();
    certificateOrder = appServiceManager.certificateOrders()
            .define(System.getenv("appservice-certificateorder"))
            .withExistingResourceGroup(System.getenv("appservice-group"))
            .withHostName("*." + domain.name())
            .withWildcardSku()
            .withDomainVerification(domain)
            .withNewKeyVault("graphvault", Region.US_WEST)
            .withValidYears(1)
            .create();
}
 
Example #16
Source File: FunctionAppsTests.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Test
public void canCRUDLinuxFunctionAppPremium() {
    RG_NAME_2 = null;

    // function app with premium plan
    FunctionApp functionApp1 = appServiceManager.functionApps().define(WEBAPP_NAME_1)
            .withRegion(Region.US_EAST)
            .withNewResourceGroup(RG_NAME_1)
            .withNewLinuxAppServicePlan(new PricingTier(com.microsoft.azure.management.appservice.SkuName.ELASTIC_PREMIUM.toString(), "EP1"))
            .withBuiltInImage(FunctionRuntimeStack.JAVA_8)
            .withHttpsOnly(true)
            .withAppSetting("WEBSITE_RUN_FROM_PACKAGE", FUNCTION_APP_PACKAGE_URL)
            .create();
    Assert.assertNotNull(functionApp1);
    AppServicePlan plan1 = appServiceManager.appServicePlans().getById(functionApp1.appServicePlanId());
    Assert.assertNotNull(plan1);
    Assert.assertEquals(new PricingTier(com.microsoft.azure.management.appservice.SkuName.ELASTIC_PREMIUM.toString(), "EP1"), plan1.pricingTier());
    Assert.assertTrue(plan1.inner().reserved());
    assertLinuxJava(functionApp1, FunctionRuntimeStack.JAVA_8.getLinuxFxVersionForDedicatedPlan());

    // wait for deploy
    if (!isPlaybackMode()) {
        SdkContext.sleep(180000);
    }

    // verify deploy
    List<FunctionEnvelope> functions = appServiceManager.functionApps().listFunctions(functionApp1.resourceGroupName(), functionApp1.name());
    Assert.assertEquals(1, functions.size());
}
 
Example #17
Source File: TopicAuthorizationRulesImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
TopicAuthorizationRulesImpl(String resourceGroupName,
                            String namespaceName,
                            String topicName,
                            Region region,
                            ServiceBusManager manager) {
    super(manager.inner().topics(), manager);
    this.resourceGroupName = resourceGroupName;
    this.namespaceName = namespaceName;
    this.topicName = topicName;
    this.region = region;
}
 
Example #18
Source File: DeploymentImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public DeploymentImpl withNewResourceGroup(String resourceGroupName, Region region) {
    this.creatableResourceGroup = this.resourceManager.resourceGroups()
            .define(resourceGroupName)
            .withRegion(region);
    this.addDependency(this.creatableResourceGroup);
    this.resourceGroupName = resourceGroupName;
    return this;
}
 
Example #19
Source File: TestVirtualMachine.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public VirtualMachine createResource(VirtualMachines virtualMachines) throws Exception {
    final String vmName = "vm" + this.testId;
    final VirtualMachine[] vms = new VirtualMachine[1];
    final SettableFuture<VirtualMachine> future = SettableFuture.create();

    Observable<Indexable> resourceStream = virtualMachines.define(vmName)
            .withRegion(Region.US_EAST)
            .withNewResourceGroup()
            .withNewPrimaryNetwork("10.0.0.0/28")
            .withPrimaryPrivateIPAddressDynamic()
            .withoutPrimaryPublicIPAddress()
            .withPopularWindowsImage(KnownWindowsVirtualMachineImage.WINDOWS_SERVER_2012_R2_DATACENTER)
            .withAdminUsername("testuser")
            .withAdminPassword("12NewPA$$w0rd!")
            .withNewDataDisk(150)
            .withSize(VirtualMachineSizeTypes.STANDARD_D1_V2)
            .createAsync();

    Utils.<VirtualMachine>rootResource(resourceStream)
            .subscribe(new Action1<VirtualMachine>() {
                @Override
                public void call(VirtualMachine virtualMachine) {
                    future.set(virtualMachine);
                }
            });
    vms[0] = future.get();

    Assert.assertEquals(1, vms[0].dataDisks().size());
    VirtualMachineDataDisk dataDisk = vms[0].dataDisks().values().iterator().next();
    Assert.assertEquals(150, dataDisk.size());
    Assert.assertEquals(128, vms[0].osDiskSize());
    Disk osDisk = virtualMachines.manager().disks().getById(vms[0].osDiskId());
    Assert.assertNotNull(osDisk);
    Assert.assertEquals(128, osDisk.sizeInGB());

    return vms[0];
}
 
Example #20
Source File: CosmosDBAccountImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public CosmosDBAccountImpl withWriteReplication(Region region) {
    FailoverPolicy failoverPolicyInner = new FailoverPolicy();
    failoverPolicyInner.withLocationName(region.name());
    this.hasFailoverPolicyChanges = true;
    this.failoverPolicies.add(failoverPolicyInner);
    return this;
}
 
Example #21
Source File: ManageWebAppWithTrafficManager.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private static AppServicePlan createAppServicePlan(String name, Region region) {
    return azure.appServices().appServicePlans().define(name)
            .withRegion(region)
            .withExistingResourceGroup(RG_NAME)
            .withPricingTier(PricingTier.STANDARD_S1)
            .withOperatingSystem(OperatingSystem.WINDOWS)
            .create();
}
 
Example #22
Source File: QueueAuthorizationRuleImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
QueueAuthorizationRuleImpl(String resourceGroupName,
                           String namespaceName,
                           String queueName,
                           String name,
                           Region region,
                           SharedAccessAuthorizationRuleInner inner,
                           ServiceBusManager manager) {
    super(name, inner, manager);
    this.namespaceName = namespaceName;
    this.region = region;
    this.withExistingParentResource(resourceGroupName, queueName);
    if (inner.location() == null) {
        inner.withLocation(this.region.toString());
    }
}
 
Example #23
Source File: TestBatchAI.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private static String ensureStorageAccount(StorageAccounts storageAccounts, String saName, String rgName, String shareName) throws Exception {
    StorageAccount storageAccount = storageAccounts.define(saName)
            .withRegion(Region.US_WEST)
            .withExistingResourceGroup(rgName)
            .create();

    return storageAccount.getKeys().get(0).value();
}
 
Example #24
Source File: VirtualMachinePublishersImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
protected VirtualMachinePublisherImpl wrapModel(VirtualMachineImageResourceInner inner) {
    if (inner == null) {
        return null;
    }
    return new VirtualMachinePublisherImpl(Region.fromName(inner.location()),
            inner.name(),
            this.imagesInnerCollection,
            this.extensionsInnerCollection);
}
 
Example #25
Source File: AzureTests.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@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());
}
 
Example #26
Source File: SharedGalleryImageTests.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private VirtualMachineCustomImage prepareCustomImage(String rgName, Region region, ComputeManager computeManager) {
    VirtualMachine linuxVM = prepareGeneralizedVmWith2EmptyDataDisks(rgName,
            generateRandomResourceName("muldvm", 15),
            region,
            computeManager);

    final String vhdBasedImageName = generateRandomResourceName("img", 20);
    //
    VirtualMachineCustomImage.DefinitionStages.WithCreateAndDataDiskImageOSDiskSettings
            creatableDisk = computeManager
            .virtualMachineCustomImages()
            .define(vhdBasedImageName)
            .withRegion(region)
            .withNewResourceGroup(rgName)
            .withLinuxFromVhd(linuxVM.osUnmanagedDiskVhdUri(), OperatingSystemStateTypes.GENERALIZED)
            .withOSDiskCaching(linuxVM.osDiskCachingType());
    for (VirtualMachineUnmanagedDataDisk disk : linuxVM.unmanagedDataDisks().values()) {
        creatableDisk.defineDataDiskImage()
                .withLun(disk.lun())
                .fromVhd(disk.vhdUri())
                .withDiskCaching(disk.cachingType())
                .withDiskSizeInGB(disk.size() + 10) // Resize each data disk image by +10GB
                .attach();
    }
    //
    VirtualMachineCustomImage customImage = creatableDisk.create();
    return customImage;
}
 
Example #27
Source File: AzureClient.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
public Collection<Region> getRegion(com.sequenceiq.cloudbreak.cloud.model.Region region) {
    Collection<Region> resultList = new HashSet<>();
    for (Region tmpRegion : Region.values()) {
        if (region == null || Strings.isNullOrEmpty(region.value())
                || tmpRegion.name().equals(region.value()) || tmpRegion.label().equals(region.value())) {
            resultList.add(tmpRegion);
        }
    }
    return resultList;
}
 
Example #28
Source File: ComputeSkusImpl.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
@Override
public Observable<ComputeSku> listByRegionAsync(final Region region) {
    return this.listAsync()
            .filter(new Func1<ComputeSku, Boolean>() {
                @Override
                public Boolean call(ComputeSku computeSku) {
                    return computeSku.regions() != null && computeSku.regions().contains(region);
                }
            });
}
 
Example #29
Source File: ManageManagedDisks.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private static VirtualMachine prepareSpecializedManagedVirtualMachine(Azure azure, Region region, String rgName) {
    final String userName = "tirekicker";
    // [SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine", Justification="Serves as an example, not for deployment. Please change when using this in your code.")]
    final String password = "12NewPA$$w0rd!";
    final String linuxVMName1 = SdkContext.randomResourceName("vm" + "-", 10);
    final String publicIPDnsLabel = SdkContext.randomResourceName("pip" + "-", 20);

    VirtualMachine linuxVM = azure.virtualMachines().define(linuxVMName1)
            .withRegion(region)
            .withNewResourceGroup(rgName)
            .withNewPrimaryNetwork("10.0.0.0/28")
            .withPrimaryPrivateIPAddressDynamic()
            .withNewPrimaryPublicIPAddress(publicIPDnsLabel)
            .withPopularLinuxImage(KnownLinuxVirtualMachineImage.UBUNTU_SERVER_16_04_LTS)
            .withRootUsername(userName)
            .withRootPassword(password)
            .withNewDataDisk(100)
            .withNewDataDisk(200)
            .withSize(VirtualMachineSizeTypes.STANDARD_D3_V2)
            .create();

    // De-provision the virtual machine
    deprovisionAgentInLinuxVM(linuxVM.getPrimaryPublicIPAddress().fqdn(), 22, userName, password);
    System.out.println("Deallocate VM: " + linuxVM.id());
    linuxVM.deallocate();
    System.out.println("Deallocated VM: " + linuxVM.id() + "; state = " + linuxVM.powerState());
    System.out.println("Generalize VM: " + linuxVM.id());
    linuxVM.generalize();
    System.out.println("Generalized VM: " + linuxVM.id());
    return linuxVM;
}
 
Example #30
Source File: ListComputeSkus.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private static String regionZoneToString(Map<Region, Set<AvailabilityZoneId>> regionZonesMap) {
    StringBuilder builder = new StringBuilder();
    for (Map.Entry<Region, Set<AvailabilityZoneId>> regionZones : regionZonesMap.entrySet()) {
        builder.append(regionZones.getKey().toString());
        builder.append(" [ ");
        for (AvailabilityZoneId zone :regionZones.getValue()) {
            builder.append(zone).append(" ");
        }
        builder.append("] ");
    }
    return builder.toString();
}