/// <summary>
 /// The Begin Creating Volume Container operation creates a new volume
 /// container.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.StorSimple.IDataContainerOperations.
 /// </param>
 /// <param name='deviceId'>
 /// Required. device id
 /// </param>
 /// <param name='containerDetails'>
 /// Required. Parameters supplied to the Begin Creating Volume
 /// Container operation.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. The Custom Request Headers which client must use.
 /// </param>
 /// <returns>
 /// This is the Task Response for all Async Calls
 /// </returns>
 public static TaskResponse BeginCreating(this IDataContainerOperations operations, string deviceId, DataContainerRequest containerDetails, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IDataContainerOperations)s).BeginCreatingAsync(deviceId, containerDetails, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        public void DeviceRestoreScenarioTest()
        {
            using (var context = UndoContext.Current)
            {
                context.Start();

                var client = GetServiceClient<StorSimpleManagementClient>();

                // Listing all Devices
                var devices = client.Devices.List(GetCustomRequestHeaders());

                var onlineDeviceIds = from deviceInfo in devices.Devices
                                      where deviceInfo.Status == DeviceStatus.Online
                                      select deviceInfo.DeviceId;
                Assert.True(onlineDeviceIds.Count() >= 2);
                var sourceDeviceId = onlineDeviceIds.ElementAt(0);
                var targetDeviceId = onlineDeviceIds.ElementAt(1);

                CustomRequestHeaders hdrs = new CustomRequestHeaders();
                hdrs.ClientRequestId = Guid.NewGuid().ToString();
                hdrs.Language = "en-us";
                
                //Get service configuration
                var serviceConfigList = client.ServiceConfig.Get(GetCustomRequestHeaders());

                Assert.True(serviceConfigList != null);

                var existingSac = serviceConfigList.CredentialChangeList.Updated.FirstOrDefault();

                Assert.True(existingSac != null);

                var dataContainerName = TestUtilities.GenerateName("DCName");

                // new Data container request object
                var dc = new DataContainerRequest();

                dc.IsDefault = false;
                dc.Name = dataContainerName;
                dc.BandwidthRate = 256;
                dc.VolumeCount = 0;
                dc.IsEncryptionEnabled = false;
                dc.PrimaryStorageAccountCredential = existingSac;

                //Create DataContainer call
                var taskStatus = client.DataContainer.Create(sourceDeviceId, dc, hdrs);

                //Assert the task status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //Get Data Container call
                var Createddatacontainer = client.DataContainer.Get(sourceDeviceId, dataContainerName, hdrs);

                //Assert the returned data container object
                Assert.True(Createddatacontainer != null);
                Assert.True(Createddatacontainer.DataContainerInfo.Name.Equals(dataContainerName));

                //ACR list for Virtual disk creation
                List<AccessControlRecord> acrList = new List<AccessControlRecord>();

                for (var i = 0; i < 1; i++)
                {
                    AccessControlRecord acr = new AccessControlRecord()
                    {
                        Name = TestUtilities.GenerateName("VDnewTestAcr"),
                        InitiatorName = TestUtilities.GenerateName("VDinitiator") + i
                    };
                    acrList.Add(acr);
                }

                //Virtual disk create request object
                var virtualDiskToCreate = new VirtualDiskRequest()
                {
                    Name = TestUtilities.GenerateName("VD1Name"),
                    AccessType = AccessType.ReadWrite,
                    AcrList = acrList,
                    AppType = AppType.PrimaryVolume,
                    IsDefaultBackupEnabled = true,
                    SizeInBytes = 10737418240,
                    DataContainer = Createddatacontainer.DataContainerInfo,
                    Online = true
                };

                //Virtual disk create call
                taskStatus = client.VirtualDisk.Create(sourceDeviceId, virtualDiskToCreate, hdrs);

                //Asserting the task status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //Virtual disk get call
                var createdVirtualDisk = client.VirtualDisk.GetByName(sourceDeviceId, virtualDiskToCreate.Name, hdrs);

                Assert.True(createdVirtualDisk != null);
                Assert.True(createdVirtualDisk.VirtualDiskInfo.Name.Equals(virtualDiskToCreate.Name));

                var volumeIds = new List<string>();
                volumeIds.Add(createdVirtualDisk.VirtualDiskInfo.InstanceId);

                var dailySchedule = new BackupScheduleBase();
                dailySchedule.BackupType = BackupType.CloudSnapshot;
                dailySchedule.Status = ScheduleStatus.Enabled;
                dailySchedule.RetentionCount = 5;
                dailySchedule.StartTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");
                dailySchedule.Recurrence = new ScheduleRecurrence();
                dailySchedule.Recurrence.RecurrenceType = RecurrenceType.Daily;
                dailySchedule.Recurrence.RecurrenceValue = 5;

                var backupPolicyToCreate = new NewBackupPolicyConfig();
                backupPolicyToCreate.Name = TestUtilities.GenerateName("PolicyName");
                backupPolicyToCreate.VolumeIds = volumeIds;
                backupPolicyToCreate.BackupSchedules = new List<BackupScheduleBase>();
                backupPolicyToCreate.BackupSchedules.Add(dailySchedule);

                //BackupPolicy create call
                taskStatus = client.BackupPolicy.Create(sourceDeviceId, backupPolicyToCreate, hdrs);

                //Asserting the task status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //BackupPolicy get by name call
                var createdBackupPolicy = client.BackupPolicy.GetBackupPolicyDetailsByName(sourceDeviceId, backupPolicyToCreate.Name, hdrs);

                //Assert the returned BackupPolicy object
                Assert.True(createdBackupPolicy != null);
                Assert.True(createdBackupPolicy.BackupPolicyDetails.Name.Equals(backupPolicyToCreate.Name));

                BackupNowRequest backupNowRequest = new BackupNowRequest();
                backupNowRequest.Type = BackupType.CloudSnapshot;


                //BackupSets Create call
                taskStatus = client.Backup.Create(sourceDeviceId, createdBackupPolicy.BackupPolicyDetails.InstanceId, backupNowRequest, hdrs);

                //Asserting the task status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                GetBackupResponse backupSetResult;

                do
                {
                    //BackupSets Get call
                    backupSetResult = client.Backup.Get(sourceDeviceId, "BackupPolicy", Boolean.FalseString, createdBackupPolicy.BackupPolicyDetails.InstanceId, null, null, null, null, hdrs);
                    TestUtilities.Wait(1000);
                } while (!backupSetResult.BackupSetsList.Any());
                
                var dcGroupsGetResponse = client.DeviceFailover.ListDCGroups(sourceDeviceId, hdrs);

                var dcIdList = from drDc in dcGroupsGetResponse.DataContainerGroupResponse.DCGroups[0].DCGroup
                    select drDc.InstanceId;

                var drRequest = new DeviceFailoverRequest();
                drRequest.CleanupPrimary = false;
                drRequest.DataContainerIds = dcIdList.ToList();
                drRequest.ReturnWorkflowId = true;
                drRequest.TargetDeviceId = targetDeviceId;

                //trigger failover call
                var jobResponse = client.DeviceFailover.Trigger(sourceDeviceId, drRequest, hdrs);

                //Asserting the task status
                Assert.NotNull(jobResponse);

                //track device job for its completion
                var deviceJobResponse = new GetDeviceJobResponse();
                int retryLimit = 30;
                int pollInterval = 60 * 1000;
                int retryCount = 0;
                bool found = false;

                do
                {
                    TestUtilities.Wait(pollInterval);
                    deviceJobResponse = client.DeviceJob.Get(null, null, null, jobResponse.JobId, null, null, 0, 1, hdrs);
                    if(deviceJobResponse != null)
                    {
                        found = true;
                    }
                    retryCount++;
                } while ((!found || deviceJobResponse.DeviceJobList[0].Status == "Running") && (retryCount < retryLimit));

                Assert.NotNull(deviceJobResponse);
                Assert.Equal(deviceJobResponse.DeviceJobList[0].Status, "Completed");
            }
        }
 public TaskResponse CreateDataContainerAsync(string deviceId, DataContainerRequest dc)
 {
     return GetStorSimpleClient().DataContainer.BeginCreating(deviceId, dc, GetCustomRequestHeaders());
 }
 public TaskStatusInfo CreateDataContainer(string deviceId,DataContainerRequest dc)
 {
         return GetStorSimpleClient().DataContainer.Create(deviceId, dc, GetCustomRequestHeaders());
    
 }
        public override void ExecuteCmdlet()
        {
            try
            {
                string deviceid = StorSimpleClient.GetDeviceId(DeviceName);
                if (deviceid == null)
                {
                    throw new ArgumentException(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, StorSimpleContext.ResourceName, DeviceName));
                }

                if(EncryptionEnabled == true && (string.IsNullOrEmpty(EncryptionKey) || !IsValidAsciiString(EncryptionKey)))
                {
                    throw new ArgumentException(Resources.EncryptionKeyNotAcceptableMessage);
                }

                string encryptedKey = null;
                StorSimpleCryptoManager storSimpleCryptoManager = new StorSimpleCryptoManager(StorSimpleClient);
                if (EncryptionEnabled == true)
                {
                    WriteVerbose(Resources.EncryptionInProgressMessage);
                    storSimpleCryptoManager.EncryptSecretWithRakPub(EncryptionKey, out encryptedKey);
                }

                if (string.IsNullOrEmpty(PrimaryStorageAccountCredential.InstanceId))
                {
                    //The SAC needs to be created inline
                    WriteVerbose(Resources.InlineSacCreationMessage);

                    var sac = PrimaryStorageAccountCredential;

                    //validate storage account credentials
                    bool storageAccountPresent;
                    string encryptedPassword;
                    string thumbprint;
                    string endpoint = GetEndpointFromHostname(sac.Hostname);
                    string location = GetStorageAccountLocation(sac.Name, out storageAccountPresent);
                    if (!storageAccountPresent 
                        || !ValidateAndEncryptStorageCred(sac.Name, sac.Password, endpoint, out encryptedPassword, out thumbprint))
                    {
                        return;
                    }
                    
                    sac.Password = encryptedPassword;
                    sac.PasswordEncryptionCertThumbprint = thumbprint;
                    sac.Location = location;
                }

                var dc = new DataContainerRequest
                {
                    IsDefault = false,
                    Name = VolumeContainerName,
                    BandwidthRate = BandWidthRateInMbps,
                    IsEncryptionEnabled = EncryptionEnabled ?? false,
                    EncryptionKey = encryptedKey,
                    VolumeCount = 0,
                    PrimaryStorageAccountCredential = PrimaryStorageAccountCredential,
                    SecretsEncryptionThumbprint = storSimpleCryptoManager.GetSecretsEncryptionThumbprint()
                };

                if (WaitForComplete.IsPresent)
                {
                    var taskStatus = StorSimpleClient.CreateDataContainer(deviceid, dc);
                    HandleSyncTaskResponse(taskStatus, "create");
                    if (taskStatus.AsyncTaskAggregatedResult == AsyncTaskAggregatedResult.Succeeded)
                    {
                        var createdDataContainer = StorSimpleClient.GetDataContainer(deviceid, VolumeContainerName);
                        WriteObject(createdDataContainer.DataContainerInfo);
                    }
                }

                else
                {
                    var taskstatus = StorSimpleClient.CreateDataContainerAsync(deviceid, dc);
                    HandleAsyncTaskResponse(taskstatus, "create");                
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
Пример #6
0
        public void BackupScenarioTest()
        {
            using (var context = UndoContext.Current)
            {
                context.Start();

                var client = GetServiceClient<StorSimpleManagementClient>();

                // Listing all Devices
                var devices = client.Devices.List(GetCustomRequestHeaders());

                // Asserting that atleast One Device is returned.
                Assert.True(devices != null);
                Assert.True(devices.Any());

                var actualdeviceId = devices.FirstOrDefault().DeviceId;
                actualdeviceId = actualdeviceId.Trim();
                CustomRequestHeaders hdrs = new CustomRequestHeaders();
                hdrs.ClientRequestId = Guid.NewGuid().ToString();
                hdrs.Language = "en-us";

                //Get service configuration
                var serviceConfigList = client.ServiceConfig.Get(GetCustomRequestHeaders());

                Assert.True(serviceConfigList != null);

                var existingSac = serviceConfigList.CredentialChangeList.Updated.FirstOrDefault();

                Assert.True(existingSac != null);

                var dataContainerName = TestUtilities.GenerateName("DCName");

                // new Data container request object
                var dc = new DataContainerRequest();

                dc.IsDefault = false;
                dc.Name = dataContainerName;
                dc.BandwidthRate = 256;
                dc.VolumeCount = 0;
                dc.IsEncryptionEnabled = false;
                dc.PrimaryStorageAccountCredential = existingSac;
                
                //Create DataContainer call
                var taskStatus = client.DataContainer.Create(actualdeviceId, dc, hdrs);

                //Assert the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //Get Data Container call
                var Createddatacontainer = client.DataContainer.Get(actualdeviceId, dataContainerName, hdrs);

                //Assert the returned data container object
                Assert.True(Createddatacontainer != null);
                Assert.True(Createddatacontainer.DataContainerInfo.Name.Equals(dataContainerName));

                //ACR list for Virtual disk creation
                List<AccessControlRecord> acrList = new List<AccessControlRecord>();

                for (var i = 0; i < 1; i++)
                {
                    AccessControlRecord acr = new AccessControlRecord()
                    {
                        Name = TestUtilities.GenerateName("VDnewTestAcr"),
                        InitiatorName = TestUtilities.GenerateName("VDinitiator") + i
                    };
                    acrList.Add(acr);
                }

                //Virtual disk create request object
                var virtualDiskToCreate = new VirtualDiskRequest()
                {
                    Name = TestUtilities.GenerateName("VD1Name"),
                    AccessType = AccessType.ReadWrite,
                    AcrList = acrList,
                    AppType = AppType.PrimaryVolume,
                    IsDefaultBackupEnabled = true,
                    SizeInBytes = 10737418240,
                    DataContainer = Createddatacontainer.DataContainerInfo,
                    Online = true
                };

                //Virtual disk create call
                taskStatus = client.VirtualDisk.Create(actualdeviceId, virtualDiskToCreate, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //Virtual disk get call
                var createdVirtualDisk = client.VirtualDisk.GetByName(actualdeviceId, virtualDiskToCreate.Name, hdrs);

                Assert.True(createdVirtualDisk != null);
                Assert.True(createdVirtualDisk.VirtualDiskInfo.Name.Equals(virtualDiskToCreate.Name));

                var volumeIds = new List<string>();
                volumeIds.Add(createdVirtualDisk.VirtualDiskInfo.InstanceId);
                
                var dailySchedule = new BackupScheduleBase();
                dailySchedule.BackupType = BackupType.CloudSnapshot;
                dailySchedule.Status = ScheduleStatus.Enabled;
                dailySchedule.RetentionCount = 5;
                dailySchedule.StartTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");
                dailySchedule.Recurrence = new ScheduleRecurrence();
                dailySchedule.Recurrence.RecurrenceType = RecurrenceType.Daily;
                dailySchedule.Recurrence.RecurrenceValue = 5;

                var backupPolicyToCreate = new NewBackupPolicyConfig();
                backupPolicyToCreate.Name = TestUtilities.GenerateName("PolicyName");
                backupPolicyToCreate.VolumeIds = volumeIds;
                backupPolicyToCreate.BackupSchedules = new List<BackupScheduleBase>();
                backupPolicyToCreate.BackupSchedules.Add(dailySchedule);

                //BackupPolicy create call
                taskStatus = client.BackupPolicy.Create(actualdeviceId, backupPolicyToCreate, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //BackupPolicy list call
                var allBackupPolicies = client.BackupPolicy.List(actualdeviceId, hdrs);

                //Assert the returned BackupPolicy object
                Assert.True(allBackupPolicies != null);
                Assert.True(allBackupPolicies.Any());

                //BackupPolicy get by name call
                var createdBackupPolicy = client.BackupPolicy.GetBackupPolicyDetailsByName(actualdeviceId, backupPolicyToCreate.Name, hdrs);

                //Assert the returned BackupPolicy object
                Assert.True(createdBackupPolicy != null);
                Assert.True(createdBackupPolicy.BackupPolicyDetails.Name.Equals(backupPolicyToCreate.Name));

                BackupNowRequest backupNowRequest = new BackupNowRequest();
                backupNowRequest.Type = BackupType.CloudSnapshot;
                

                //BackupSets Create call
                taskStatus = client.Backup.Create(actualdeviceId, createdBackupPolicy.BackupPolicyDetails.InstanceId, backupNowRequest, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                BackupScheduleBase hourlySchedule = new BackupScheduleBase();
                hourlySchedule.BackupType = BackupType.LocalSnapshot;
                hourlySchedule.Status = ScheduleStatus.Enabled;
                hourlySchedule.RetentionCount = 10;
                hourlySchedule.StartTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");
                hourlySchedule.Recurrence = new ScheduleRecurrence();
                hourlySchedule.Recurrence.RecurrenceType = RecurrenceType.Hourly;
                hourlySchedule.Recurrence.RecurrenceValue = 12;

                List<BackupScheduleBase> backupSchedulesToBeAdded = new List<BackupScheduleBase>();
                backupSchedulesToBeAdded.Add(hourlySchedule);

                var updatePolicyRequest = new UpdateBackupPolicyConfig();
                updatePolicyRequest.InstanceId = createdBackupPolicy.BackupPolicyDetails.InstanceId;
                updatePolicyRequest.Name = createdBackupPolicy.BackupPolicyDetails.Name;
                updatePolicyRequest.BackupSchedulesToBeAdded = backupSchedulesToBeAdded;
                updatePolicyRequest.BackupSchedulesToBeUpdated = new List<BackupScheduleUpdateRequest>();
                updatePolicyRequest.BackupSchedulesToBeDeleted = new List<string>();
                updatePolicyRequest.VolumeIds = volumeIds;

                //Backup policy update call
                taskStatus = client.BackupPolicy.Update(actualdeviceId, createdBackupPolicy.BackupPolicyDetails.InstanceId, updatePolicyRequest, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                GetBackupResponse backupSetResult;

                do
                {
                    //BackupSets Get call
                    backupSetResult = client.Backup.Get(actualdeviceId, "BackupPolicy", Boolean.TrueString, null, null, null, null, null, hdrs);

                    Assert.True(backupSetResult != null);
                    Assert.True(backupSetResult.BackupSetsList != null);

                    TestUtilities.Wait(1000);
                } while (!backupSetResult.BackupSetsList.Any());

                var backupSetId = backupSetResult.BackupSetsList.First().InstanceId;
                var restoreBackupRequest = new RestoreBackupRequest()
                {
                    BackupSetId = backupSetId,
                    SnapshotId = null
                };

                //Restore call
                taskStatus = client.Backup.Restore(actualdeviceId, restoreBackupRequest, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //BackupSets Delete call
                taskStatus = client.Backup.Delete(actualdeviceId, backupSetId, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                TestUtilities.Wait(60*1000); //wait for 1min for the backup to be deleted

                //Backup Policy delete call
                taskStatus = client.BackupPolicy.Delete(actualdeviceId, createdBackupPolicy.BackupPolicyDetails.InstanceId, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

            }
        }
        public void CanCreateDataContainerTest()
        {
            using (var context = UndoContext.Current)
            {
                context.Start();

                var client = GetServiceClient<StorSimpleManagementClient>();

                // Listing all Devices
                var devices = client.Devices.List(GetCustomRequestHeaders());

                // Asserting that atleast One Device is returned.
                Assert.True(devices != null);
                Assert.True(devices.Any());

                var actualdeviceId = devices.FirstOrDefault().DeviceId;
                actualdeviceId = actualdeviceId.Trim();
                CustomRequestHeaders hdrs = new CustomRequestHeaders();
                hdrs.ClientRequestId = Guid.NewGuid().ToString();
                hdrs.Language = "en-us";
                
                //Get service configuration
                var serviceConfigList = client.ServiceConfig.Get(GetCustomRequestHeaders());

                Assert.True(serviceConfigList != null);

                var existingSac = serviceConfigList.CredentialChangeList.Updated.FirstOrDefault();

                Assert.True(existingSac != null);

                var dataContainerName = TestUtilities.GenerateName("DCName");
                
                // new Data container request object
                var dc = new DataContainerRequest();

                dc.IsDefault = false;
                dc.Name = dataContainerName;
                dc.BandwidthRate = 256;
                dc.VolumeCount = 0;
                dc.IsEncryptionEnabled = false;
                dc.PrimaryStorageAccountCredential = existingSac;

                //Create DataContainer call
                var taskStatus = client.DataContainer.Create(actualdeviceId, dc, hdrs);
                
                //Assert the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);


                //Get Data Container call
                var Createddatacontainer = client.DataContainer.Get(actualdeviceId, dataContainerName, hdrs);

                //Assert the returned data container object
                Assert.True(Createddatacontainer != null);
                Assert.True(Createddatacontainer.DataContainerInfo.Name.Equals(dataContainerName));

                //var dataContainerToUpdate = new DataContainerRequest();

                //var sacToBeUsedForUpdate = Createddatacontainer.DataContainerInfo.PrimaryStorageAccountCredential;
                //sacToBeUsedForUpdate.PasswordEncryptionCertThumbprint = "7DE2C6A43E7B6B35997EC1180CEE43EA2333CE93";

                //dataContainerToUpdate.IsDefault = Createddatacontainer.DataContainerInfo.IsDefault;
                //dataContainerToUpdate.InstanceId = Createddatacontainer.DataContainerInfo.InstanceId;
                //dataContainerToUpdate.Name = Createddatacontainer.DataContainerInfo.Name;
                //dataContainerToUpdate.BandwidthRate = Createddatacontainer.DataContainerInfo.BandwidthRate;
                //dataContainerToUpdate.VolumeCount = Createddatacontainer.DataContainerInfo.VolumeCount;
                //dataContainerToUpdate.IsEncryptionEnabled = Createddatacontainer.DataContainerInfo.IsEncryptionEnabled;
                ////dataContainerToUpdate.EncryptionKey = Createddatacontainer.DataContainerInfo.EncryptionKey;
                //dataContainerToUpdate.PrimaryStorageAccountCredential = Createddatacontainer.DataContainerInfo.PrimaryStorageAccountCredential;
                //dataContainerToUpdate.SecretsEncryptionThumbprint = "7DE2C6A43E7B6B35997EC1180CEE43EA2333CE93";
                    

                //dataContainerToUpdate.BandwidthRate = 512;

                //jobStatus = client.DataContainer.Update(actualdeviceId, dataContainerToUpdate.InstanceId,
                //    dataContainerToUpdate, hdrs);

                ////Assert the job status
                //Assert.NotNull(taskStatus);
                //Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                //Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                taskStatus = client.DataContainer.Delete(actualdeviceId, Createddatacontainer.DataContainerInfo.InstanceId, hdrs);

                //Assert the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);
            }
        }
Пример #8
0
        public void CloneScenarioMultipleDeviceTest()
        {
            using (var context = UndoContext.Current)
            {
                context.Start();

                var client = GetServiceClient<StorSimpleManagementClient>();

                // Listing all Devices
                var devices = client.Devices.List(GetCustomRequestHeaders());

                // Asserting that atleast One Device is returned.
                Assert.True(devices != null);
                Assert.True(devices.Any());

                var actualdeviceId = devices.FirstOrDefault().DeviceId;
                actualdeviceId = actualdeviceId.Trim();
                CustomRequestHeaders hdrs = new CustomRequestHeaders();
                hdrs.ClientRequestId = Guid.NewGuid().ToString();
                hdrs.Language = "en-us";

                //Get service configuration
                var serviceConfigList = client.ServiceConfig.Get(GetCustomRequestHeaders());

                Assert.True(serviceConfigList != null);

                var existingSac = serviceConfigList.CredentialChangeList.Updated.FirstOrDefault();

                Assert.True(existingSac != null);

                var dataContainerName = TestUtilities.GenerateName("DCName");

                // new Data container request object
                var dc = new DataContainerRequest();

                dc.IsDefault = false;
                dc.Name = dataContainerName;
                dc.BandwidthRate = 256;
                dc.VolumeCount = 0;
                dc.IsEncryptionEnabled = false;
                dc.PrimaryStorageAccountCredential = existingSac;

                //Create DataContainer call
                var taskStatus = client.DataContainer.Create(actualdeviceId, dc, hdrs);

                //Assert the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //Get Data Container call
                var Createddatacontainer = client.DataContainer.Get(actualdeviceId, dataContainerName, hdrs);

                //Assert the returned data container object
                Assert.True(Createddatacontainer != null);
                Assert.True(Createddatacontainer.DataContainerInfo.Name.Equals(dataContainerName));

                //ACR list for Virtual disk creation
                List<AccessControlRecord> acrList = new List<AccessControlRecord>();

                for (var i = 0; i < 1; i++)
                {
                    AccessControlRecord acr = new AccessControlRecord()
                    {
                        Name = TestUtilities.GenerateName("VDnewTestAcr"),
                        InitiatorName = TestUtilities.GenerateName("VDinitiator") + i
                    };
                    acrList.Add(acr);
                }

                //Virtual disk create request object
                var virtualDiskToCreate = new VirtualDiskRequest()
                {
                    Name = TestUtilities.GenerateName("VD1Name"),
                    AccessType = AccessType.ReadWrite,
                    AcrList = acrList,
                    AppType = AppType.PrimaryVolume,
                    IsDefaultBackupEnabled = true,
                    SizeInBytes = 10737418240,
                    DataContainer = Createddatacontainer.DataContainerInfo,
                    Online = true
                };

                //Virtual disk create call
                taskStatus = client.VirtualDisk.Create(actualdeviceId, virtualDiskToCreate, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //Virtual disk get call
                var createdVirtualDisk = client.VirtualDisk.GetByName(actualdeviceId, virtualDiskToCreate.Name, hdrs);

                Assert.True(createdVirtualDisk != null);
                Assert.True(createdVirtualDisk.VirtualDiskInfo.Name.Equals(virtualDiskToCreate.Name));

                var volumeIds = new List<string>();
                volumeIds.Add(createdVirtualDisk.VirtualDiskInfo.InstanceId);

                var dailySchedule = new BackupScheduleBase();
                dailySchedule.BackupType = BackupType.CloudSnapshot;
                dailySchedule.Status = ScheduleStatus.Enabled;
                dailySchedule.RetentionCount = 5;
                dailySchedule.StartTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");
                dailySchedule.Recurrence = new ScheduleRecurrence();
                dailySchedule.Recurrence.RecurrenceType = RecurrenceType.Daily;
                dailySchedule.Recurrence.RecurrenceValue = 5;

                var backupPolicyToCreate = new NewBackupPolicyConfig();
                backupPolicyToCreate.Name = TestUtilities.GenerateName("PolicyName");
                backupPolicyToCreate.VolumeIds = volumeIds;
                backupPolicyToCreate.BackupSchedules = new List<BackupScheduleBase>();
                backupPolicyToCreate.BackupSchedules.Add(dailySchedule);

                //BackupPolicy create call
                taskStatus = client.BackupPolicy.Create(actualdeviceId, backupPolicyToCreate, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //BackupPolicy list call
                var allBackupPolicies = client.BackupPolicy.List(actualdeviceId, hdrs);

                //Assert the returned BackupPolicy object
                Assert.True(allBackupPolicies != null);
                Assert.True(allBackupPolicies.Any());

                //BackupPolicy get by name call
                var createdBackupPolicy = client.BackupPolicy.GetBackupPolicyDetailsByName(actualdeviceId, backupPolicyToCreate.Name, hdrs);

                //Assert the returned BackupPolicy object
                Assert.True(createdBackupPolicy != null);
                Assert.True(createdBackupPolicy.BackupPolicyDetails.Name.Equals(backupPolicyToCreate.Name));

                BackupNowRequest backupNowRequest = new BackupNowRequest();
                backupNowRequest.Type = BackupType.CloudSnapshot;


                //BackupSets Create call
                taskStatus = client.Backup.Create(actualdeviceId, createdBackupPolicy.BackupPolicyDetails.InstanceId, backupNowRequest, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                GetBackupResponse backupSetResult;

                do
                {
                    //BackupSets Get call
                    backupSetResult = client.Backup.Get(actualdeviceId, "BackupPolicy", Boolean.TrueString, null, null, null, null, null, hdrs);

                    Assert.True(backupSetResult != null);
                    Assert.True(backupSetResult.BackupSetsList != null);

                    TestUtilities.Wait(1000);
                } while (!backupSetResult.BackupSetsList.Any());

                var backupSet = backupSetResult.BackupSetsList.First();
                var clonedVolName = createdVirtualDisk.VirtualDiskInfo.Name + "_Cloned";
                var secondDeviceId = devices.Devices[1].DeviceId;
                var triggerCloneRequest = new TriggerCloneRequest()
                {
                    BackupSetId = backupSet.InstanceId,
                    SourceSnapshot = backupSet.Snapshots.First(),
                    TargetVolName = clonedVolName,
                    TargetDeviceId = secondDeviceId,
                    ReturnWorkflowId = true,
                    TargetACRList = createdVirtualDisk.VirtualDiskInfo.AcrList
                };

                var jobResponse = client.CloneVolume.Trigger(actualdeviceId, triggerCloneRequest, hdrs);
                //Asserting the job id.
                Assert.NotNull(jobResponse);
                Assert.True(jobResponse.JobId != Guid.Empty.ToString());

                GetDeviceJobResponse deviceJobResponse;
                do
                {
                    //DeviceJob Get call
                    deviceJobResponse = client.DeviceJob.Get(secondDeviceId, null, null, jobResponse.JobId, null, null, 0, 10, hdrs);
                    TestUtilities.Wait(1000);
                    Assert.True(deviceJobResponse.DeviceJobList != null);
                    Assert.True(deviceJobResponse.DeviceJobList.Count == 1);
                } while (deviceJobResponse.DeviceJobList.First().Status == "Running");

                Assert.True(deviceJobResponse.DeviceJobList != null);
                Assert.True(deviceJobResponse.DeviceJobList.First().Status.Equals("Completed", StringComparison.InvariantCultureIgnoreCase));
                VirtualDiskGetResponse virtualDiskGetResponse = client.VirtualDisk.GetByName(secondDeviceId, clonedVolName, GetCustomRequestHeaders());
                Assert.True(virtualDiskGetResponse != null);
                Assert.True(virtualDiskGetResponse.VirtualDiskInfo != null);
                Assert.True(virtualDiskGetResponse.VirtualDiskInfo.Name.Equals(clonedVolName, StringComparison.InvariantCultureIgnoreCase));
            }

        }
        public void VirtualDiskScenarioTest()
        {
            using (var context = UndoContext.Current)
            {
                context.Start();

                var client = GetServiceClient<StorSimpleManagementClient>();

                // Listing all Devices
                var devices = client.Devices.List(GetCustomRequestHeaders());

                // Asserting that atleast One Device is returned.
                Assert.True(devices != null);
                Assert.True(devices.Any());

                var actualdeviceId = devices.FirstOrDefault().DeviceId;
                actualdeviceId = actualdeviceId.Trim();
                CustomRequestHeaders hdrs = new CustomRequestHeaders();
                hdrs.ClientRequestId = Guid.NewGuid().ToString();
                hdrs.Language = "en-us";

                //Get service configuration
                var serviceConfigList = client.ServiceConfig.Get(GetCustomRequestHeaders());

                Assert.True(serviceConfigList != null);

                var existingSac = serviceConfigList.CredentialChangeList.Updated.FirstOrDefault();

                Assert.True(existingSac != null);

                var dataContainerName = TestUtilities.GenerateName("DCName");
                
                // new Data container request object
                var dc = new DataContainerRequest();

                dc.IsDefault = false;
                dc.Name = dataContainerName;
                dc.BandwidthRate = 256;
                dc.VolumeCount = 0;
                dc.IsEncryptionEnabled = false;
                dc.PrimaryStorageAccountCredential = existingSac;
                
                //Create DataContainer call
                var taskStatus = client.DataContainer.Create(actualdeviceId, dc, hdrs);
                
                //Assert the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);


                //Get Data Container call
                var Createddatacontainer = client.DataContainer.Get(actualdeviceId, dataContainerName, hdrs);

                //Assert the returned data container object
                Assert.True(Createddatacontainer != null);
                Assert.True(Createddatacontainer.DataContainerInfo.Name.Equals(dataContainerName));

                //ACR list for Virtual disk creation
                List<AccessControlRecord> acrList = new List<AccessControlRecord>();

                for (var i = 0; i < 1; i++)
                {
                    AccessControlRecord acr = new AccessControlRecord()
                    {
                        Name = TestUtilities.GenerateName("VDnewTestAcr"),
                        InitiatorName = TestUtilities.GenerateName("VDinitiator") + i
                    };
                    acrList.Add(acr);
                }

                //Virtual disk create request object
                var virtualDiskToCreate = new VirtualDiskRequest()
                {
                    Name = TestUtilities.GenerateName("VDName"),
                    AccessType = AccessType.ReadWrite,
                    AcrList =  acrList,
                    AppType = AppType.ArchiveVolume,
                    IsDefaultBackupEnabled = true,
                    SizeInBytes = 10737418240,
                    DataContainer = Createddatacontainer.DataContainerInfo,
                    Online = true
                };

                //Virtual disk create call
                taskStatus = client.VirtualDisk.Create(actualdeviceId, virtualDiskToCreate, hdrs);
                
                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                //virtual disk list call
                var vdlist = client.VirtualDisk.List(actualdeviceId, Createddatacontainer.DataContainerInfo.InstanceId, hdrs);

                Assert.True(vdlist != null);
                Assert.True(vdlist.Any());

                var vdbbyname = client.VirtualDisk.GetByName(actualdeviceId, vdlist.ListofVirtualDisks[0].Name, hdrs);
                Assert.True(vdbbyname != null);

                var virtualDiskToUpdate = vdbbyname.VirtualDiskInfo;

                virtualDiskToUpdate.SizeInBytes = 21474836480;
                virtualDiskToUpdate.Online = false;

                taskStatus = client.VirtualDisk.Update(actualdeviceId, virtualDiskToUpdate.InstanceId,
                    virtualDiskToUpdate, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

                taskStatus = client.VirtualDisk.Delete(actualdeviceId, virtualDiskToUpdate.InstanceId, hdrs);

                //Asserting the job status
                Assert.NotNull(taskStatus);
                Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
                Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

            }
        }
Пример #10
0
        /// <summary>
        /// In order to stop a job we need to first schedule a job that is going to run long 
        /// enough for it to be stopped.
        /// </summary>
        /// <param name="deviceInfo">Device details.</param>
        private void CreateSupportingVolumeAndBackupPolicy(DeviceInfo deviceInfo)
        {
            var client = GetServiceClient<StorSimpleManagementClient>();

            var actualdeviceId = deviceInfo.DeviceId;
            actualdeviceId = actualdeviceId.Trim();
            CustomRequestHeaders hdrs = new CustomRequestHeaders();
            hdrs.ClientRequestId = Guid.NewGuid().ToString();
            hdrs.Language = "en-us";

            //Get service configuration
            var serviceConfigList = client.ServiceConfig.Get(GetCustomRequestHeaders());

            Assert.True(serviceConfigList != null);

            var existingSac = serviceConfigList.CredentialChangeList.Updated.FirstOrDefault();

            Assert.True(existingSac != null);

            var dataContainerName = TestUtilities.GenerateName("DCName");

            // new Data container request object
            var dc = new DataContainerRequest();

            dc.IsDefault = false;
            dc.Name = dataContainerName;
            dc.BandwidthRate = 256;
            dc.VolumeCount = 0;
            dc.IsEncryptionEnabled = false;
            dc.PrimaryStorageAccountCredential = existingSac;

            //Create DataContainer call
            var taskStatus = client.DataContainer.Create(actualdeviceId, dc, hdrs);

            //Assert the job status
            Assert.NotNull(taskStatus);
            Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
            Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

            //Get Data Container call
            var Createddatacontainer = client.DataContainer.Get(actualdeviceId, dataContainerName, hdrs);

            //Assert the returned data container object
            Assert.True(Createddatacontainer != null);
            Assert.True(Createddatacontainer.DataContainerInfo.Name.Equals(dataContainerName));

            //ACR list for Virtual disk creation
            List<AccessControlRecord> acrList = new List<AccessControlRecord>();

            for (var i = 0; i < 1; i++)
            {
                AccessControlRecord acr = new AccessControlRecord()
                {
                    Name = TestUtilities.GenerateName("VDnewTestAcr"),
                    InitiatorName = TestUtilities.GenerateName("VDinitiator") + i
                };
                acrList.Add(acr);
            }

            //Virtual disk create request object
            var virtualDiskToCreate = new VirtualDiskRequest()
            {
                Name = TestUtilities.GenerateName("VD1Name"),
                AccessType = AccessType.ReadWrite,
                AcrList = acrList,
                AppType = AppType.PrimaryVolume,
                IsDefaultBackupEnabled = true,
                SizeInBytes = 107374182400,
                DataContainer = Createddatacontainer.DataContainerInfo,
                Online = true
            };

            //Virtual disk create call
            taskStatus = client.VirtualDisk.Create(actualdeviceId, virtualDiskToCreate, hdrs);

            //Asserting the job status
            Assert.NotNull(taskStatus);
            Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
            Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

            //Virtual disk get call
            var createdVirtualDisk = client.VirtualDisk.GetByName(actualdeviceId, virtualDiskToCreate.Name, hdrs);

            Assert.True(createdVirtualDisk != null);
            Assert.True(createdVirtualDisk.VirtualDiskInfo.Name.Equals(virtualDiskToCreate.Name));

            var volumeIds = new List<string>();
            volumeIds.Add(createdVirtualDisk.VirtualDiskInfo.InstanceId);

            var dailySchedule = new BackupScheduleBase();
            dailySchedule.BackupType = BackupType.CloudSnapshot;
            dailySchedule.Status = ScheduleStatus.Enabled;
            dailySchedule.RetentionCount = 5;
            dailySchedule.StartTime = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzz");
            dailySchedule.Recurrence = new ScheduleRecurrence();
            dailySchedule.Recurrence.RecurrenceType = RecurrenceType.Daily;
            dailySchedule.Recurrence.RecurrenceValue = 5;

            var backupPolicyToCreate = new NewBackupPolicyConfig();
            backupPolicyToCreate.Name = TestUtilities.GenerateName("PolicyName");
            backupPolicyToCreate.VolumeIds = volumeIds;
            backupPolicyToCreate.BackupSchedules = new List<BackupScheduleBase>();
            backupPolicyToCreate.BackupSchedules.Add(dailySchedule);

            //BackupPolicy create call
            taskStatus = client.BackupPolicy.Create(actualdeviceId, backupPolicyToCreate, hdrs);

            //Asserting the job status
            Assert.NotNull(taskStatus);
            Assert.True(taskStatus.Status == AsyncTaskStatus.Completed);
            Assert.True(taskStatus.Result == AsyncTaskResult.Succeeded);

            //BackupPolicy list call
            var allBackupPolicies = client.BackupPolicy.List(actualdeviceId, hdrs);

            //Assert the returned BackupPolicy object
            Assert.True(allBackupPolicies != null);
            Assert.True(allBackupPolicies.Any());
        }
 /// <summary>
 /// The Begin Creating Volume Container operation creates a new volume
 /// container.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.StorSimple.IDataContainerOperations.
 /// </param>
 /// <param name='deviceId'>
 /// Required. device id
 /// </param>
 /// <param name='containerDetails'>
 /// Required. Parameters supplied to the Begin Creating Volume
 /// Container operation.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. The Custom Request Headers which client must use.
 /// </param>
 /// <returns>
 /// This is the Task Response for all Async Calls
 /// </returns>
 public static Task<TaskResponse> BeginCreatingAsync(this IDataContainerOperations operations, string deviceId, DataContainerRequest containerDetails, CustomRequestHeaders customRequestHeaders)
 {
     return operations.BeginCreatingAsync(deviceId, containerDetails, customRequestHeaders, CancellationToken.None);
 }
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.WindowsAzure.Management.StorSimple.IDataContainerOperations.
 /// </param>
 /// <param name='deviceId'>
 /// Required. device id
 /// </param>
 /// <param name='containerDetails'>
 /// Required. Parameters supplied to the Create Volume Container
 /// operation.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Required. The Custom Request Headers which client must use.
 /// </param>
 /// <returns>
 /// Info about the async task
 /// </returns>
 public static Task<TaskStatusInfo> CreateAsync(this IDataContainerOperations operations, string deviceId, DataContainerRequest containerDetails, CustomRequestHeaders customRequestHeaders)
 {
     return operations.CreateAsync(deviceId, containerDetails, customRequestHeaders, CancellationToken.None);
 }