private DataContainer ConvertToDataContainer(MigrationDataContainer dataContainer) { DataContainer dc = new DataContainer(); dc.BandwidthRate = dataContainer.BandwidthSetting.Schedules[0].Rate; dc.EncryptionKey = dataContainer.EncryptionKey; dc.InstanceId = dataContainer.InstanceId; dc.IsDefault = dataContainer.IsDefault; dc.IsEncryptionEnabled = !string.IsNullOrEmpty(dataContainer.EncryptionKey); dc.Name = dataContainer.Name; dc.OperationInProgress = dataContainer.OperationInProgress; dc.Owned = dataContainer.Owned; dc.PrimaryStorageAccountCredential = this.ConvertToSACResponse(dataContainer.PrimaryStorageAccountCredential); dc.VolumeCount = 0; return dc; }
private List<MigrationDataContainer> ParseVolumeContainer(XmlDocument document) { List<MigrationDataContainer> dataContainerList = new List<MigrationDataContainer>(); XmlNodeList nodeList = document.SelectNodes(@"//VolumeContainer"); foreach (XmlNode node in nodeList) { MigrationDataContainer volumeContainer = new MigrationDataContainer(); volumeContainer.Name = node.Attributes["Name"].Value; volumeContainer.InstanceId = node.Attributes["Id"].Value; volumeContainer.BandwidthSetting = new BandwidthSetting() { InstanceId = node.Attributes["BandwidthTempateId"].Value }; volumeContainer.EncryptionKey = node.Attributes["EncryptionKey"].Value; volumeContainer.SecretsEncryptionThumbprint = node.Attributes["SecretEncryptionThumbPrint"].Value; foreach (XmlNode childNode in node.ChildNodes) { if ("PrimaryBucket" == childNode.Name) { volumeContainer.PrimaryBucket = childNode.Attributes["Name"].Value; volumeContainer.PrimaryStorageAccountCredential = new StorageAccountCredential() { InstanceId = childNode.Attributes["CredentialId"].Value }; } else if ("BackupBucket" == childNode.Name) { volumeContainer.BackupBucket = childNode.Attributes["Name"].Value; volumeContainer.BackupStorageAccountCredential = new StorageAccountCredential() { InstanceId = childNode.Attributes["CredentialId"].Value }; } } dataContainerList.Add(volumeContainer); } return dataContainerList; }
/// <summary> /// Parse data container /// </summary> private void ParseDataContainers() { this.dataContainerList = new List<DataContainer>(); this.migrationDataContainerList = new List<MigrationDataContainer>(); var cloudConfigurationsList = this.GetSubElements(doc.Root, "CloudConfigurations"); foreach (var cloudConfigurations in cloudConfigurationsList) { var cloudConfigurationInfoList = this.GetSubElements(cloudConfigurations, "CloudConfigurationInfo"); foreach (var cloudConfigurationInfo in cloudConfigurationInfoList) { DataContainer dataContainer = new DataContainer(); MigrationDataContainer migrationDataContainer = new MigrationDataContainer(); string bandwidthSettingID = string.Empty; bool bandwidthSettingAddStatus = true; foreach (var dataContainerProperty in cloudConfigurationInfo.Elements()) { switch (dataContainerProperty.Name.LocalName) { case "Alias": { dataContainer.Name = dataContainerProperty.Value; migrationDataContainer.Name = dataContainer.Name; break; } case "PrimaryBucket": { string Id = GetSubElements(dataContainerProperty, "CredentialId").First().Value; StorageAccountCredential primarySAC = this.storageAcctCredList.Find(sac => sac.InstanceId == Id); if (null != primarySAC) { dataContainer.PrimaryStorageAccountCredential = ConvertToSACResponse(primarySAC); migrationDataContainer.PrimaryStorageAccountCredential = primarySAC; } else { throw new MissingMemberException( string.Format(Resources.MigrationExpectedSACNotFound, Id)); } migrationDataContainer.PrimaryBucket = GetSubElements(dataContainerProperty, "Name").First().Value; break; } case "BackupBucket": { string Id = GetSubElements(dataContainerProperty, "CredentialId").First().Value; StorageAccountCredential backupSAC = this.storageAcctCredList.Find(sac => sac.InstanceId == Id); if (null != backupSAC) { migrationDataContainer.BackupStorageAccountCredential = backupSAC; } else { throw new MissingMemberException( string.Format(Resources.MigrationExpectedSACNotFound, Id)); } migrationDataContainer.BackupBucket = GetSubElements(dataContainerProperty, "Name").First().Value; break; } case "QosTemplateId": { migrationDataContainer.BandwidthSetting = this.bandwidthSettingList.Find( setting => setting.InstanceId == dataContainerProperty.Value); if (null != migrationDataContainer.BandwidthSetting && null != migrationDataContainer.BandwidthSetting.Schedules && 0 < migrationDataContainer.BandwidthSetting.Schedules.Count) { dataContainer.BandwidthRate = migrationDataContainer.BandwidthSetting.Schedules[0].Rate; } else { bandwidthSettingAddStatus = false; } break; } case "EncryptionKey": { string encryptedEncryptionKey = string.Empty; dataContainer.IsEncryptionEnabled = !String.IsNullOrEmpty(dataContainerProperty.Value); if (dataContainer.IsEncryptionEnabled) { dataContainer.EncryptionKey = this.serviceSecretEncryptor.EncryptSecret(dataContainerProperty.Value); dataContainer.SecretsEncryptionThumbprint = this.serviceSecretEncryptor.GetSecretsEncryptionThumbprint(); } else { dataContainer.EncryptionKey = string.Empty; dataContainer.SecretsEncryptionThumbprint = string.Empty; } dataContainer.IsEncryptionEnabled = !String.IsNullOrEmpty(dataContainerProperty.Value); migrationDataContainer.EncryptionKey = dataContainer.EncryptionKey; migrationDataContainer.SecretsEncryptionThumbprint = dataContainer.SecretsEncryptionThumbprint; break; } case "Id": { dataContainer.InstanceId = dataContainerProperty.Value; migrationDataContainer.InstanceId = dataContainer.InstanceId; break; } default: { break; } } } // below properties are a not a part of legacy appliance config filling with default value. dataContainer.OperationInProgress = migrationDataContainer.OperationInProgress = OperationInProgress.None; dataContainer.VolumeCount = -1; dataContainer.IsDefault = migrationDataContainer.IsDefault = false; dataContainer.Owned = migrationDataContainer.Owned = true; migrationDataContainer.SecretsEncryptionThumbprint = migrationDataContainer.PrimaryStorageAccountCredential.PasswordEncryptionCertThumbprint; if (!bandwidthSettingAddStatus) { this.AddMessage(LegacyObjectsSupported.DataContainer, Resources.MigrationAssociatedBandwidthSettingIncomplete, dataContainer.Name, MessageType.Warning); } this.dataContainerList.Add(dataContainer); this.migrationDataContainerList.Add(migrationDataContainer); } } }