Search in sources :

Example 1 with CheckNameAvailabilityResult

use of com.azure.resourcemanager.storage.models.CheckNameAvailabilityResult in project azure-maven-plugins by microsoft.

the class AzureStorageAccount method checkNameAvailability.

public CheckNameAvailabilityResultEntity checkNameAvailability(String subscriptionId, String name) {
    StorageManager manager = StorageManagerFactory.create(subscriptionId);
    CheckNameAvailabilityResult result = manager.storageAccounts().checkNameAvailability(name);
    return new CheckNameAvailabilityResultEntity(result.isAvailable(), Optional.ofNullable(result.reason()).map(Reason::toString).orElse(null), result.message());
}
Also used : StorageManager(com.azure.resourcemanager.storage.StorageManager) CheckNameAvailabilityResult(com.azure.resourcemanager.storage.models.CheckNameAvailabilityResult) CheckNameAvailabilityResultEntity(com.microsoft.azure.toolkit.lib.common.entity.CheckNameAvailabilityResultEntity) Reason(com.azure.resourcemanager.storage.models.Reason)

Example 2 with CheckNameAvailabilityResult

use of com.azure.resourcemanager.storage.models.CheckNameAvailabilityResult in project azure-vm-agents-plugin by jenkinsci.

the class AzureVMManagementServiceDelegate method verifyStorageAccountName.

public String verifyStorageAccountName(String resourceGroupName, String storageAccountName, String storageAccountType) {
    boolean isAvailable = false;
    try {
        if (StringUtils.isBlank(storageAccountType)) {
            return Messages.Azure_GC_Template_SA_Type_Null_Or_Empty();
        }
        CheckNameAvailabilityResult checkResult = azureClient.storageAccounts().checkNameAvailability(storageAccountName);
        isAvailable = checkResult.isAvailable();
        if (!isAvailable && Reason.ACCOUNT_NAME_INVALID.equals(checkResult.reason())) {
            return Messages.Azure_GC_Template_SA_Not_Valid();
        } else if (!isAvailable) {
            /*if it's not available we need to check if it's already in our resource group*/
            StorageAccount checkAccount = azureClient.storageAccounts().getByResourceGroup(resourceGroupName, storageAccountName);
            if (null == checkAccount) {
                return Messages.Azure_GC_Template_SA_Already_Exists();
            } else {
                /*if the storage account is already in out resource group, check whether they are the same type*/
                if (checkAccount.skuType().name().toString().equalsIgnoreCase(storageAccountType)) {
                    return Constants.OP_SUCCESS;
                } else {
                    return Messages.Azure_GC_Template_SA_Type_Not_Match(storageAccountType, checkAccount.skuType().name().toString());
                }
            }
        } else {
            return Constants.OP_SUCCESS;
        }
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Verification failed for storage account name", e);
        return Messages.Azure_GC_Template_SA_Already_Exists();
    }
}
Also used : StorageAccount(com.azure.resourcemanager.storage.models.StorageAccount) CheckNameAvailabilityResult(com.azure.resourcemanager.storage.models.CheckNameAvailabilityResult) AzureCloudException(com.microsoft.azure.vmagent.exceptions.AzureCloudException) FormException(hudson.model.Descriptor.FormException) ManagementException(com.azure.core.management.exception.ManagementException) IOException(java.io.IOException)

Aggregations

CheckNameAvailabilityResult (com.azure.resourcemanager.storage.models.CheckNameAvailabilityResult)2 ManagementException (com.azure.core.management.exception.ManagementException)1 StorageManager (com.azure.resourcemanager.storage.StorageManager)1 Reason (com.azure.resourcemanager.storage.models.Reason)1 StorageAccount (com.azure.resourcemanager.storage.models.StorageAccount)1 CheckNameAvailabilityResultEntity (com.microsoft.azure.toolkit.lib.common.entity.CheckNameAvailabilityResultEntity)1 AzureCloudException (com.microsoft.azure.vmagent.exceptions.AzureCloudException)1 FormException (hudson.model.Descriptor.FormException)1 IOException (java.io.IOException)1