#region Copyright /* * Copyright © 2014-2016 NetApp, Inc. All Rights Reserved. * * CONFIDENTIALITY NOTICE: THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION OF * NETAPP, INC. USE, DISCLOSURE OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR * EXPRESS WRITTEN PERMISSION OF NETAPP, INC. */ #endregion #region Using Directives using System; using System.Collections; using System.ComponentModel; using System.Linq; using System.Management.Automation; using SolidFire.Core.Validation; using System.Management.Automation.Runspaces; using SolidFire.Core; using SolidFire.Element.Api; #endregion namespace SolidFire.Cluster.Set { /// /// ModifyVirtualNetwork is used to change various attributes of a VirtualNetwork object. This method can be used to add or /// remove address blocks, change the netmask IP, or modify the name or description of the virtual network. /// [Cmdlet(VerbsCommon.Set, "SFVirtualNetwork", SupportsShouldProcess = true, ConfirmImpact=ConfirmImpact.High)] public class SetSFVirtualNetwork : SFCmdlet { #region Private Data /// /// Member used to host a nested Pipeline for calling other CmdLets /// private Pipeline pipeline = null; #endregion #region Parameters /// /// Unique identifier of the virtual network to modify. This is the virtual network ID assigned by the SolidFire cluster. /// [Parameter(Position = 0, ParameterSetName = "VirtualNetworkID", Mandatory = true, ValueFromPipeline = true, HelpMessage = "Unique identifier of the virtual network to modify.")] [ValidatePattern(SolidFireValidations.Numeric)] public Int64 VirtualNetworkID { get; set; } /// /// A unique virtual network (VLAN) tag. Supported values are 1 to 4095 (the number zero (0) is not supported). /// [Parameter(Position = 0, ParameterSetName="VirtualNetworkTag", Mandatory = true, ValueFromPipeline=true, HelpMessage = "A unique virtual network (VLAN) tag. Supported values are 1 to 4095 (the number zero (0) is not supported).")] [ValidatePattern(SolidFireValidations.Numeric)] [ValidateRange(1,4095)] public Int64 VirtualNetworkTag { get; set; } /// /// New name for the new virtual network. /// [Parameter(Position = 1, Mandatory = false, ValueFromPipeline = true, HelpMessage = "New name for the network.")] public String Name { get; set; } /// /// New addressBlock to set for this Virtual Network /// object. This may contain new address blocks to add to /// the existing object or it may omit unused address /// blocks that need to be removed. Alternatively, existing /// address blocks may be extended or reduced in size. /// The size of the starting addressBlocks for a Virtual /// Network object can only be increased, and can never be decreased. /// Attributes for this parameter are: /// start: start of the IP address range. (String) /// size: number of IP addresses to include in the block. (Integer) /// [Parameter(Position = 2, Mandatory = false, ValueFromPipeline = true, HelpMessage = "New addressBlock to set for this Virtual Network object. This may contain new address blocks to add to the existing object or it may omit unused address blocks that need to be removed. Alternatively, existing address blocks may be extended or reduced in size. The size of the starting addressBlocks for a Virtual Network object.")] public AddressBlock[] AddressBlocks { get; set; } /// /// New netmask for this virtual network. /// [Parameter(Position = 3, Mandatory = false, ValueFromPipeline = true, HelpMessage = "New netmask for this virtual network.")] public String Netmask { get; set; } /// /// The storage virtual IP address for this virtual network. The svip for Virtual Network cannot be changed. A new Virtual Network must be created in order to use a different svip address. /// [Parameter(Position = 4, Mandatory = false, ValueFromPipeline = true, HelpMessage = "The storage virtual IP address for this virtual network. The svip for Virtual Network cannot be changed. A new Virtual Network must be created in order to use a different svip address.")] public String Svip { get; set; } /// /// List of Name/Value pairs in JSON object format. /// [Parameter(Mandatory = false, Position = 5, ValueFromPipeline = false, HelpMessage = "A new list of Name/Value pairs in JSON object format.")] public Hashtable Attributes { get; set; } #endregion #region Cmdlet Overrides /// /// Create a nested pipeline that can be written to after processing /// protected override void BeginProcessing() { base.BeginProcessing(); pipeline = Runspace.DefaultRunspace.CreateNestedPipeline(); CheckConnection(minVersionNumber: 7.0f); } /// /// After processing, invoke Get-SFClusterAdmin so the latest list of admins is passed into the pipeline /// protected override void EndProcessing() { base.EndProcessing(); var command = new Command("Get-SFVirtualNetwork"); switch (ParameterSetName) { case "VirtualNetworkID": command.Parameters.Add("VirtualNetworkID", VirtualNetworkID); break; case "VirtualNetworkTag": command.Parameters.Add("VirtualNetworkTag", VirtualNetworkTag); break; } if (SFConnection != null) { command.Parameters.Add("SFConnection", SFConnection); } else if (Target != null) { command.Parameters.Add("Target", Target); } pipeline.Commands.Add(command); // Send it to the pipline WriteObject(pipeline.Invoke(), true); pipeline = null; } /// /// Implementation for processing the execution of the cmdlet. /// protected override void ProcessRecord() { base.ProcessRecord(); // Assemble the parameters object var request = new ModifyVirtualNetworkRequest(); switch (ParameterSetName) { case "VirtualNetworkID": request.VirtualNetworkID = VirtualNetworkID; break; case "VirtualNetworkTag": request.VirtualNetworkTag = VirtualNetworkTag; break; } if (AddressBlocks != null) { request.AddressBlocks = AddressBlocks.Select( a => new AddressBlockParams {Size = a.Size, Start = a.Start}).ToArray(); } request.Name = Name; request.Netmask = Netmask; request.Svip = Svip; request.Attributes = Attributes; SendRequest("ModifyVirtualNetwork", request); } #endregion } }