1
/* ============================================================================
2
Copyright 2014 Hewlett Packard
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
8
http://www.apache.org/licenses/LICENSE-2.0
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
============================================================================ */
17
using System.Collections.Generic;
18
using System.Management.Automation;
19
using Openstack.Client.Powershell.Cmdlets.Common;
20
using Openstack.Client.Powershell.Providers.Common;
21
using Openstack.Client.Powershell.Providers.Security;
22
using Openstack.Objects.Domain.BlockStorage;
24
namespace Openstack.Client.Powershell.Cmdlets.BlockStorage
26
[Cmdlet(VerbsCommon.Remove, "Volume", SupportsShouldProcess = true)]
27
[RequiredServiceIdentifierAttribute(Openstack.Objects.Domain.Admin.Services.Compute)]
28
public class RemoveVolumeCmdlet : BasePSCmdlet
30
private string _volumeId;
31
private SwitchParameter _force = false;
34
//=========================================================================================
38
//=========================================================================================
39
[Parameter(Position = 1, ParameterSetName = "RemoveVolume2", Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Help Text")]
41
public SwitchParameter RemoveAll
43
get { return _force; }
44
set { _force = value; }
46
//=========================================================================================
50
//=========================================================================================
51
[Parameter(Position = 0, ParameterSetName = "RemoveVolume", Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "a")]
53
public string VolumeId
55
get { return _volumeId; }
56
set { _volumeId = value; }
60
//=========================================================================================
64
//=========================================================================================
65
protected override void ProcessRecord()
67
string id = this.TranslateQuickPickNumber(this.VolumeId);
69
if (_force == true && this.UserConfirmsDeleteAction("Volumes")) {
70
this.RemoveAllVolumes();
74
this.RepositoryFactory.CreateVolumeRepository().DeleteVolume(id);
75
this.UpdateCache<VolumesUIContainer>();
78
//=========================================================================================
82
//=========================================================================================
83
private void RemoveAllVolumes()
85
List<Volume> volumes = this.RepositoryFactory.CreateVolumeRepository().GetVolumes();
86
Console.WriteLine("");
88
foreach (Volume volume in volumes)
91
Console.WriteLine("Removing Volume : " + volume.Name);
92
this.RepositoryFactory.CreateVolumeRepository().DeleteVolume(volume.Id);
95
Console.WriteLine("");