Types-implement #4

Merged
Arnike merged 9 commits from Types-implement into main 2022-12-13 23:55:44 +03:00
51 changed files with 1483 additions and 775 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
*.dll
bin
obj
.code-workspace

View File

@@ -27,6 +27,7 @@
[![License](https://img.shields.io/badge/license-GPL2+-blue.svg)](https://git.arnike.ru/Arnike/ps.ipam/src/branch/main/LICENSE) [![License](https://img.shields.io/badge/license-GPL2+-blue.svg)](https://git.arnike.ru/Arnike/ps.ipam/src/branch/main/LICENSE)
![Powershell](https://img.shields.io/badge/powershell-v5.1+-blue.svg) ![Powershell](https://img.shields.io/badge/powershell-v5.1+-blue.svg)
![PowerShell Gallery](https://img.shields.io/powershellgallery/dt/ps.ipam)
<h3 align="center">PS.IPAM</h3> <h3 align="center">PS.IPAM</h3>

77
classlib/class/address.cs Normal file
View File

@@ -0,0 +1,77 @@
namespace PS.IPAM;
using System;
[Serializable]
public class Address {
public int Id { get; }
public int SubnetId { get; }
public string Ip { get; }
public bool IsGateway { get; }
public string Description { get; }
public string Hostname { get; }
public string MAC { get; }
public string Owner { get; }
public int TagId { get; }
public int DeviceId { get; }
public string Location { get; }
public string Port { get; }
public string Note { get; }
public DateTime? LastSeen { get; }
public bool ExcludePing { get; }
public bool PTRignore { get; }
public int PTR { get; }
public string FirewallAddressObject { get; }
public DateTime? EditDate { get; }
public int CustomerId { get; }
public Object? ExtendedData { get; }
public Address(
int id,
int subnetId,
string ip,
bool is_gateway,
string description,
string hostname,
string mac,
string owner,
int tag,
int deviceId,
string location,
string port,
string note,
DateTime? lastSeen,
bool excludePing,
bool PTRignore,
int PTR,
string firewallAddressObject,
DateTime? editDate,
int customer_id,
Object? extendedData
) {
this.Id = id;
this.SubnetId = subnetId;
this.Ip = ip;
this.IsGateway = is_gateway;
this.Description = description;
this.Hostname = hostname;
this.MAC = mac;
this.Owner = owner;
this.TagId = tag;
this.DeviceId = deviceId;
this.Location = location;
this.Port = port;
this.Note = note;
this.EditDate = lastSeen;
this.ExcludePing = excludePing;
this.PTRignore = PTRignore;
this.PTR = PTR;
this.FirewallAddressObject = firewallAddressObject;
this.EditDate = editDate;
this.CustomerId = customer_id;
this.ExtendedData = extendedData;
}
public override string ToString() {
return this.Ip;
}
}

27
classlib/class/domain.cs Normal file
View File

@@ -0,0 +1,27 @@
namespace PS.IPAM;
using System;
[Serializable]
public class Domain {
public int Id { get; }
public string Name { get; }
public string Description { get; }
public string Sections { get; }
public Domain (
int id,
string name,
string description,
string sections
) {
this.Id = id;
this.Name = name;
this.Description = description;
this.Sections = sections;
}
public override string ToString()
{
return this.Name;
}
}

57
classlib/class/section.cs Normal file
View File

@@ -0,0 +1,57 @@
namespace PS.IPAM;
using System;
[Serializable]
public class Section {
public int Id { get; }
public string Name { get; }
public string Description { get; }
public int MasterSectionId { get; }
public string Permissions { get; }
public bool StrictMode { get; }
public string SubnetOrdering { get; }
public int Order { get; }
public DateTime? EditDate { get; }
public bool ShowSubnet { get; }
public bool ShowVlan { get; }
public bool ShowVRF { get; }
public bool ShowSupernetOnly { get; }
public int DNSId { get; }
public Section (
int id,
string name,
string description,
int masterSectionId,
string permissions,
bool strictMode,
string subnetOrdering,
int order,
DateTime? editDate,
bool showSubnet,
bool showVlan,
bool showVRF,
bool showSupernetOnly,
int dnsId
) {
this.Id = id;
this.Name = name;
this.Description = description;
this.MasterSectionId = masterSectionId;
this.Permissions = permissions;
this.StrictMode = strictMode;
this.SubnetOrdering = subnetOrdering;
this.Order = order;
this.EditDate = editDate;
this.ShowSubnet = showSubnet;
this.ShowVlan = showVlan;
this.ShowVRF = showVRF;
this.ShowSupernetOnly = showSupernetOnly;
this.DNSId = dnsId;
}
public override string ToString()
{
return this.Name;
}
}

32
classlib/class/session.cs Normal file
View File

@@ -0,0 +1,32 @@
namespace PS.IPAM;
using System;
[Serializable]
public class Session {
public AuthType AuthType { get; }
public string Token { get; }
public string AppID { get; }
public string URL { get; }
public DateTime? Expires { get; }
public Object? Credentials { get; }
public Session(
AuthType authType,
string token,
string appId,
string url,
DateTime? expires,
Object? credentials
) {
AuthType = authType;
Token = token;
AppID = appId;
URL = url;
Expires = expires;
Credentials = credentials;
}
public override string ToString()
{
return base.ToString();
}
}

114
classlib/class/subnet.cs Normal file
View File

@@ -0,0 +1,114 @@
namespace PS.IPAM;
using System;
[Serializable]
public class Subnetwork {
public int Id { get; }
public string Subnet { get; }
public int Mask { get; }
public int SectionId { get; }
public string Description { get; }
public string LinkedSubnet { get; }
public string FirewallAddressObject { get; }
public int VrfId { get; }
public int MasterSubnetId { get; }
public bool AllowRequests { get; }
public int VlanId { get; }
public bool ShowName { get; }
public int DeviceId { get; }
public string Permissions { get; }
public bool PingSubnet { get; }
public bool DiscoverSubnet { get; }
public bool ResolveDNS { get; }
public bool DNSRecursive { get; }
public bool DNSRecords { get; }
public int NameserverId { get; }
public bool ScanAgent { get; }
public bool IsFolder { get; }
public bool IsFull { get; }
public bool IsPool { get; }
public int TagId { get; }
public int Threshold { get; }
public int LocationId { get; }
public DateTime? EditDate { get; }
public DateTime? LastScan { get; }
public DateTime? LastDiscovery { get; }
public Object Calculation { get; }
public Object? ExtendedData { get; }
public Subnetwork(
int id,
string subnet,
int mask,
int sectionId,
string description,
string linkedSubnet,
string firewallAddressObject,
int vrfId,
int masterSubnetId,
bool allowRequests,
int vlanId,
bool showName,
int deviceId,
string permissions,
bool pingSubnet,
bool discoverSubnet,
bool resolveDNS,
bool dnsRecursive,
bool dnsRecords,
int nameserverId,
bool scanAgent,
bool isFolder,
bool isFull,
bool isPool,
int tagId,
int threshold,
int locationId,
DateTime? editDate,
DateTime? lastScan,
DateTime? lastDiscovery,
Object calculation,
Object? custom_fields
) {
this.Id = id;
this.Subnet = subnet;
this.Mask = mask;
this.SectionId = sectionId;
this.Description = description;
this.LinkedSubnet = linkedSubnet;
this.FirewallAddressObject = firewallAddressObject;
this.VrfId = vrfId;
this.MasterSubnetId = masterSubnetId;
this.AllowRequests = allowRequests;
this.VlanId = vlanId;
this.ShowName = showName;
this.DeviceId = deviceId;
this.Permissions = permissions;
this.PingSubnet = pingSubnet;
this.DiscoverSubnet = discoverSubnet;
this.ResolveDNS = resolveDNS;
this.DNSRecursive = dnsRecursive;
this.DNSRecords = dnsRecords;
this.NameserverId = nameserverId;
this.ScanAgent = scanAgent;
this.IsFolder = isFolder;
this.IsFull = isFull;
this.IsPool = isPool;
this.TagId = tagId;
this.Threshold = threshold;
this.LocationId = locationId;
this.EditDate = editDate;
this.LastScan = lastScan;
this.LastDiscovery = lastDiscovery;
this.Calculation = calculation;
this.ExtendedData = custom_fields;
}
public string GetCIDR() {
return $"{this.Subnet}/{this.Mask}";
}
public override string ToString()
{
return this.GetCIDR();
}
}

45
classlib/class/tag.cs Normal file
View File

@@ -0,0 +1,45 @@
namespace PS.IPAM;
using System;
[Serializable]
public class Tag {
public int Id { get; }
public string Type { get; }
public bool ShowTag { get; }
public string BGColor { get; }
public string FGColor { get; }
public bool Compress { get; }
public bool Locked { get; }
public bool UpdateTag { get; }
public Tag(
int id,
string type,
bool showTag,
string BGColor,
string FGColor,
string compress,
string locked,
bool updateTag
) {
this.Id = id;
this.Type = type;
this.ShowTag = showTag;
this.BGColor = BGColor;
this.FGColor = FGColor;
this.Compress = this.StringToBool(compress);
this.Locked = this.StringToBool(locked);
this.UpdateTag = updateTag;
}
public override string ToString() {
return this.Type;
}
private bool StringToBool(string str) {
if (str == "Yes") {
return true;
}
return false;
}
}

39
classlib/class/vlan.cs Normal file
View File

@@ -0,0 +1,39 @@
namespace PS.IPAM;
using System;
using System.Dynamic;
[Serializable]
public class Vlan : DynamicObject {
public int Id { get; }
public int DomainId { get; }
public string Name { get; }
public int Number { get; }
public string Description { get; }
public DateTime? EditDate { get; }
public int CustomerId { get; }
public Object? ExtendedData { get; }
public Vlan (
int vlanId,
int domainId,
string name,
int number,
string description,
DateTime? editDate,
int customer_id,
Object? custom_fields
) {
this.Id = vlanId;
this.DomainId = domainId;
this.Name = name;
this.Number = number;
this.Description = description;
this.EditDate = editDate;
this.CustomerId = customer_id;
this.ExtendedData = custom_fields;
}
public override string ToString()
{
return $"{this.Number}";
}
}

35
classlib/class/vrf.cs Normal file
View File

@@ -0,0 +1,35 @@
namespace PS.IPAM;
using System;
[Serializable]
public class Vrf {
public int Id { get; }
public string Name { get; }
public string RouteDistinguisher { get; }
public string Description { get; }
public string Sections { get; }
public DateTime? EditDate { get; }
public Object? ExtendedData { get; }
public Vrf(
int id,
string name,
string rd,
string description,
string sections,
DateTime? editDate,
Object? custom_fields
) {
this.Id = id;
this.Name = name;
this.RouteDistinguisher = rd;
this.Description = description;
this.Sections = sections;
this.EditDate = editDate;
this.ExtendedData = custom_fields;
}
public override string ToString()
{
return this.Name;
}
}

10
classlib/classlib.csproj Normal file
View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,8 @@
namespace PS.IPAM;
using System;
[Serializable]
public enum AuthType {
credentials,
token
}

View File

@@ -0,0 +1,14 @@
namespace PS.IPAM;
using System;
[Serializable]
public enum controllers {
user,
vlan,
subnets,
addresses,
sections,
vrf,
l2domains,
tools
}

View File

@@ -0,0 +1,16 @@
namespace PS.IPAM;
using System;
[Serializable]
public enum subcontrollers {
nameservers,
tags,
devices,
device_types,
vlans,
vrfs,
scanagents,
locations,
nat,
racks
}

13
classlib/enum/types.cs Normal file
View File

@@ -0,0 +1,13 @@
namespace PS.IPAM;
using System;
[Serializable]
public enum types {
Address,
Domain,
Section,
Subnetwork,
Tag,
Vlan,
Vrf
}

View File

@@ -1,64 +0,0 @@
function Invoke-PSIPAMRequest {
[CmdletBinding()]
param (
[parameter(Mandatory=$true)]
[ValidateSet("POST","GET","PATCH","DELETE")]
[string]
$Method,
[parameter(Mandatory=$true)]
[ValidateSet("user","vlan","subnets","addresses","sections","vrf","l2domains","tools")]
[string]
$Controller,
[parameter(Mandatory=$false)]
[ValidateSet("nameservers")]
[string]
$SubController,
[Parameter(Mandatory=$false)]
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
$Params,
[Parameter(Mandatory=$false)]
[array]
$Identifiers
)
$_tokenStatus = Test-PSIPAMSession
if ($_tokenStatus -eq "NoToken") { throw "No session available!" }
if ($_tokenStatus -eq "Expired") { Update-PSIPAMSession }
$Controller = $Controller.ToLower()
$_uri = "$($script:ipamURL)/api/$($script:ipamAppID)/$Controller"
if ($SubController) { $_uri += "/$SubController" }
if ($Identifiers) { $_uri += "/$($Identifiers -join '/')/" }
$_headers = @{
"Accept" = "application/json"
"Content-Type" = "application/json"
"token" = $script:ipamToken
}
$_arguments = @{
Method = $Method
Uri = $_uri
Headers = $_headers
}
if ($Method -match "POST|PATCH") {
if ($Params -is [PSCustomObject]) {
$_params = @{};
$Params | Get-Member -MemberType *Property | Where-Object {
$_params.($_.name) = $Params.($_.name)
}
} else { $_params = $Params }
$_arguments.Add("Body",($_params | ConvertTo-Json))
}
$_response = Invoke-RestMethod @_arguments
if ($_response.code -match "20\d") {
return $_response.data
} else {
throw ("Error - $($_response.code)")
}
}

View File

@@ -0,0 +1,101 @@
function Invoke-Request {
[CmdletBinding()]
param (
[parameter(Mandatory=$true)]
[ValidateSet("GET","POST","PATCH","DELETE")]
[string]
$Method,
[parameter(Mandatory=$true)]
[PS.IPAM.controllers]
$Controller,
[parameter(Mandatory=$false)]
[PS.IPAM.types]
$Type,
[parameter(Mandatory=$false)]
[PS.IPAM.subcontrollers]
$SubController,
[Parameter(Mandatory=$false)]
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
$Params,
[Parameter(Mandatory=$false)]
[array]
$Identifiers
)
$_tokenStatus = Test-Session
if ($_tokenStatus -eq "NoToken") { throw "No session available!" }
if ($_tokenStatus -eq "Expired") { Update-Session }
$Controller = $Controller
$_uri = "$($script:psipamSession.URL)/api/$($script:psipamSession.AppID)/$Controller"
if ($SubController) { $_uri += "/$SubController" }
if ($Identifiers) { $_uri += "/$($Identifiers -join '/')/" }
$_headers = @{
"Accept" = "application/json"
"Content-Type" = "application/json"
}
switch ($script:psipamSession.AuthType) {
"Credentials" { $_headers.Add("token", $script:psipamSession.Token) }
"Token" { $_headers.Add("phpipam-token", $script:psipamSession.Token) }
}
$_arguments = @{
Method = $Method
Uri = $_uri
Headers = $_headers
}
if ($Method -eq "POST" -or $Method -eq "PATCH") {
if ($Params -is [PSCustomObject]) {
$_params = @{};
$Params | Get-Member -MemberType *Property | Where-Object {
$_params.($_.name) = $Params.($_.name)
}
} else { $_params = $Params }
$_arguments.Add("Body",($_params | ConvertTo-Json))
}
Write-Verbose -Message "Invoking web request to $($_uri), with method $($_arguments.Method), headers: $($_arguments.Headers)"
$_response = Invoke-RestMethod @_arguments
if ($_response.code -match "20\d") {
if ($Type -is [PS.IPAM.types]) {
switch ($Type) {
"address" {
$_paramList = @("id","subnetId","ip","is_gateway","description","hostname","mac","owner","tag","deviceId","location","port","note","lastSeen","excludePing","PTRignore","PTR","firewallAddressObject","editDate","customer_id")
$_response.data | ForEach-Object {
New-Object -TypeName ([PS.IPAM.Address]) -ArgumentList (@(($_ | Select-Object $_paramList).psobject.properties.value) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
}; break
}
"vlan" {
$_paramList = @("vlanId","domainId","name","number","description","editDate","customer_id","custom_fields")
$_response.data | ForEach-Object {
New-Object -TypeName ([PS.IPAM.Vlan]) -ArgumentList (@(($_ | Select-Object $_paramList).psobject.properties.value) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
}; break
}
"subnetwork" {
$_response.data | ForEach-Object {
New-Object -TypeName ([PS.IPAM.Subnetwork]) -ArgumentList (@($_.psobject.properties.value[0..30]) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
}; break
}
"vrf" {
$_response.data | ForEach-Object {
New-Object -TypeName ([PS.IPAM.Vrf]) -ArgumentList (@($_.psobject.properties.value[0..5]) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
}; break
}
Default { $_response.data | ForEach-Object { New-Object -TypeName ("PS.IPAM.$Type") -ArgumentList $_.psobject.properties.value } }
}
} else {
return $_response.data
}
} else {
throw ("Error - $($_response.code)")
}
}

View File

@@ -1,15 +0,0 @@
function Test-PSIPAMSession {
[CmdletBinding()]
param (
)
if ($script:ipamToken) {
if ($script:ipamExpires -lt (Get-Date)) {
return "Expired"
} else {
return "Valid"
}
} else {
return "NoToken"
}
}

View File

@@ -0,0 +1,19 @@
function Test-Session {
[CmdletBinding()]
param (
)
if ($script:psipamSession) {
if ($null -eq $script:psipamSession.Expires) {
return "Valid"
} else {
if ($script:psipamSession.Expires -lt (Get-Date)) {
return "Expired"
} else {
return "Valid"
}
}
} else {
return "NoToken"
}
}

View File

@@ -1,18 +0,0 @@
function Update-PSIPAMSession {
[CmdletBinding()]
param (
[switch]
$Force
)
$_tokenStatus = Test-PSIPAMSession
if ($_tokenStatus -eq "NoToken") {
throw "No session available!"
}
if ($_tokenStatus -eq "Valid") {
return (Invoke-PSIPAMRequest -Method PATCH -Controller user).expires
}
if ($_tokenStatus -eq "Expired" -or $Force) {
New-PSIPAMSession -URL $script:ipamURL -AppID $script:ipamAppID -Credentials $script:ipamCredentials
return $script:ipamExpires
}
}

View File

@@ -0,0 +1,18 @@
function Update-Session {
[CmdletBinding()]
param (
[switch]
$Force
)
$_tokenStatus = Test-Session
if ($_tokenStatus -eq "NoToken") {
throw "No session available!"
}
if ($_tokenStatus -eq "Valid") {
return (Invoke-Request -Method [ps.ipam.methods]::PATCH -Controller [ps.ipam.controllers]::user).expires
}
if ($_tokenStatus -eq "Expired" -or $Force) {
New-Session -URL $script:psipamSession.URL -AppID $script:psipamSession.AppID -Credentials $script:psipamSession.Credentials
return
}
}

View File

@@ -0,0 +1,33 @@
function Assign-Tag {
[CmdletBinding()]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
[ValidateNotNullOrEmpty()]
[PS.IPAM.Address]
$AddressObject,
[parameter(Mandatory=$true,Position=1)]
[ValidateNotNullOrEmpty()]
[PS.IPAM.Tag]
$Tag
)
process {
$_params = @{
Controller = [PS.IPAM.controllers]::addresses
Method = "PATCH"
}
$_id = $AddressObject.id
$_tagid = $Tag.id
$_identifiers = @($_id)
$_params.Add("Identifiers",$_identifiers)
$_body = @{ }
$_body.Add("tag", $_tagid)
$_params.Add("Params",$_body)
Invoke-Request @_params
}
}
Export-ModuleMember -Function Assign-Tag

View File

@@ -0,0 +1,66 @@
function Get-Address {
[CmdletBinding(DefaultParameterSetName="ByID")]
[OutputType([PS.IPAM.address])]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateNotNullOrEmpty()]
[int]
$Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByIP")]
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="BySubnetId")]
[ValidateNotNullOrEmpty()]
[ipaddress]
$IP,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByHostName")]
[ValidateNotNullOrEmpty()]
[string]
$HostName,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByTag")]
[ValidateNotNullOrEmpty()]
[int]
$TagId,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetId")]
[ValidateNotNullOrEmpty()]
[int]
$SubnetId,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetCIDR")]
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
[ValidateNotNullOrEmpty()]
[string]
$SubnetCIDR
)
process {
$_params = @{
Controller = [PS.IPAM.controllers]::addresses
Method = "GET"
Type = [PS.IPAM.types]::address
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers = @($id); break }
"ByIP" { $_identifiers = ("search",$IP); break }
"ByHostName" { $_identifiers = ("search_hostname",$HostName); break }
"ByTag" { $_identifiers = ("tags",$TagId,[PS.IPAM.controllers]::addresses); break }
"BySubnetId" {
if ($IP) {
$_identifiers = ($IP,$SubnetId)
} else {
$_params.Item("Controller") = [PS.IPAM.controllers]::subnets
$_identifiers = ($SubnetId,[PS.IPAM.controllers]::addresses)
}
break
}
"BySubnetCIDR" {
$_params.Item("Controller") = [PS.IPAM.controllers]::subnets
$_subnetId = (Get-Subnet -CIDR $SubnetCIDR).id
if (!$_subnetId) { throw "Cannot find subnet!" }
$_identifiers = ($_subnetId,[PS.IPAM.controllers]::addresses)
break
}
}
$_params.Add("Identifiers",$_identifiers)
Invoke-Request @_params
}
}
Export-ModuleMember -Function Get-Address

View File

@@ -1,4 +1,4 @@
function Get-PSIPAMFirstFreeIP { function Get-FirstFreeIP {
[CmdletBinding(DefaultParameterSetName="ByID")] [CmdletBinding(DefaultParameterSetName="ByID")]
param ( param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")] [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")]
@@ -7,27 +7,32 @@ function Get-PSIPAMFirstFreeIP {
[string] [string]
$CIDR, $CIDR,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[string] [int]
$Id $Id,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetObject")]
[ValidateNotNullOrEmpty()]
[PS.IPAM.Subnetwork]
$SubnetObject
) )
process { process {
$_params = @{ $_params = @{
Controller = "subnets" Controller = [PS.IPAM.controllers]::subnets
Method = "GET" Method = "GET"
} }
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_subnetId = $Id } "ByID" { $_subnetId = $Id; break }
"ByCIDR" { "ByCIDR" {
$_subnetId = (Get-PSIPAMSubnet -CIDR $CIDR).id $_subnetId = (Get-Subnet -CIDR $CIDR).id
if (!$_subnetId) { throw "Cannot find subnet!" } if (!$_subnetId) { throw "Cannot find subnet!" }
break
} }
"BySubnetObject" { $_subnetId = $SubnetObject.Id; break }
} }
$_identifiers = @($_subnetId,"first_free") $_identifiers = @($_subnetId,"first_free")
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
return Invoke-PSIPAMRequest @_params | Select-Object @{n="Ip";e={$_}} return Invoke-Request @_params | Select-Object @{n="Ip";e={$_}}
} }
} }
Export-ModuleMember -Function Get-PSIPAMFirstFreeIP Export-ModuleMember -Function Get-FirstFreeIP

View File

@@ -0,0 +1,23 @@
function Get-L2Domain {
[CmdletBinding(DefaultParameterSetName="ByID")]
[OutputType([PS.IPAM.Domain])]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateNotNullOrEmpty()]
[int]
$Id
)
process {
$_params = @{
Controller = [PS.IPAM.controllers]::l2domains
Method = "GET"
Type = [PS.IPAM.types]::Domain
}
$_identifiers = @($Id)
$_params.Add("Identifiers",$_identifiers)
Invoke-Request @_params
}
}
Export-ModuleMember -Function Get-L2Domain

View File

@@ -1,10 +1,9 @@
function Get-PSIPAMNameserver { function Get-Nameserver {
[CmdletBinding(DefaultParameterSetName="ByID")] [CmdletBinding(DefaultParameterSetName="ByID")]
param ( param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[string] [int]
$Id $Id
) )
process { process {
@@ -12,18 +11,18 @@ function Get-PSIPAMNameserver {
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList) $visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{ $_params = @{
Controller = "tools" Controller = [PS.IPAM.controllers]::tools
SubController = "nameservers" SubController = [PS.IPAM.subcontrollers]::nameservers
Method = "GET" Method = "GET"
} }
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_nameserverId = $Id } "ByID" { $_nameserverId = $Id; break }
} }
$_identifiers = @($_nameserverId) $_identifiers = @($_nameserverId)
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | Select-Object @{n="address";e={$_.namesrv1}},* | Select-Object -ExcludeProperty namesrv1 | ` Invoke-Request @_params | Select-Object @{n="address";e={$_.namesrv1}},* | Select-Object -ExcludeProperty namesrv1 | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
} }
} }
Export-ModuleMember -Function Get-PSIPAMNameserver Export-ModuleMember -Function Get-Nameserver

View File

@@ -1,26 +0,0 @@
function Get-PSIPAML2Domain {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id
)
process {
[string[]]$visiblePropertiesList = @('Id','Name','Description')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "l2domains"
Method = "GET"
}
$_identifiers = @($Id)
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember -Function Get-PSIPAML2Domain

View File

@@ -1,32 +0,0 @@
function Get-PSIPAMSection {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByName")]
[ValidateNotNullOrEmpty()]
[string]
$Name
)
process {
[string[]]$visiblePropertiesList = @('Id','Name','Description')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "sections"
Method = "GET"
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers = @($Id) }
"ByName" { $_identifiers = @($Name) }
}
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember Get-PSIPAMSection

View File

@@ -1,26 +0,0 @@
function Get-PSIPAMTags {
[CmdletBinding()]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id
)
process {
[string[]]$visiblePropertiesList = @('Id','Name')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "addresses"
Method = "GET"
}
$_identifiers = @("tags")
if ($Id) { $_identifiers += $Id }
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember -Function Get-PSIPAMTags

View File

@@ -1,45 +0,0 @@
function Get-PSIPAMVlan {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByNumber")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Number,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByL2Domain")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$L2DomainId
)
process {
[string[]]$visiblePropertiesList = @('Id','Name','Description')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "vlan"
Method = "GET"
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers = @($Id) }
"ByNumber" { $_identifiers = @("search",$Number) }
"ByL2Domain"{
$_params.Item("Controller") = "l2domains"
$_l2domainId = $L2DomainId
$_identifiers = @($_l2domainId,"vlans")
}
}
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | Select-Object @{n="id";e={$_.vlanId}},* | Select-Object -ExcludeProperty vlanId | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember -Function Get-PSIPAMVlan

View File

@@ -1,26 +0,0 @@
function Get-PSIPAMVrf {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id
)
process {
[string[]]$visiblePropertiesList = @('Id','Name','Description')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{
Controller = "vrf"
Method = "GET"
}
if ($Id) { $_identifiers = @($Id) }
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | Select-Object @{n="id";e={$_.vrfId}},* | Select-Object -ExcludeProperty vrfId | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
}
}
Export-ModuleMember -Function Get-PSIPAMVrf

View File

@@ -1,5 +1,5 @@
function Get-PSIPAMAddress { function Get-Permissions {
[CmdletBinding(DefaultParameterSetName="ByID")] [CmdletBinding()]
param ( param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })] [ValidateScript({ $_ -match "^\d+$" })]
@@ -41,10 +41,10 @@ function Get-PSIPAMAddress {
Method = "GET" Method = "GET"
} }
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers = @($id) } "ByID" { $_identifiers = @($id); break }
"ByIP" { $_identifiers = ("search",$IP) } "ByIP" { $_identifiers = ("search",$IP); break }
"ByHostName" { $_identifiers = ("search_hostname",$HostName) } "ByHostName" { $_identifiers = ("search_hostname",$HostName); break }
"ByTag" { $_identifiers = ("tags",$TagId,"addresses") } "ByTag" { $_identifiers = ("tags",$TagId,"addresses"); break }
"BySubnetId" { "BySubnetId" {
if ($IP) { if ($IP) {
$_identifiers = ($IP,$SubnetId) $_identifiers = ($IP,$SubnetId)
@@ -52,19 +52,21 @@ function Get-PSIPAMAddress {
$_params.Item("Controller") = "subnets" $_params.Item("Controller") = "subnets"
$_identifiers = ($SubnetId,"addresses") $_identifiers = ($SubnetId,"addresses")
} }
break
} }
"BySubnetCIDR" { "BySubnetCIDR" {
$_params.Item("Controller") = "subnets" $_params.Item("Controller") = "subnets"
$_subnetId = (Get-PSIPAMSubnet -CIDR $SubnetCIDR).id $_subnetId = (Get-Subnet -CIDR $SubnetCIDR).id
if (!$_subnetId) { throw "Cannot find subnet!" } if (!$_subnetId) { throw "Cannot find subnet!" }
$_identifiers = ($_subnetId,"addresses") $_identifiers = ($_subnetId,"addresses")
break
} }
} }
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | ` Invoke-Request @_params | `
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
} }
} }
Export-ModuleMember -Function Get-PSIPAMAddress Export-ModuleMember -Function Get-Permissions

View File

@@ -0,0 +1,29 @@
function Get-Section {
[CmdletBinding(DefaultParameterSetName="NoParams")]
[OutputType([PS.IPAM.Section])]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")]
[ValidateNotNullOrEmpty()]
[int]
$Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByName")]
[ValidateNotNullOrEmpty()]
[string]
$Name
)
process {
$_params = @{
Controller = [PS.IPAM.controllers]::sections
Method = "GET"
Type = [PS.IPAM.types]::Section
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers = @($Id); break }
"ByName" { $_identifiers = @($Name); break }
}
$_params.Add("Identifiers",$_identifiers)
Invoke-Request @_params
}
}
Export-ModuleMember Get-Section

View File

@@ -1,5 +1,6 @@
function Get-PSIPAMSubnet { function Get-Subnet {
[CmdletBinding(DefaultParameterSetName="ByID")] [CmdletBinding(DefaultParameterSetName="NoParams")]
[OutputType([PS.IPAM.Subnetwork])]
param ( param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")] [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")]
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})] [ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
@@ -7,16 +8,14 @@ function Get-PSIPAMSubnet {
[string] [string]
$CIDR, $CIDR,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")] [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[string] [int]
$Id, $Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySectionId")] [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySectionId")]
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2,ParameterSetName="ByVlanNumber")] [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2,ParameterSetName="ByVlanNumber")]
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="ByVlanId")] [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="ByVlanId")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[string] [int]
$SectionId, $SectionId,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySectionName")] [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySectionName")]
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=3,ParameterSetName="ByVlanNumber")] [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=3,ParameterSetName="ByVlanNumber")]
@@ -25,25 +24,21 @@ function Get-PSIPAMSubnet {
[string] [string]
$SectionName, $SectionName,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVrfId")] [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVrfId")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[string] [int]
$VrfId, $VrfId,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVlanId")] [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVlanId")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[string] [int]
$VlanId, $VlanId,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVlanNumber")] [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByVlanNumber")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[string] [int]
$VlanNumber, $VlanNumber,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="ByVlanNumber")] [parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1,ParameterSetName="ByVlanNumber")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[string] [int]
$VlanDomain, $VlanDomainId,
[parameter(Mandatory=$false,ParameterSetName="ByID")] [parameter(Mandatory=$false,ParameterSetName="ByID")]
[switch] [switch]
$Slaves, $Slaves,
@@ -52,16 +47,14 @@ function Get-PSIPAMSubnet {
$Recurse $Recurse
) )
process { process {
[string[]]$visiblePropertiesList = @('Id','Subnet','Mask','Description')
$visibleProperties = [System.Management.Automation.PSPropertySet]::new('DefaultDisplayPropertySet',$visiblePropertiesList)
$_params = @{ $_params = @{
Controller = "subnets" Controller = [PS.IPAM.controllers]::subnets
Method = "GET" Method = "GET"
Type = [PS.IPAM.types]::Subnetwork
} }
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
"ByCIDR" { "ByCIDR" {
$_identifiers = @("cidr",$CIDR) $_identifiers = @("cidr",$CIDR); break
} }
"ByID" { "ByID" {
$_identifiers = @($Id) $_identifiers = @($Id)
@@ -73,42 +66,47 @@ function Get-PSIPAMSubnet {
$_identifiers += "slaves" $_identifiers += "slaves"
} }
} }
break
} }
"BySectionId" { "BySectionId" {
$_params.Item("Controller") = "sections" $_params.Item("Controller") = "sections"
$_sectionId = $SectionId $_sectionId = $SectionId
$_identifiers = @($_sectionId,"subnets") $_identifiers = @($_sectionId,"subnets")
break
} }
"BySectionName" { "BySectionName" {
$_params.Item("Controller") = "sections" $_params.Item("Controller") = "sections"
$_sectionId = (Get-PSIPAMSection -Name $SectionName).id $_sectionId = (Get-Section -Name $SectionName).id
if (!$_sectionId) { throw "Cannot find section!" } if (!$_sectionId) { throw "Cannot find section!" }
$_identifiers = @($_sectionId,"subnets") $_identifiers = @($_sectionId,"subnets")
break
} }
"ByVrfId" { "ByVrfId" {
$_params.Item("Controller") = "vrf" $_params.Item("Controller") = "vrf"
$_vrfId = $VrfId $_vrfId = $VrfId
$_identifiers = @($_vrfId,"subnets") $_identifiers = @($_vrfId,"subnets")
break
} }
"ByVlanId" { "ByVlanId" {
$_params.Item("Controller") = "vlan" $_params.Item("Controller") = "vlan"
$_vlanId = $VlanId $_vlanId = $VlanId
if ($SectionId) { $_sectionId = $SectionId } if ($SectionId) { $_sectionId = $SectionId }
if ($SectionName){ $_sectionId = (Get-PSIPAMSection -Name $SectionName).id } if ($SectionName){ $_sectionId = (Get-Section -Name $SectionName).id }
$_identifiers = @($_vlanId,"subnets") $_identifiers = @($_vlanId,"subnets")
if ($_sectionId) { $_identifiers += $_sectionId } if ($_sectionId) { $_identifiers += $_sectionId }
break
} }
"ByVlanNumber" { "ByVlanNumber" {
$_params.Item("Controller") = "vlan" $_params.Item("Controller") = "vlan"
$_vlans = Get-PSIPAMVlan -Number $VlanNumber $_vlans = Get-Vlan -Number $VlanNumber
if ($VlanDomain) { $_vlans = $_vlans | Where-Object {$_.domainId -eq $VlanDomain} } if ($VlanDomain) { $_vlans = $_vlans | Where-Object {$_.domainId -eq $VlanDomain} }
if ($SectionId) { $_sectionId = $SectionId } if ($SectionId) { $_sectionId = $SectionId }
if ($SectionName){ $_sectionId = (Get-PSIPAMSection -Name $SectionName).id } if ($SectionName){ $_sectionId = (Get-Section -Name $SectionName).id }
$_vlanId = $_vlans.vlanId $_vlanId = $_vlans.vlanId
@@ -118,12 +116,12 @@ function Get-PSIPAMSubnet {
$_identifiers = @($_vlanId,"subnets") $_identifiers = @($_vlanId,"subnets")
if ($_sectionId) { $_identifiers += $_sectionId } if ($_sectionId) { $_identifiers += $_sectionId }
break
} }
} }
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params | ` Invoke-Request @_params
Add-Member -MemberType MemberSet -Name PSStandardMembers -Value $visibleProperties -PassThru
} }
} }
Export-ModuleMember Get-PSIPAMSubnet Export-ModuleMember Get-Subnet

View File

@@ -1,4 +1,4 @@
function Get-PSIPAMSubnetUsage { function Get-SubnetUsage {
[CmdletBinding(DefaultParameterSetName="ByID")] [CmdletBinding(DefaultParameterSetName="ByID")]
param ( param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")] [parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByCIDR")]
@@ -19,15 +19,16 @@ function Get-PSIPAMSubnetUsage {
} }
switch ($PSCmdlet.ParameterSetName) { switch ($PSCmdlet.ParameterSetName) {
"ByCIDR" { "ByCIDR" {
$_subnetId = (Get-PSIPAMSubnet -CIDR $CIDR).id $_subnetId = (Get-Subnet -CIDR $CIDR).id
if (!$_subnetId) { throw "Cannot find subnet!" } if (!$_subnetId) { throw "Cannot find subnet!" }
break
} }
"ByID" { $_subnetId = $Id } "ByID" { $_subnetId = $Id; break }
} }
$_identifiers = @($_subnetId,"usage") $_identifiers = @($_subnetId,"usage")
$_params.Add("Identifiers",$_identifiers) $_params.Add("Identifiers",$_identifiers)
return Invoke-PSIPAMRequest @_params return Invoke-Request @_params
} }
} }
Export-ModuleMember -Function Get-PSIPAMSubnetUsage Export-ModuleMember -Function Get-SubnetUsage

View File

@@ -0,0 +1,49 @@
function Get-Tag {
[CmdletBinding(DefaultParameterSetName="NoParams")]
[OutputType([PS.IPAM.Tag])]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateNotNullOrEmpty()]
[int]
$Id,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByAddressObject")]
[ValidateNotNullOrEmpty()]
[PS.IPAM.Address]
$AddressObject,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetObject")]
[ValidateNotNullOrEmpty()]
[PS.IPAM.Subnetwork]
$SubnetObject
)
process {
$_params = @{
Controller = [PS.IPAM.controllers]::addresses
Method = "GET"
Type = [PS.IPAM.types]::tag
}
$_identifiers = @("tags")
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers += $Id; break }
"ByAddressObject" {
if ($AddressObject.TagId) {
$_identifiers += $AddressObject.TagId
} else {
return $null
}
break
}
"BySubnetObject" {
if ($SubnetObject.TagId) {
$_identifiers += $SubnetObject.TagId
} else {
return $null
}
break
}
}
$_params.Add("Identifiers",$_identifiers)
Invoke-Request @_params
}
}
Export-ModuleMember -Function Get-Tag

View File

@@ -0,0 +1,59 @@
function Get-Vlan {
[CmdletBinding(DefaultParameterSetName="ByID")]
[OutputType([PS.IPAM.Vlan])]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateNotNullOrEmpty()]
[int]
$Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByNumber")]
[ValidateNotNullOrEmpty()]
[int]
$Number,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByL2Domain")]
[ValidateNotNullOrEmpty()]
[int]
$L2DomainId,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetObject")]
[ValidateNotNullOrEmpty()]
[PS.IPAM.Subnetwork]
$SubnetObject,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByDomainObject")]
[ValidateNotNullOrEmpty()]
[PS.IPAM.Domain]
$DomainObject
)
process {
$_params = @{
Controller = [PS.IPAM.controllers]::vlan
Method = "GET"
Type = [PS.IPAM.types]::Vlan
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers = @($Id); break }
"ByNumber" { $_identifiers = @("search",$Number); break }
"ByL2Domain"{
$_params.Item("Controller") = [PS.IPAM.controllers]::l2domains
$_l2domainId = $L2DomainId
$_identifiers = @($_l2domainId,[PS.IPAM.subcontrollers]::vlans)
break
}
"BySubnetObject" {
if ($SubnetObject.VlanId) {
$_identifiers = @($SubnetObject.VlanId); break
} else {
return $null
}
}
"DomainObject" {
Get-Vlan -L2DomainId $DomainObject.Id
}
}
$_params.Add("Identifiers",$_identifiers)
Invoke-Request @_params
}
}
Export-ModuleMember -Function Get-Vlan

View File

@@ -0,0 +1,23 @@
function Get-Vrf {
[CmdletBinding(DefaultParameterSetName="ByID")]
[OutputType([PS.IPAM.Vrf])]
param (
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
[ValidateNotNullOrEmpty()]
[int]
$Id
)
process {
$_params = @{
Controller = [PS.IPAM.controllers]::vrf
Method = "GET"
Type = [PS.IPAM.types]::vrf
}
if ($Id) { $_identifiers = @($Id) }
$_params.Add("Identifiers",$_identifiers)
Invoke-Request @_params
}
}
Export-ModuleMember -Function Get-Vrf

View File

@@ -1,4 +1,4 @@
function New-PSIPAMAddress { function New-Address {
[CmdletBinding()] [CmdletBinding()]
param ( param (
[parameter( [parameter(
@@ -7,9 +7,8 @@ function New-PSIPAMAddress {
ValueFromPipelineByPropertyName=$true, ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of subnet address belongs to", HelpMessage="Id of subnet address belongs to",
Position=0)] Position=0)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[string] [int]
$SubnetId, $SubnetId,
[parameter( [parameter(
Mandatory=$true, Mandatory=$true,
@@ -72,9 +71,8 @@ function New-PSIPAMAddress {
ValueFromPipelineByPropertyName=$true, ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of subnet address belongs to", HelpMessage="Id of subnet address belongs to",
Position=7)] Position=7)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[string] [int]
$TagId, $TagId,
[parameter( [parameter(
Mandatory=$false, Mandatory=$false,
@@ -90,9 +88,8 @@ function New-PSIPAMAddress {
ValueFromPipelineByPropertyName=$true, ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of PowerDNS PTR record", HelpMessage="Id of PowerDNS PTR record",
Position=7)] Position=7)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[string] [int]
$PTRId, $PTRId,
[parameter( [parameter(
Mandatory=$false, Mandatory=$false,
@@ -117,9 +114,8 @@ function New-PSIPAMAddress {
ValueFromPipelineByPropertyName=$true, ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of device address belongs to", HelpMessage="Id of device address belongs to",
Position=12)] Position=12)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()] [ValidateNotNullOrEmpty()]
[string] [int]
$DeviceId, $DeviceId,
[parameter( [parameter(
Mandatory=$false, Mandatory=$false,
@@ -137,7 +133,7 @@ function New-PSIPAMAddress {
) )
process { process {
$_params = @{ $_params = @{
Controller = "addresses" Controller = [PS.IPAM.controllers]::addresses
Method = "POST" Method = "POST"
} }
@@ -172,11 +168,11 @@ function New-PSIPAMAddress {
$_params.Add("Params",$_body) $_params.Add("Params",$_body)
try { try {
Invoke-PSIPAMRequest @_params Invoke-Request @_params
} }
finally { finally {
Get-PSIPAMAddress -SubnetId $SubnetId -Ip $Ip Get-Address -SubnetId $SubnetId -Ip $Ip
} }
} }
} }
Export-ModuleMember -Function New-PSIPAMAddress Export-ModuleMember -Function New-Address

View File

@@ -1,4 +1,4 @@
function New-PSIPAMFirstFreeIP { function New-FirstFreeIP {
[CmdletBinding()] [CmdletBinding()]
param ( param (
[parameter( [parameter(
@@ -163,10 +163,10 @@ function New-PSIPAMFirstFreeIP {
$_params.Add("Params",$_body) $_params.Add("Params",$_body)
$_result = Invoke-PSIPAMRequest @_params $_result = Invoke-Request @_params
if ($_result) { if ($_result) {
Get-PSIPAMAddress -SubnetId $SubnetId -IP $_result Get-Address -SubnetId $SubnetId -IP $_result
} }
} }
} }
Export-ModuleMember -Function New-PSIPAMFirstFreeIP Export-ModuleMember -Function New-FirstFreeIP

View File

@@ -1,37 +0,0 @@
function New-PSIPAMSession {
[CmdletBinding()]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
[ValidateNotNullOrEmpty()]
[string]$URL,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1)]
[ValidateNotNullOrEmpty()]
[string]$AppID,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2)]
[ValidateNotNullOrEmpty()]
[pscredential]$Credentials
)
$_bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credentials.Password)
$_password = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($_bstr)
$_uri = "$URL/api/$AppID/user"
$_auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$($Credentials.UserName):$_password"))
$_headers = @{
"Accept" = "application/json"
"Content-Type" = "application/json"
"Authorization" = "Basic $_auth"
}
$_response = Invoke-RestMethod -Method Post -Uri $_uri -Headers $_headers -ErrorAction SilentlyContinue
if ($_response.success -eq $true) {
$script:ipamAuth = $true
$script:ipamToken = $_response.data.token
$script:ipamAppID = $AppID
$script:ipamURL = $URL
$script:ipamCredentials = $Credentials
$script:ipamExpires = Get-Date $_response.data.expires
} else {
$_response.error
}
}
Export-ModuleMember -Function New-PSIPAMSession

View File

@@ -1,202 +0,0 @@
function New-PSIPAMSubnet {
[CmdletBinding()]
param (
[parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="CIDR of subnet in dotted format (e.g 10.10.10.0/24)",
Position=0)]
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
[ValidateNotNullOrEmpty()]
[string]
$CIDR,
[parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Section identifier",
Position=1)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$SectionId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Subnet description",
Position=2)]
[string]
$Description,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Assigns subnet to VLAN",
Position=3)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$VlanId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Assigns subnet to VRF",
Position=4)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$VrfId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Master subnet id for nested subnet",
Position=5)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$MasterSubnetId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of nameserver to attach to subnet",
Position=6)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$NameserverId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls weather subnet is displayed as IP address or Name in subnets menu",
Position=7)]
[switch]
$ShowName,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls if PTR records should be created for subnet",
Position=8)]
[switch]
$DNSRecursive,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls weather hostname DNS records are displayed",
Position=9)]
[switch]
$DNSRecords,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls if IP requests are allowed for subnet",
Position=10)]
[switch]
$AllowRequests,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls which scanagent to use for subnet (default id 1)",
Position=11)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$ScanAgentId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls if new hosts should be discovered for new host scans",
Position=12)]
[switch]
$DiscoverSubnet,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Marks subnet as used",
Position=12)]
[switch]
$IsFull,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Assignes state (tag) to subnet (default: 1 Used)",
Position=12)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$TagId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Subnet threshold",
Position=13)]
[ValidateScript({ $_ -match "^\d+$" -and $_ -le 100 -and $_ -ge 1 })]
$Threshold,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Location index",
Position=14)]
[ValidateScript({ $_ -match "^\d+$" })]
[string]
$LocationId,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
$CustomFields
)
process {
$_params = @{
Controller = "subnets"
Method = "POST"
}
$_body = @{
subnet = $CIDR.Split('/')[0]
mask = $CIDR.Split('/')[1]
sectionId = $SectionId
}
if ($Description) { $_body.Add("description", $Description) }
if ($VlanId) { $_body.Add("vlanId", $VlanId) }
if ($VrfId) { $_body.Add("vrfId", $VrfId) }
if ($MasterSubnetId) { $_body.Add("masterSubnetId", $MasterSubnetId) }
if ($NameserverId) { $_body.Add("nameserverId", $NameserverId) }
if ($ShowName) { $_body.Add("showName", "1") }
if ($DNSRecursive) { $_body.Add("DNSrecursive", "1") }
if ($DNSRecords) { $_body.Add("DNSrecords", "1") }
if ($AllowRequests) { $_body.Add("allowRequests", "1") }
if ($ScanAgentId) { $_body.Add("scanAgent", $ScanAgentId) }
if ($DiscoverSubnet) { $_body.Add("discoverSubnet", "1") }
if ($IsFull) { $_body.Add("isFull", "1") }
if ($TagId) { $_body.Add("state", $TagId) }
if ($Threshold) { $_body.Add("threshold", $Threshold) }
if ($Location) { $_body.Add("location", $Location) }
if ($CustomFields) {
if ($CustomFields -is [PSCustomObject]) {
$_customFields = @{};
$CustomFields | Get-Member -MemberType *Property | Where-Object {
$_customFields.($_.name) = $CustomFields.($_.name)
}
} else { $_customFields = $CustomFields }
$_body = $_body + $_customFields
}
$_params.Add("Params",$_body)
$_result = Invoke-PSIPAMRequest @_params
if ($_result) {
return Get-PSIPAMSubnet -CIDR $_result
}
}
}
Export-ModuleMember -Function New-PSIPAMSubnet

View File

@@ -0,0 +1,59 @@
function New-Session {
[CmdletBinding(DefaultParameterSetName="Credentials")]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0)]
[ValidateNotNullOrEmpty()]
[validatescript({$_.startswith("http")})]
[string]$URL,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=1)]
[ValidateNotNullOrEmpty()]
[string]$AppID,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2,ParameterSetName="Credentials")]
[ValidateNotNullOrEmpty()]
[pscredential]$Credentials,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=2,ParameterSetName="Token")]
[ValidateNotNullOrEmpty()]
[string]$Token,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=3)]
[switch]$IgnoreSSL = $false
)
switch ($PSCmdlet.ParameterSetName) {
"Credentials" {
$_bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Credentials.Password)
$_password = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($_bstr)
$_uri = "$URL/api/$AppID/user"
$_auth = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("$($Credentials.UserName):$_password"))
$_headers = @{
"Accept" = "application/json"
"Content-Type" = "application/json"
"Authorization" = "Basic $_auth"
}
$_response = Invoke-RestMethod -Method POST -Uri $_uri -Headers $_headers
if ($_response.success -ne $true) { return $_response.error }
$script:psipamSession = [PS.IPAM.Session]::new(
[ps.ipam.authType]::credentials,
$_response.data.token,
$AppID,
$URL,
(Get-Date $_response.data.expires),
$Credentials
)
break
}
"Token" {
$script:psipamSession = [PS.IPAM.Session]::new(
[ps.ipam.authType]::token,
$Token,
$AppID,
$URL,
$null,
$null
)
break
}
}
}
Export-ModuleMember -Function New-Session

View File

@@ -0,0 +1,124 @@
function New-Subnet {
[CmdletBinding()]
param (
[parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="CIDR of subnet in dotted format (e.g 10.10.10.0/24)",
Position=0)]
[ValidateScript({[ipaddress] $_.Split("/")[0] -and $_.Split("/")[1] -match "\d{1,2}"})]
[ValidateNotNullOrEmpty()]
[string]
$CIDR,
[parameter(Mandatory=$true,HelpMessage="Section identifier",Position=1)]
[ValidateNotNullOrEmpty()]
[int]
$SectionId,
[parameter(Mandatory=$false,HelpMessage="Subnet description",Position=2)]
[ValidateNotNullOrEmpty()]
[string]
$Description,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Assigns subnet to VLAN",Position=3)]
[ValidateNotNullOrEmpty()]
[int]
$VlanId,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Assigns subnet to VRF",Position=4)]
[ValidateNotNullOrEmpty()]
[int]
$VrfId,
[parameter(Mandatory=$false,HelpMessage="Master subnet id for nested subnet",Position=5)]
[ValidateNotNullOrEmpty()]
[int]
$MasterSubnetId,
[parameter(Mandatory=$false,HelpMessage="Id of nameserver to attach to subnet",Position=6)]
[ValidateNotNullOrEmpty()]
[int]
$NameserverId,
[parameter(Mandatory=$false,HelpMessage="Controls weather subnet is displayed as IP address or Name in subnets menu",Position=7)]
[switch]
$ShowName,
[parameter(Mandatory=$false,HelpMessage="Controls if PTR records should be created for subnet",Position=8)]
[switch]
$DNSRecursive,
[parameter(Mandatory=$false,HelpMessage="Controls weather hostname DNS records are displayed",Position=9)]
[switch]
$DNSRecords,
[parameter(Mandatory=$false,HelpMessage="Controls if IP requests are allowed for subnet",Position=10)]
[switch]
$AllowRequests,
[parameter(Mandatory=$false,HelpMessage="Controls which scanagent to use for subnet (default id 1)",Position=11)]
[ValidateNotNullOrEmpty()]
[int]
$ScanAgentId,
[parameter(Mandatory=$false,HelpMessage="Controls if new hosts should be discovered for new host scans",Position=12)]
[switch]
$DiscoverSubnet,
[parameter(Mandatory=$false,HelpMessage="Marks subnet as used",Position=12)]
[switch]
$IsFull,
[parameter(Mandatory=$false,HelpMessage="Assignes state (tag) to subnet (default: 1 Used)",Position=12)]
[ValidateNotNullOrEmpty()]
[int]
$TagId,
[parameter(Mandatory=$false,HelpMessage="Subnet threshold",Position=13)]
[ValidateScript({ $_ -le 100 -and $_ -ge 1 })]
[ValidateNotNullOrEmpty()]
[int]
$Threshold,
[parameter(Mandatory=$false,HelpMessage="Location index",Position=14)]
[ValidateNotNullOrEmpty()]
[int]
$LocationId,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
[ValidateNotNullOrEmpty()]
$CustomFields
)
process {
$_params = @{
Controller = "subnets"
Method = "POST"
}
$_body = @{
subnet = $CIDR.Split('/')[0]
mask = $CIDR.Split('/')[1]
sectionId = $SectionId
}
if ($Description) { $_body.Add("description", $Description) }
if ($VlanId) { $_body.Add("vlanId", $VlanId) }
if ($VrfId) { $_body.Add("vrfId", $VrfId) }
if ($MasterSubnetId) { $_body.Add("masterSubnetId", $MasterSubnetId) }
if ($NameserverId) { $_body.Add("nameserverId", $NameserverId) }
if ($ShowName) { $_body.Add("showName", "1") }
if ($DNSRecursive) { $_body.Add("DNSrecursive", "1") }
if ($DNSRecords) { $_body.Add("DNSrecords", "1") }
if ($AllowRequests) { $_body.Add("allowRequests", "1") }
if ($ScanAgentId) { $_body.Add("scanAgent", $ScanAgentId) }
if ($DiscoverSubnet) { $_body.Add("discoverSubnet", "1") }
if ($IsFull) { $_body.Add("isFull", "1") }
if ($TagId) { $_body.Add("state", $TagId) }
if ($Threshold) { $_body.Add("threshold", $Threshold) }
if ($Location) { $_body.Add("location", $Location) }
if ($CustomFields) {
if ($CustomFields -is [PSCustomObject]) {
$_customFields = @{};
$CustomFields | Get-Member -MemberType *Property | Where-Object {
$_customFields.($_.name) = $CustomFields.($_.name)
}
} else { $_customFields = $CustomFields }
$_body = $_body + $_customFields
}
$_params.Add("Params",$_body)
$_result = Invoke-Request @_params
if ($_result) {
return Get-Subnet -CIDR $_result
}
}
}
Export-ModuleMember -Function New-Subnet

View File

@@ -0,0 +1,28 @@
function Remove-Address {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")]
[ValidateNotNullOrEmpty()]
[int]
$Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByAddressObject")]
[ValidateNotNullOrEmpty()]
[PS.IPAM.Address]
$AddressObject
)
process {
$_params = @{
Controller = [PS.IPAM.controllers]::addresses
Method = "DELETE"
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers = @($Id); break }
"ByAddressObject" { $_identifiers = @($AddressObject.Id); break }
}
$_params.Add("Identifiers",$_identifiers)
Invoke-Request @_params
}
}
Export-ModuleMember Remove-Address

View File

@@ -1,35 +0,0 @@
function Remove-PSIPAMAddress {
[CmdletBinding(DefaultParameterSetName="ByID")]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id,
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByIP")]
[ValidateScript({[ipaddress] $_ })]
[ValidateNotNullOrEmpty()]
[string]
$IP,
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=1,ParameterSetName="ByIP")]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$SubnetId
)
process {
$_params = @{
Controller = "addresses"
Method = "DELETE"
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_identifiers = @($Id) }
"ByIP" { $_identifiers = @($IP,$SubnetId) }
}
$_params.Add("Identifiers",$_identifiers)
Invoke-PSIPAMRequest @_params
}
}
Export-ModuleMember Remove-PSIPAMAddress

View File

@@ -0,0 +1,110 @@
function Set-Address {
[CmdletBinding(DefaultParameterSetName="ById")]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="Id of subnet address belongs to",Position=0,ParameterSetName="ById")]
[ValidateNotNullOrEmpty()]
[int]
$Id,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByAddressObject")]
[ValidateNotNullOrEmpty()]
[PS.IPAM.Address]
$AddressObject,
[parameter(Mandatory=$false,HelpMessage="Defines if address is presented as gateway",Position=1)]
[bool]
$Gateway,
[parameter(Mandatory=$false,HelpMessage="Address description",Position=2)]
[ValidateNotNullOrEmpty()]
[string]
$Description,
[parameter(Mandatory=$false,HelpMessage="Address hostname",Position=3)]
[ValidateNotNullOrEmpty()]
[string]
$Hostname,
[parameter(Mandatory=$false,HelpMessage="Mac address",Position=4)]
[ValidateScript({ $_.Replace(":","") -match "^$('([A-F0-9]{2})' * 6)$" })]
[ValidateNotNullOrEmpty()]
[string]
$MAC,
[parameter(Mandatory=$false,HelpMessage="Address owner",Position=5)]
[ValidateNotNullOrEmpty()]
[string]
$Owner,
[parameter(Mandatory=$false,HelpMessage="Id of subnet address belongs to",Position=6)]
[ValidateNotNullOrEmpty()]
[int]
$TagId,
[parameter(Mandatory=$false,HelpMessage="Controls if PTR should not be created",Position=7)]
[bool]
$PTRIgnore,
[parameter(Mandatory=$false,HelpMessage="Id of PowerDNS PTR record",Position=8)]
[ValidateNotNullOrEmpty()]
[int]
$PTRId,
[parameter(Mandatory=$false,HelpMessage="Note",Position=9)]
[ValidateNotNullOrEmpty()]
[string]
$Note,
[parameter(Mandatory=$false,HelpMessage="Exclude this address from status update scans (ping)",Position=10)]
[bool]
$ExcludePing,
[parameter(Mandatory=$false,HelpMessage="Id of device address belongs to",Position=11)]
[ValidateNotNullOrEmpty()]
[int]
$DeviceId,
[parameter(Mandatory=$false,HelpMessage="Port",Position=12)]
[ValidateNotNullOrEmpty()]
[string]
$Port,
[parameter(Mandatory=$false)]
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
$CustomFields
)
process {
$_params = @{
Controller = [PS.IPAM.controllers]::addresses
Method = "PATCH"
}
switch ($PSCmdlet.ParameterSetName) {
"ByID" { $_id = $Id; break }
"ByAddressObject" { $_id = $AddressObject.id; break }
}
$_identifiers = @($_id)
$_params.Add("Identifiers",$_identifiers)
$_body = @{ }
if ($Gateway) { $_body.Add("is_gateway", $Gateway) }
if ($Description) { $_body.Add("description", $Description) }
if ($Hostname) { $_body.Add("hostname", $Hostname) }
if ($MAC) { $_body.Add("mac", $MAC) }
if ($Owner) { $_body.Add("owner", $Owner) }
if ($TagId) { $_body.Add("tag", $TagId) }
if ($PTRIgnore) { $_body.Add("PTRignore", $PTRIgnore) }
if ($PTRId) { $_body.add("PTR", $PTRId)}
if ($Note) { $_body.Add("note", $Note) }
if ($ExcludePing) { $_body.Add("excludePing", $ExcludePing) }
if ($DeviceId) { $_body.Add("deviceId", $DeviceId) }
if ($Port) { $_body.Add("port", $Port) }
if ($CustomFields) {
if ($CustomFields -is [PSCustomObject]) {
$_customFields = @{};
$CustomFields | Get-Member -MemberType *Property | Where-Object {
$_customFields.($_.name) = $CustomFields.($_.name)
}
} else { $_customFields = $CustomFields }
$_body = $_body + $_customFields
}
$_params.Add("Params",$_body)
try {
Invoke-Request @_params
}
finally {
Get-Address -Id $_id
}
}
}
Export-ModuleMember -Function Set-Address

View File

@@ -1,172 +0,0 @@
function Set-PSIPAMAddress {
[CmdletBinding()]
param (
[parameter(
Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of subnet address belongs to",
Position=0)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$Id,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Defines if address is presented as gateway",
Position=1)]
[bool]
$Gateway,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Address description",
Position=2)]
[ValidateNotNullOrEmpty()]
[string]
$Description,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Address hostname",
Position=3)]
[ValidateNotNullOrEmpty()]
[string]
$Hostname,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Mac address",
Position=4)]
[ValidateScript({ $_.Replace(":","") -match "^$('([A-F0-9]{2})' * 6)$" })]
[ValidateNotNullOrEmpty()]
[string]
$MAC,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Address owner",
Position=5)]
[ValidateNotNullOrEmpty()]
[string]
$Owner,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of subnet address belongs to",
Position=6)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$TagId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Controls if PTR should not be created",
Position=7)]
[bool]
$PTRIgnore,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of PowerDNS PTR record",
Position=8)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$PTRId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Note",
Position=9)]
[ValidateNotNullOrEmpty()]
[string]
$Note,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Exclude this address from status update scans (ping)",
Position=10)]
[bool]
$ExcludePing,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Id of device address belongs to",
Position=11)]
[ValidateScript({ $_ -match "^\d+$" })]
[ValidateNotNullOrEmpty()]
[string]
$DeviceId,
[parameter(
Mandatory=$false,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
HelpMessage="Port",
Position=12)]
[ValidateNotNullOrEmpty()]
[string]
$Port,
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
$CustomFields
)
process {
$_params = @{
Controller = "addresses"
Method = "PATCH"
}
$_identifiers = @($Id)
$_params.Add("Identifiers",$_identifiers)
$_body = @{ }
if ($Gateway) { $_body.Add("is_gateway", [int]$Gateway) }
if ($Description) { $_body.Add("description", $Description) }
if ($Hostname) { $_body.Add("hostname", $Hostname) }
if ($MAC) { $_body.Add("mac", $MAC) }
if ($Owner) { $_body.Add("owner", $Owner) }
if ($TagId) { $_body.Add("tag", $TagId) }
if ($PTRIgnore) { $_body.Add("PTRignore", [int]$PTRIgnore) }
if ($PTRId) { $_body.add("PTR", $PTRId)}
if ($Note) { $_body.Add("note", $Note) }
if ($ExcludePing) { $_body.Add("excludePing", [int]$ExcludePing) }
if ($DeviceId) { $_body.Add("deviceId", $DeviceId) }
if ($Port) { $_body.Add("port", $Port) }
if ($CustomFields) {
if ($CustomFields -is [PSCustomObject]) {
$_customFields = @{};
$CustomFields | Get-Member -MemberType *Property | Where-Object {
$_customFields.($_.name) = $CustomFields.($_.name)
}
} else { $_customFields = $CustomFields }
$_body = $_body + $_customFields
}
$_params.Add("Params",$_body)
try {
Invoke-PSIPAMRequest @_params
}
finally {
Get-PSIPAMAddress -Id $Id
}
}
}
Export-ModuleMember -Function Set-PSIPAMAddress

Binary file not shown.

172
types/types.ps1xml Normal file
View File

@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="utf-8" ?>
<Types>
<Type>
<Name>ps.ipam.address</Name>
<Members>
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
<PropertySet>
<Name>DefaultDisplayPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
<Name>Ip</Name>
<Name>Hostname</Name>
<Name>Description</Name>
</ReferencedProperties>
</PropertySet>
<PropertySet>
<Name>DefaultKeyPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
</ReferencedProperties>
</PropertySet>
</Members>
</MemberSet>
</Members>
</Type>
<Type>
<Name>ps.ipam.tag</Name>
<Members>
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
<PropertySet>
<Name>DefaultDisplayPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
<Name>Type</Name>
</ReferencedProperties>
</PropertySet>
<PropertySet>
<Name>DefaultKeyPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
</ReferencedProperties>
</PropertySet>
</Members>
</MemberSet>
</Members>
</Type>
<Type>
<Name>ps.ipam.domain</Name>
<Members>
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
<PropertySet>
<Name>DefaultDisplayPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
<Name>Name</Name>
</ReferencedProperties>
</PropertySet>
<PropertySet>
<Name>DefaultKeyPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
</ReferencedProperties>
</PropertySet>
</Members>
</MemberSet>
</Members>
</Type>
<Type>
<Name>ps.ipam.section</Name>
<Members>
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
<PropertySet>
<Name>DefaultDisplayPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
<Name>Name</Name>
<Name>MasterSectionId</Name>
<Name>StrictMode</Name>
</ReferencedProperties>
</PropertySet>
<PropertySet>
<Name>DefaultKeyPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
</ReferencedProperties>
</PropertySet>
</Members>
</MemberSet>
</Members>
</Type>
<Type>
<Name>ps.ipam.vlan</Name>
<Members>
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
<PropertySet>
<Name>DefaultDisplayPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
<Name>Name</Name>
<Name>DomainId</Name>
<Name>Number</Name>
</ReferencedProperties>
</PropertySet>
<PropertySet>
<Name>DefaultKeyPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
</ReferencedProperties>
</PropertySet>
</Members>
</MemberSet>
</Members>
</Type>
<Type>
<Name>ps.ipam.vrf</Name>
<Members>
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
<PropertySet>
<Name>DefaultDisplayPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
<Name>Name</Name>
</ReferencedProperties>
</PropertySet>
<PropertySet>
<Name>DefaultKeyPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
</ReferencedProperties>
</PropertySet>
</Members>
</MemberSet>
</Members>
</Type>
<Type>
<Name>ps.ipam.subnet</Name>
<Members>
<MemberSet>
<Name>PSStandardMembers</Name>
<Members>
<PropertySet>
<Name>DefaultDisplayPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
<Name>Name</Name>
<Name>DomainId</Name>
<Name>Number</Name>
</ReferencedProperties>
</PropertySet>
<PropertySet>
<Name>DefaultKeyPropertySet</Name>
<ReferencedProperties>
<Name>Id</Name>
</ReferencedProperties>
</PropertySet>
</Members>
</MemberSet>
</Members>
</Type>
</Types>