Exemple #1
0
        /// <summary>
        /// Exports Subscription metadata.
        /// </summary>
        /// <returns>Subscription details/></returns>
        internal Subscription ExportSubscriptionMetadata()
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            Logger.Info(methodName, ProgressResources.ExecutionStarted);
            Subscription subscription = new Subscription()
            {
                Name = exportParameters.SourceSubscriptionSettings.Name
            };

            Logger.Info(methodName, string.Format(ProgressResources.ExportDataCenterStarted, exportParameters.SourceDCName), ResourceType.DataCenter.ToString(), exportParameters.SourceDCName);
            dcMigration.ReportProgress(string.Format(ProgressResources.ExportDataCenterStarted, exportParameters.SourceDCName));

            AffinityGroupListResponse       affinityGroupResponse  = GetAffinityGroupListResponseFromMSAzure(exportParameters.SourceSubscriptionSettings.Credentials);
            HostedServiceListResponse       cloudserviceResponse   = GetCloudServiceListResponseFromMSAzure(exportParameters.SourceSubscriptionSettings.Credentials, exportParameters.SourceSubscriptionSettings.ServiceUrl);
            NetworkGetConfigurationResponse networkResponse        = GetNetworkConfigurationFromMSAzure(exportParameters.SourceSubscriptionSettings.Credentials, exportParameters.SourceSubscriptionSettings.ServiceUrl);
            StorageAccountListResponse      storageAccountResponse = GetStorageAccountListResponseFromMSAzure(exportParameters.SourceSubscriptionSettings.Credentials);

            // Create an instance of data center.
            var dataCenter = new DataCenter
            {
                LocationName = exportParameters.SourceDCName,
            };

            // Get all affinity groups.
            Logger.Info(methodName, ProgressResources.ExportAffinityGroupStarted, ResourceType.AffinityGroup.ToString());
            dcMigration.ReportProgress(ProgressResources.ExportAffinityGroupStarted);

            var affinityGroups = ExportAffinityGroups(affinityGroupResponse);

            dataCenter.AffinityGroups.AddRange(affinityGroups.ToList());
            int stageCount = 1;

            Logger.Info(methodName, string.Format(ProgressResources.CompletedStages, stageCount, Constants.ExportTotalStages));
            dcMigration.ReportProgress(string.Format(ProgressResources.CompletedStages, stageCount, Constants.ExportTotalStages));

            List <string> affinityGroupNamesInDC = affinityGroups.Select(ag => ag.AffinityGroupDetails.Name).ToList();

            Logger.Info(methodName, ProgressResources.ExportVNetConfigurationStarted, ResourceType.VirtualNetwork.ToString());
            dcMigration.ReportProgress(ProgressResources.ExportVNetConfigurationStarted);

            // Filter and Export network configuration file.
            dataCenter.NetworkConfiguration = ExportVNetConfiguration(networkResponse, affinityGroupNamesInDC);
            Logger.Info(methodName, string.Format(ProgressResources.CompletedStages, ++stageCount, Constants.ExportTotalStages));
            dcMigration.ReportProgress(string.Format(ProgressResources.CompletedStages, stageCount, Constants.ExportTotalStages));

            Logger.Info(methodName, ProgressResources.ExportCloudServicesStarted, ResourceType.CloudService.ToString());
            dcMigration.ReportProgress(ProgressResources.ExportCloudServicesStarted);

            // Get cloud services for affinityGroupNamesInDC or for SourceDCName
            dataCenter.CloudServices.AddRange(ExportCloudServices(affinityGroupNamesInDC, cloudserviceResponse));
            Logger.Info(methodName, string.Format(ProgressResources.CompletedStages, ++stageCount, Constants.ExportTotalStages));
            dcMigration.ReportProgress(string.Format(ProgressResources.CompletedStages, stageCount, Constants.ExportTotalStages));

            Logger.Info(methodName, ProgressResources.ExportStorageAccountStarted, ResourceType.StorageAccount.ToString());
            dcMigration.ReportProgress(ProgressResources.ExportStorageAccountStarted);

            // Get list of storage accounts
            dataCenter.StorageAccounts.AddRange(ExportStorageAccounts(affinityGroupNamesInDC, storageAccountResponse));
            Logger.Info(methodName, string.Format(ProgressResources.CompletedStages, ++stageCount, Constants.ExportTotalStages));
            dcMigration.ReportProgress(string.Format(ProgressResources.CompletedStages, stageCount, Constants.ExportTotalStages));

            // Add the data center into subscription.
            subscription.DataCenters.Add(dataCenter);
            Logger.Info(methodName, string.Format(ProgressResources.ExportDataCenterCompleted, dataCenter.LocationName), ResourceType.DataCenter.ToString());
            Logger.Info(methodName, ProgressResources.ExecutionCompleted);
            return(subscription);
        }
Exemple #2
0
        /// <summary>
        /// Rollback all imported resources.
        /// </summary>
        internal void RollBackResources()
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;

            Logger.Info(methodName, ProgressResources.ExecutionStarted);
            Logger.Info(methodName, ProgressResources.RollbackStarted);
            dcMigrationManager.ReportProgress(ProgressResources.RollbackStarted);
            List <string> listOfImportedResources = new List <string>();

            foreach (var datacenter in subscription.DataCenters)
            {
                // Rollback all services.
                RollBackServices(datacenter.CloudServices.Where(csImported => csImported.IsImported == true).Select(cs =>
                                                                                                                    resourceImporter.GetDestinationResourceName(ResourceType.CloudService, cs.CloudServiceDetails.ServiceName)
                                                                                                                    ).ToList());
                int stageCount = 1;
                Logger.Info(methodName, string.Format(ProgressResources.RollbackCompletedStages, stageCount,
                                                      Constants.RollBackTotalStages), ResourceType.CloudService.ToString());
                dcMigrationManager.ReportProgress(string.Format(ProgressResources.RollbackCompletedStages, stageCount,
                                                                Constants.RollBackTotalStages));

                // Rollback all storage accounts.
                RollBackStorageAccounts(datacenter.StorageAccounts.Where(saImported => saImported.IsImported == true).Select(sa =>
                                                                                                                             resourceImporter.GetDestinationResourceName(ResourceType.StorageAccount, sa.StorageAccountDetails.Name)
                                                                                                                             ).ToList());
                Logger.Info(methodName, string.Format(ProgressResources.RollbackCompletedStages, stageCount++,
                                                      Constants.RollBackTotalStages), ResourceType.StorageAccount.ToString());
                dcMigrationManager.ReportProgress(string.Format(ProgressResources.RollbackCompletedStages, stageCount,
                                                                Constants.RollBackTotalStages));

                dcMigrationManager.ReportProgress(ProgressResources.RollbackVirtualNetworks);
                Logger.Info(methodName, ProgressResources.RollbackVirtualNetworks, ResourceType.NetworkConfiguration.ToString());
                // Rollback all virtual networks.
                if (datacenter.NetworkConfiguration != null && datacenter.NetworkConfiguration.IsImported)
                {
                    RollBackVirtualNetworks(datacenter.NetworkConfiguration);
                }
                Logger.Info(methodName, string.Format(ProgressResources.RollbackCompletedStages, stageCount++,
                                                      Constants.RollBackTotalStages), ResourceType.NetworkConfiguration.ToString());
                dcMigrationManager.ReportProgress(string.Format(ProgressResources.RollbackCompletedStages, stageCount,
                                                                Constants.RollBackTotalStages));

                // Rollback all affinity groups.
                RollBackAffinityGroups(datacenter.AffinityGroups.Where(agImported => agImported.IsImported == true).Select(ag =>
                                                                                                                           resourceImporter.GetDestinationResourceName(ResourceType.AffinityGroup, ag.AffinityGroupDetails.Name)
                                                                                                                           ).ToList());

                Logger.Info(methodName, string.Format(ProgressResources.RollbackCompletedStages, stageCount++,
                                                      Constants.RollBackTotalStages), ResourceType.AffinityGroup.ToString());
                dcMigrationManager.ReportProgress(string.Format(ProgressResources.RollbackCompletedStages, stageCount,
                                                                Constants.RollBackTotalStages));

                Logger.Info(methodName, ProgressResources.RollbackCompleted);
                dcMigrationManager.ReportProgress(ProgressResources.RollbackCompleted);

                Logger.Info(methodName, ProgressResources.ExecutionCompleted);
            }
        }