public override void ExecuteCmdlet()
        {
            bool success = false;

            if (ParameterSetName == ResourceIdParameterSet)
            {
                var resourceIdentifier = new ResourceIdentifier(ResourceId);
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                var parentResources = resourceIdentifier.ParentResource.Split('/');
                AccountName = parentResources[1];
                PoolName    = parentResources[3];
                VolumeName  = parentResources[5];
                Name        = resourceIdentifier.ResourceName;
            }
            else if (ParameterSetName == ParentObjectParameterSet && this.IsParameterBound(c => c.VolumeObject))
            {
                ResourceGroupName = VolumeObject.ResourceGroupName;
                var NameParts = VolumeObject.Name.Split('/');
                if (NameParts.Length > 2)
                {
                    AccountName = NameParts[0];
                    PoolName    = NameParts[1];
                    VolumeName  = NameParts[2];
                }
                else
                {
                    throw new ArgumentException("Invalid Parent id in volume object input .", "VolumeObject");
                }
            }

            if (ShouldProcess(Name, string.Format(PowerShell.Cmdlets.NetAppFiles.Properties.Resources.RestoringFilesMessage, string.Join(",", FilePath))))
            {
                SnapshotRestoreFiles snapshotRestoreFilesBody = new SnapshotRestoreFiles()
                {
                    FilePaths       = FilePath,
                    DestinationPath = DestinationPath
                };

                AzureNetAppFilesManagementClient.Snapshots.RestoreFiles(snapshotRestoreFilesBody, ResourceGroupName, AccountName, PoolName, VolumeName, Name);
                success = true;
            }
            if (PassThru.IsPresent)
            {
                WriteObject(success);
            }
        }
        public void RestoreFilesFromSnapshotFileDoesNotExist()
        {
            HttpMockServer.RecordsDirectory = GetSessionsDirectoryPath();
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var netAppMgmtClient = NetAppTestUtilities.GetNetAppManagementClient(context, new RecordedDelegatingHandler {
                    StatusCodeToReturn = HttpStatusCode.OK
                });

                // create the snapshot
                var snapshot = ResourceUtils.CreateSnapshot(netAppMgmtClient);

                // check snapshot exists
                var snapshotsBefore = netAppMgmtClient.Snapshots.List(ResourceUtils.resourceGroup, ResourceUtils.accountName1, ResourceUtils.poolName1, ResourceUtils.volumeName1);
                Assert.Single(snapshotsBefore);
                // check date created has been set to something
                // can't check exact times becausefails in playback mode
                Assert.True(true);
                Assert.NotNull(snapshotsBefore.First().Created);

                SnapshotRestoreFiles restoreBody = new SnapshotRestoreFiles()
                {
                    FilePaths = new List <string> {
                        "/dir1/file1"
                    }, DestinationPath = "/dataStore"
                };
                var    assertException = Assert.Throws <CloudException>(() => netAppMgmtClient.Snapshots.RestoreFiles(restoreBody, ResourceUtils.resourceGroup, ResourceUtils.accountName1, ResourceUtils.poolName1, ResourceUtils.volumeName1, ResourceUtils.snapshotName1));
                string exceptionCode   = "SingleFileSnapshotRestoreInvalidStatusForOperation";
                Assert.Equal(exceptionCode, assertException.Body.Details[0]?.Code);

                // delete the snapshot and check again
                netAppMgmtClient.Snapshots.Delete(ResourceUtils.resourceGroup, ResourceUtils.accountName1, ResourceUtils.poolName1, ResourceUtils.volumeName1, ResourceUtils.snapshotName1);
                var snapshotsAfter = netAppMgmtClient.Snapshots.List(ResourceUtils.resourceGroup, ResourceUtils.accountName1, ResourceUtils.poolName1, ResourceUtils.volumeName1);
                Assert.Empty(snapshotsAfter);

                // cleanup - remove the resources
                ResourceUtils.DeleteVolume(netAppMgmtClient);
                ResourceUtils.DeletePool(netAppMgmtClient);
                ResourceUtils.DeleteAccount(netAppMgmtClient);
            }
        }
Exemple #3
0
 /// <summary>
 /// Create a new Snapshot Restore Files request
 /// </summary>
 /// <remarks>
 /// Restore the specified files from the specified snapshot to the active
 /// filesystem
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='body'>
 /// Restore payload supplied in the body of the operation.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='accountName'>
 /// The name of the NetApp account
 /// </param>
 /// <param name='poolName'>
 /// The name of the capacity pool
 /// </param>
 /// <param name='volumeName'>
 /// The name of the volume
 /// </param>
 /// <param name='snapshotName'>
 /// The name of the snapshot
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task BeginRestoreFilesAsync(this ISnapshotsOperations operations, SnapshotRestoreFiles body, string resourceGroupName, string accountName, string poolName, string volumeName, string snapshotName, CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.BeginRestoreFilesWithHttpMessagesAsync(body, resourceGroupName, accountName, poolName, volumeName, snapshotName, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
Exemple #4
0
 /// <summary>
 /// Create a new Snapshot Restore Files request
 /// </summary>
 /// <remarks>
 /// Restore the specified files from the specified snapshot to the active
 /// filesystem
 /// </remarks>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='body'>
 /// Restore payload supplied in the body of the operation.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='accountName'>
 /// The name of the NetApp account
 /// </param>
 /// <param name='poolName'>
 /// The name of the capacity pool
 /// </param>
 /// <param name='volumeName'>
 /// The name of the volume
 /// </param>
 /// <param name='snapshotName'>
 /// The name of the snapshot
 /// </param>
 public static void BeginRestoreFiles(this ISnapshotsOperations operations, SnapshotRestoreFiles body, string resourceGroupName, string accountName, string poolName, string volumeName, string snapshotName)
 {
     operations.BeginRestoreFilesAsync(body, resourceGroupName, accountName, poolName, volumeName, snapshotName).GetAwaiter().GetResult();
 }