public EnvironmentStorageConfigModel(RenderManagerType renderManagerType, StorageProperties storageProps) { RenderManagerType = renderManagerType; AccountName = storageProps.AccountName; Uri = storageProps.Uri; PrimaryKey = storageProps.PrimaryKey; SecondaryKey = storageProps.SecondaryKey; FileShares = storageProps.Shares; }
/// <summary> /// Fetch the storage properties for a storage resource. /// </summary> /// <param name="storageResource">The Storage resource</param> /// <returns> Returns the storage properties </returns> private StorageProperties GetStoragePropertiesForStorageResource(Resource storageResource) { StorageProperties storageProp = null; try { storageProp = storageResource.Properties.ToObject <StorageProperties>(); } catch (Exception) { // Do nothing storageProp = null; } return(storageProp); }
internal static StorageResourceData DeserializeStorageResourceData(JsonElement element) { Optional <StorageProperties> properties = default; ResourceIdentifier id = default; string name = default; ResourceType type = default; SystemData systemData = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("properties")) { if (property.Value.ValueKind == JsonValueKind.Null) { property.ThrowNonNullablePropertyIsNull(); continue; } properties = StorageProperties.DeserializeStorageProperties(property.Value); continue; } if (property.NameEquals("id")) { id = new ResourceIdentifier(property.Value.GetString()); continue; } if (property.NameEquals("name")) { name = property.Value.GetString(); continue; } if (property.NameEquals("type")) { type = new ResourceType(property.Value.GetString()); continue; } if (property.NameEquals("systemData")) { systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString()); continue; } } return(new StorageResourceData(id, name, type, systemData, properties.Value)); }
/// <summary> /// Gets the resource components for the Diagnostics if applicable/enabled for the Virtual machine resource. /// </summary> /// <returns> Returns the list of resource components </returns> private List <ResourceComponent> GetResourceComponentForDiagnostics() { List <ResourceComponent> componentList = new List <ResourceComponent>(); string diagnosticsEnabled = null; if (this.prop.DiagnosticsProfile != null && this.prop.DiagnosticsProfile.BootDiagnostics != null) { // Fetch the Enabled property for Diagnostics of the VM resource diagnosticsEnabled = this.prop.DiagnosticsProfile.BootDiagnostics.Enabled; } if (diagnosticsEnabled != null && diagnosticsEnabled.Equals("true", StringComparison.OrdinalIgnoreCase)) { // Get list of all storage resources in template List <Resource> storageResourceList = this.template.Resources.FindAll(x => ARMResourceTypeConstants.ARMStorageResourceType.Equals(x.Type, StringComparison.OrdinalIgnoreCase)); string diagnosticsStorageURI = null; if (this.prop.DiagnosticsProfile != null && this.prop.DiagnosticsProfile.BootDiagnostics != null) { // Fetch the URI of Diagnostics diagnosticsStorageURI = this.prop.DiagnosticsProfile.BootDiagnostics.StorageUri; } Resource diagnosticsStorageResource = null; if (diagnosticsStorageResource != null) { diagnosticsStorageResource = PropertyHelper.SearchResourceInListByName(storageResourceList, diagnosticsStorageURI); } string storageAccountType = null; StorageProperties storageProp = null; if (diagnosticsStorageResource != null && diagnosticsStorageResource.Properties != null) { // Get the Properties of the Storage Resource associated with storing the Diagnostics of the VM storageProp = this.GetStoragePropertiesForStorageResource(diagnosticsStorageResource); } if (storageProp != null) { // Get the Storage Account Type storageAccountType = PropertyHelper.GetValueIfVariableOrParam(storageProp.AccountType, this.template.Variables, this.template.Parameters, this.paramValue.Parameters); } // Use Default Storage Account Type, as template may be using existing storage account if (storageAccountType == null) { storageAccountType = StorageResourceConstants.StorageDefaultAccountType; } if (storageAccountType != null && storageAccountType != StorageResourceConstants.StoragePremiumAccountType) { // Create the resource component for Diagnostics ResourceComponent diagnosticsComponent = new ResourceComponent { ResourceType = this.resource.Type, MeterCategory = StorageResourceConstants.StorageMeterCategory, MeterSubCategory = null, MeterName = StorageResourceConstants.StorageMeterNameForTable, Quantity = VMResourceConstants.StorageDiagnosticsTableSize, IsChargeable = true }; string meterSubCategory = null; // Set the Meter SubCategory based on the Storage Account Type if (StorageResourceConstants.StorageTypeAndMeterSubCategoryMap.TryGetValue(storageAccountType, out meterSubCategory)) { diagnosticsComponent.MeterSubCategory = meterSubCategory; } else { throw new Exception(ExceptionLogger.GenerateLoggerTextForInvalidField("StorageAccountType", storageAccountType, this.nameOfResource)); } componentList.Add(diagnosticsComponent); // Add the Storage Transactions component componentList.Add(new ResourceComponent() { ResourceType = this.resource.Type, MeterCategory = StorageResourceConstants.DataManagementMeterCategory, MeterSubCategory = StorageResourceConstants.DataManagementMeterSubCategoryForVMDisk, MeterName = StorageResourceConstants.DataManagementMeterNameForStorageTrans, Quantity = VMResourceConstants.DataManagementVMDiagnosticsStorageTrans, IsChargeable = true }); } else { throw new Exception(ExceptionLogger.GenerateLoggerTextForInvalidField("StorageAccountType for Diagnostics", storageAccountType, this.nameOfResource)); } } return(componentList); }
/// <summary> /// Gets the resource components for the Disks of the Virtual machine resource. /// </summary> /// <param name="diskURI">The URI of the disk</param> /// <param name="diskSize">The size of the Disk</param> /// <param name="storageResourceList">The list of storage resources in the ARM Template</param> /// <param name="isOSDisk">Set true for OS Disk and false for Data Disk</param> /// <returns> Returns the list of resource components </returns> private List <ResourceComponent> GetResourceComponentForDiskStorage(string diskURI, string diskSize, List <Resource> storageResourceList, bool isOSDisk) { List <ResourceComponent> storageComponentList = new List <ResourceComponent>(); List <ResourceComponent> storageDiskComponentList = new List <ResourceComponent>(); List <ResourceComponent> storageTransactionComponentList = new List <ResourceComponent>(); // Get the Storage resource corresponding to the Storage of the Disk of the VM Resource diskStorageResource = PropertyHelper.SearchResourceInListByName(storageResourceList, diskURI); // Create the resource component for Storage of the VM disk, MeterSubCategory and MeterName will be set later ResourceComponent storageDiskComponent = new ResourceComponent { ResourceType = this.resource.Type, MeterCategory = StorageResourceConstants.StorageMeterCategory, MeterSubCategory = null, MeterName = null, IsChargeable = true }; string storageAccountType = null; bool isPremiumStorage = false; StorageProperties storageProp = null; if (diskStorageResource != null && diskStorageResource.Properties != null) { // Get properties of the Storage resource storageProp = this.GetStoragePropertiesForStorageResource(diskStorageResource); } if (storageProp != null) { // Get Account Type of the Storage resource storageAccountType = PropertyHelper.GetValueIfVariableOrParam(storageProp.AccountType, this.template.Variables, this.template.Parameters, this.paramValue.Parameters); } // If Unable to fetch Storage Account Type, then, the template may be using existing storage account, Take Default Storage Account Type if (storageAccountType == null) { storageAccountType = StorageResourceConstants.StorageDefaultAccountType; } string meterSubCategory = null; // Set the Meter SubCategory based on the Storage Account Type if (StorageResourceConstants.StorageTypeAndMeterSubCategoryMap.TryGetValue(storageAccountType, out meterSubCategory)) { storageDiskComponent.MeterSubCategory = meterSubCategory; } else { throw new Exception(ExceptionLogger.GenerateLoggerTextForInvalidField("StorageAccountType", storageAccountType, this.nameOfResource)); } // Check if premium storage is used if (storageAccountType.Equals(StorageResourceConstants.StoragePremiumAccountType, StringComparison.OrdinalIgnoreCase)) { isPremiumStorage = true; } double diskQuantity = 0; if (isOSDisk) { // Get default Storage for OS Disk from Constants/Config diskQuantity = isPremiumStorage ? VMResourceConstants.StoragePremiumOSDiskSize : VMResourceConstants.StorageOSDiskSize; } else { // Get the Storage size for the Data Disk double dataDiskQuantityValue = 0; if (diskSize != null && double.TryParse(diskSize, out dataDiskQuantityValue)) { if (isPremiumStorage) { // If Premium Storage, Map the disk size to the next greater available size of premium disk for (int i = 0; i < StorageResourceConstants.StoragePremiumDiskValuesArray.Count(); i++) { double premiumDiskSizeValue = StorageResourceConstants.StoragePremiumDiskValuesArray[i]; if ((dataDiskQuantityValue <= premiumDiskSizeValue) || (i == StorageResourceConstants.StoragePremiumDiskValuesArray.Count() - 1)) { diskQuantity = premiumDiskSizeValue; break; } } } else { diskQuantity = dataDiskQuantityValue < VMResourceConstants.StorageDataDiskSize ? dataDiskQuantityValue : VMResourceConstants.StorageDataDiskSize; } } } // Set the meter name for the Disk resource based on premium and standard if (isPremiumStorage) { string meterName = null; if (StorageResourceConstants.StoragePremiumDiskSizeAndMeterNameMap.TryGetValue(diskQuantity, out meterName)) { storageDiskComponent.MeterName = meterName; } } else { storageDiskComponent.MeterName = StorageResourceConstants.StorageMeterNameForVMDisk; } // Set the Quantity of the component to the Disk Size, Set 1 if its premium disk storageDiskComponent.Quantity = isPremiumStorage ? 1 : diskQuantity; storageComponentList.Add(storageDiskComponent); if (!isPremiumStorage) { // Add Storage transactions component if not a premium disk storageTransactionComponentList.Add(new ResourceComponent() { ResourceType = this.resource.Type, MeterCategory = StorageResourceConstants.DataManagementMeterCategory, MeterSubCategory = StorageResourceConstants.DataManagementMeterSubCategoryForVMDisk, MeterName = StorageResourceConstants.DataManagementMeterNameForStorageTrans, Quantity = isOSDisk ? VMResourceConstants.DataManagementVMStorageOSDiskTrans : VMResourceConstants.DataManagementVMStorageDataDiskTrans, IsChargeable = true }); } // Add the list of components obtained for the Storage Disk of the VM resource storageComponentList.AddRange(storageDiskComponentList); storageComponentList.AddRange(storageTransactionComponentList); return(storageComponentList); }
internal StorageResourceData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, StorageProperties properties) : base(id, name, resourceType, systemData) { Properties = properties; }