~travis-plummer/openstack-cli-powershell/master

« back to all changes in this revision

Viewing changes to Openstack.Client.Powershell/Cmdlets/BlockStorage/RemoveVolumeCmdlet.cs

  • Committer: Monty Taylor
  • Date: 2015-10-17 20:03:56 UTC
  • Revision ID: git-v1:803406e7e09f6f4199f7a92f11f2904ad1d6cc15
Retire stackforge/openstack-cli-powershell

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ============================================================================
2
 
Copyright 2014 Hewlett Packard
3
 
 
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
7
 
 
8
 
    http://www.apache.org/licenses/LICENSE-2.0
9
 
 
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
 
============================================================================ */
16
 
using System;
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;
23
 
 
24
 
namespace Openstack.Client.Powershell.Cmdlets.BlockStorage
25
 
{
26
 
    [Cmdlet(VerbsCommon.Remove, "Volume", SupportsShouldProcess = true)]
27
 
    [RequiredServiceIdentifierAttribute(Openstack.Objects.Domain.Admin.Services.Compute)]
28
 
    public class RemoveVolumeCmdlet : BasePSCmdlet
29
 
    {
30
 
        private string _volumeId;
31
 
        private SwitchParameter _force = false;
32
 
 
33
 
        #region Parameters
34
 
//=========================================================================================
35
 
/// <summary>
36
 
/// 
37
 
/// </summary>
38
 
//=========================================================================================  
39
 
        [Parameter(Position = 1, ParameterSetName = "RemoveVolume2", Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Help Text")]
40
 
        [Alias("all")]
41
 
        public SwitchParameter RemoveAll
42
 
        {
43
 
            get { return _force; }
44
 
            set { _force = value; }
45
 
        }
46
 
//=========================================================================================
47
 
/// <summary>
48
 
/// 
49
 
/// </summary>
50
 
//=========================================================================================
51
 
        [Parameter(Position = 0, ParameterSetName = "RemoveVolume", Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "a")]
52
 
        [Alias("v")]
53
 
        public string VolumeId
54
 
        {
55
 
            get { return _volumeId; }
56
 
            set { _volumeId = value; }
57
 
        }
58
 
        #endregion
59
 
        #region Methods
60
 
//=========================================================================================
61
 
/// <summary>
62
 
/// 
63
 
/// </summary>
64
 
//=========================================================================================
65
 
        protected override void ProcessRecord()
66
 
        {
67
 
           string id = this.TranslateQuickPickNumber(this.VolumeId);
68
 
 
69
 
           if (_force == true && this.UserConfirmsDeleteAction("Volumes")) {
70
 
               this.RemoveAllVolumes();
71
 
            }
72
 
           else
73
 
           {
74
 
               this.RepositoryFactory.CreateVolumeRepository().DeleteVolume(id);
75
 
               this.UpdateCache<VolumesUIContainer>();
76
 
           }
77
 
        }
78
 
//=========================================================================================
79
 
/// <summary>
80
 
/// 
81
 
/// </summary>
82
 
//=========================================================================================
83
 
        private void RemoveAllVolumes()
84
 
        {
85
 
            List<Volume> volumes = this.RepositoryFactory.CreateVolumeRepository().GetVolumes();
86
 
            Console.WriteLine("");
87
 
 
88
 
            foreach (Volume volume in volumes)
89
 
            {
90
 
               
91
 
                Console.WriteLine("Removing Volume : " + volume.Name);
92
 
                this.RepositoryFactory.CreateVolumeRepository().DeleteVolume(volume.Id);
93
 
               
94
 
            }
95
 
            Console.WriteLine("");
96
 
        }
97
 
        #endregion
98
 
    }
99
 
}
100
 
 
101
 
 
102