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

« back to all changes in this revision

Viewing changes to Openstack.Client.Powershell/Cmdlets/Security/NewSecurityGroupCmdlet.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.Linq;
19
 
using System.Text;
20
 
using System.Management.Automation;
21
 
using Openstack.Client.Powershell.Cmdlets.Common;
22
 
using Openstack.Objects.Domain.Security;
23
 
using Openstack.Client.Powershell.Providers.Common;
24
 
using Openstack.Client.Powershell.Providers.Security;
25
 
 
26
 
namespace Openstack.Client.Powershell.Cmdlets.Security
27
 
{
28
 
    [Cmdlet(VerbsCommon.New, "SecurityGroup", SupportsShouldProcess = true)]
29
 
    [RequiredServiceIdentifierAttribute(Openstack.Objects.Domain.Admin.Services.Compute)]
30
 
    public class NewSecurityGroupCmdlet : BasePSCmdlet
31
 
    {
32
 
        private string _name;
33
 
        private string _description;
34
 
 
35
 
        #region Parameters
36
 
//=========================================================================================
37
 
/// <summary>
38
 
/// 
39
 
/// </summary>
40
 
//=========================================================================================
41
 
        [Parameter(Position = 1, Mandatory = true, ParameterSetName = "NewSecurityGroup", ValueFromPipelineByPropertyName = true, HelpMessage = "ww")]
42
 
        [Alias("d")]
43
 
        [ValidateNotNullOrEmpty]
44
 
        public string Description
45
 
        {
46
 
            get { return _description; }
47
 
            set { _description = value; }
48
 
        }
49
 
//=========================================================================================
50
 
/// <summary>
51
 
/// 
52
 
/// </summary>
53
 
//=========================================================================================
54
 
        [Parameter(Position = 0, ParameterSetName = "NewSecurityGroup", Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "www")]
55
 
        [Alias("n")]
56
 
        public string Name
57
 
        {
58
 
            get { return _name; }
59
 
            set { _name = value; }
60
 
        }
61
 
        #endregion
62
 
        #region Methods
63
 
//=========================================================================================
64
 
/// <summary>
65
 
/// 
66
 
/// </summary>
67
 
//=========================================================================================
68
 
        protected override void ProcessRecord()
69
 
        {
70
 
            NewSecurityGroup newGroup = new NewSecurityGroup();
71
 
            newGroup.Description      = this.Description;
72
 
            newGroup.Name             = this.Name;
73
 
 
74
 
            SecurityGroup securityGroup = this.RepositoryFactory.CreateSecurityRepository().SaveSecurityGroup(newGroup);
75
 
            this.UpdateCache<SecurityGroupsUIContainer>();
76
 
        }
77
 
        #endregion
78
 
    }
79
 
        
80
 
}