#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.Generic;
using System.ComponentModel;
using System.Linq;
using System.Management.Automation;
using SolidFire.Core.Helpers;
using SolidFire.Core.Validation;
using System.Management.Automation.Runspaces;
using SolidFire.Core;
using SolidFire.Element.Api;
#endregion
namespace SolidFire.Cluster.Add
{
///
///
///
[Cmdlet(VerbsCommon.Add, "SFSnmpUsmUser", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.None)]
public class AddSFSnmpUsmUser : SFCmdlet
{
#region Private Data
///
/// Member used to host a nested Pipeline for calling other CmdLets
///
private Pipeline pipeline = null;
#endregion
#region Parameters
///
/// The name of the user. Must contain at least one character, but no longer than 32 characters. No blank space.
///
[Parameter(Position = 1, Mandatory = true, HelpMessage = "The name of the user. Must contain at least one character, but no longer than 32 characters. No blank space.")]
public String Name { get; set; }
///
/// rouser: read-only access.*, rwuser: for read-write access, rosys: for read-only access to a restricted set of system information.
///
[Parameter(Position = 0, Mandatory = true, HelpMessage = "rouser: read-only access.*, rwuser: for read-write access, rosys: for read-only access to a restricted set of system information.")]
[ValidatePattern(SolidFireValidations.UpperAndLowerCase)]
[ValidateSet("rouser", "rwuser", "rosys", IgnoreCase = true)]
public String Access { get; set; }
///
/// The password of the user. Must be between 8 and 255 characters long (inclusive). No blanks allowed. Required if "secLevel" is "auth" or "priv."
///
[Parameter(Position = 2, Mandatory = true, HelpMessage = "The password of the user. Must be between 8 and 255 characters long (inclusive). No blanks allowed. Required if 'secLevel' is 'auth' or 'priv.'")]
public String Password { get; set; }
///
/// The passphrase of the user. Must be between 8 and 255 characters long (inclusive). No blanks allowed. Required if "secLevel" is "priv."
///
[Parameter(Position = 3, Mandatory = true, HelpMessage = "The passphrase of the user. Must be between 8 and 255 characters long (inclusive). No blanks allowed. Required if 'secLevel' is 'priv'.")]
public String Passphrase { get; set; }
///
/// noauth: no password or passphrase required. auth: a password is required for user access. priv: a password and passphrase is required for user access.
///
[Parameter(Position = 4, Mandatory = true, HelpMessage = "'noauth': no password or passphrase required. 'auth': a password is required for user access. 'priv': a password and passphrase is required for user access.")]
[ValidatePattern(SolidFireValidations.UpperAndLowerCase)]
[ValidateSet("noauth", "auth", "priv", IgnoreCase = true)]
public String SecLevel { get; set; }
#endregion
#region Cmdlet Overrides
///
/// Make sure the connection is Oxygen or greater.
/// Create a nested pipeline that can be written to after processing
///
protected override void BeginProcessing()
{
base.BeginProcessing();
CheckConnection(minVersionNumber: 8.0f);
pipeline = Runspace.DefaultRunspace.CreateNestedPipeline();
}
///
/// After processing, invoke Get-SFSnmpACL to pass the latest into the pipeline.
///
protected override void EndProcessing()
{
base.EndProcessing();
var command = new Command("Get-SFSnmpInfo");
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();
// Get the current TrapRecipients
var objsFromAPI = SendRequest("GetSnmpInfo");
foreach (var obj in objsFromAPI)
{
var users = obj.Result.UsmUsers == null ? new List() : obj.Result.UsmUsers.ToList();
var user = new SnmpV3UsmUser();
user.Access = Access;
user.Name = Name;
user.Passphrase = Passphrase;
user.Password = Password;
user.SecLevel = SecLevel;
users.Add(user);
// Assemble the parameters object
var request = new SetSnmpInfoRequest();
request.UsmUsers = users.ToArray();
request.SnmpV3Enabled = true;
request.Enabled = true;
if (WhatIfShouldProcessHandler(string.Format(obj.Target.Target)))
{
var objFromAPI = SingleConnectionRequest("SetSnmpInfo", obj.Target, request);
if (SolidFireUtilities.HasAPIError(objFromAPI.Error, this)) return;
}
}
}
#endregion
}
}