public override void ExecuteCmdlet() { if (ParameterSetName == ParentObjectParameterSet) { ResourceGroupName = VolumeObject.ResourceGroupName; Location = VolumeObject.Location; var NameParts = VolumeObject.Name.Split('/'); AccountName = NameParts[0]; PoolName = NameParts[1]; VolumeName = NameParts[2]; } var backupBody = new Management.NetApp.Models.Backup() { Location = Location, Label = Label, UseExistingSnapshot = UseExistingSnapshot }; if (ShouldProcess(Name, string.Format(PowerShell.Cmdlets.NetAppFiles.Properties.Resources.CreateResourceMessage, ResourceGroupName))) { var anfBackupPolicy = AzureNetAppFilesManagementClient.Backups.Create(ResourceGroupName, AccountName, poolName: PoolName, volumeName: VolumeName, backupName: Name, body: backupBody); WriteObject(anfBackupPolicy.ConvertToPs()); } }
public static PSNetAppFilesBackup ConvertToPs(this Management.NetApp.Models.Backup backup) { var psBackup = new PSNetAppFilesBackup { ResourceGroupName = new ResourceIdentifier(backup.Id).ResourceGroupName, Location = backup.Location, Id = backup.Id, Name = backup.Name, BackupId = backup.BackupId, Type = backup.Type, BackupType = backup.Type, Label = backup.Label, ProvisioningState = backup.ProvisioningState, Size = backup.Size }; return(psBackup); }
public override void ExecuteCmdlet() { bool accountBackup = false; if (ParameterSetName == ResourceIdParameterSet) { var resourceIdentifier = new ResourceIdentifier(this.ResourceId); ResourceGroupName = resourceIdentifier.ResourceGroupName; var parentResources = resourceIdentifier.ParentResource.Split('/'); AccountName = parentResources[1]; PoolName = parentResources[3]; VolumeName = parentResources[5]; Name = resourceIdentifier.ResourceName; try { var existingVolume = AzureNetAppFilesManagementClient.Volumes.Get(ResourceGroupName, AccountName, PoolName, VolumeName); if (existingVolume == null) { accountBackup = true; } } catch { accountBackup = true; } } if (ParameterSetName == ParentObjectParameterSet) { ResourceGroupName = VolumeObject.ResourceGroupName; var NameParts = VolumeObject.Name.Split('/'); AccountName = NameParts[0]; PoolName = NameParts[1]; VolumeName = NameParts[2]; } else if (ParameterSetName == AccountBackupFieldsParameterSet) { accountBackup = true; Name = AccountBackupName; } if (Name != null) { Management.NetApp.Models.Backup anfBackup = null; if (accountBackup) { anfBackup = AzureNetAppFilesManagementClient.AccountBackups.Get(ResourceGroupName, AccountName, backupName: Name); } else { anfBackup = AzureNetAppFilesManagementClient.Backups.Get(ResourceGroupName, AccountName, backupName: Name, poolName: PoolName, volumeName: VolumeName); } WriteObject(anfBackup.ConvertToPs()); } else { List <PSNetAppFilesBackup> anfBackups = null; if (accountBackup) { var backups = AzureNetAppFilesManagementClient.AccountBackups.List(ResourceGroupName, accountName: AccountName); anfBackups = backups.Value.ConvertToPS(); } else { //anfBackups = AzureNetAppFilesManagementClient.Backups.List(ResourceGroupName, accountName: AccountName, poolName: PoolName, volumeName: VolumeName)..Select(e => e.ConvertToPs()); var backups = AzureNetAppFilesManagementClient.Backups.List(ResourceGroupName, accountName: AccountName, poolName: PoolName, volumeName: VolumeName).ToList(); anfBackups = backups.ConvertToPS(); } WriteObject(anfBackups, true); } }