Types-implement #5
@@ -14,10 +14,10 @@ public class Domain {
|
||||
string description,
|
||||
string sections
|
||||
) {
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
this.Description = description;
|
||||
this.Sections = sections;
|
||||
this.Sections = sections;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
||||
25
classlib/class/nameserver.cs
Normal file
25
classlib/class/nameserver.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace PS.IPAM;
|
||||
using System;
|
||||
|
||||
[Serializable]
|
||||
public class Nameserver {
|
||||
public int Id { get; }
|
||||
public string Name { get; }
|
||||
public string[] NameSevers { get; }
|
||||
public string Permissions { get; }
|
||||
public DateTime? EditDate { get; }
|
||||
|
||||
public Nameserver(
|
||||
int id,
|
||||
string name,
|
||||
string nameServers,
|
||||
string permissions,
|
||||
DateTime? editDate
|
||||
) {
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
this.NameSevers = nameServers.Split(';');
|
||||
this.Permissions = permissions;
|
||||
this.EditDate = editDate;
|
||||
}
|
||||
}
|
||||
@@ -34,20 +34,20 @@ public class Section {
|
||||
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.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;
|
||||
this.DNSId = dnsId;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
||||
@@ -17,11 +17,11 @@ public class Session {
|
||||
DateTime? expires,
|
||||
Object? credentials
|
||||
) {
|
||||
AuthType = authType;
|
||||
Token = token;
|
||||
AppID = appId;
|
||||
URL = url;
|
||||
Expires = expires;
|
||||
AuthType = authType;
|
||||
Token = token;
|
||||
AppID = appId;
|
||||
URL = url;
|
||||
Expires = expires;
|
||||
Credentials = credentials;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,38 +69,38 @@ public class Subnetwork {
|
||||
Object calculation,
|
||||
Object? custom_fields
|
||||
) {
|
||||
this.Id = id;
|
||||
this.Subnet = subnet;
|
||||
this.Mask = mask;
|
||||
this.SectionId = sectionId;
|
||||
this.Description = description;
|
||||
this.LinkedSubnet = linkedSubnet;
|
||||
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;
|
||||
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() {
|
||||
|
||||
@@ -22,13 +22,13 @@ public class Vlan : DynamicObject {
|
||||
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.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;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,13 +20,13 @@ public class Vrf {
|
||||
DateTime? editDate,
|
||||
Object? custom_fields
|
||||
) {
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
this.Id = id;
|
||||
this.Name = name;
|
||||
this.RouteDistinguisher = rd;
|
||||
this.Description = description;
|
||||
this.Sections = sections;
|
||||
this.EditDate = editDate;
|
||||
this.ExtendedData = custom_fields;
|
||||
this.Description = description;
|
||||
this.Sections = sections;
|
||||
this.EditDate = editDate;
|
||||
this.ExtendedData = custom_fields;
|
||||
}
|
||||
public override string ToString()
|
||||
{
|
||||
|
||||
@@ -26,11 +26,9 @@ function Invoke-Request {
|
||||
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 '/')/" }
|
||||
if ($SubController -ne $null) { $SubController;$_uri += "/$SubController" }
|
||||
if ($Identifiers -ne $null) { $_uri += "/$($Identifiers -join '/')/" }
|
||||
|
||||
$_headers = @{
|
||||
"Accept" = "application/json"
|
||||
@@ -60,42 +58,48 @@ function Invoke-Request {
|
||||
|
||||
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
|
||||
try {
|
||||
$_response = Invoke-RestMethod @_arguments
|
||||
}
|
||||
catch [System.Net.WebException] {
|
||||
switch ($_.Exception.Message) {
|
||||
"The remote server returned an error: (404) Not Found." { Write-Verbose -Message "Not found." }
|
||||
"The remote server returned an error: (400) Bad Request." { Write-Warning -Message "Bad Request." }
|
||||
Default { Write-Verbose -Message "Error occured while requesting api" }
|
||||
}
|
||||
}
|
||||
if (!$_response) { return $null }
|
||||
|
||||
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_\*'))
|
||||
}
|
||||
}
|
||||
"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_\*'))
|
||||
}
|
||||
}
|
||||
"subnetwork" {
|
||||
$_response.data | ForEach-Object {
|
||||
New-Object -TypeName ([PS.IPAM.Subnetwork]) -ArgumentList (@($_.psobject.properties.value[0..30]) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
||||
}
|
||||
}
|
||||
"vrf" {
|
||||
$_response.data | ForEach-Object {
|
||||
New-Object -TypeName ([PS.IPAM.Vrf]) -ArgumentList (@($_.psobject.properties.value[0..5]) + ($_ | Select-Object -Property custom_* -ExcludeProperty 'custom_\*'))
|
||||
}
|
||||
}
|
||||
Default { $_response.data | ForEach-Object { New-Object -TypeName ("PS.IPAM.$Type") -ArgumentList $_.psobject.properties.value } }
|
||||
}
|
||||
|
||||
} else {
|
||||
throw ("Error - $($_response.code)")
|
||||
$_response.data
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,16 @@ function Get-Address {
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$HostName,
|
||||
[parameter(
|
||||
Mandatory=$true,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
Position=0,
|
||||
ParameterSetName="ByHostBase"
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$HostBase,
|
||||
[parameter(
|
||||
Mandatory=$true,
|
||||
ValueFromPipeline=$true,
|
||||
@@ -81,6 +91,7 @@ function Get-Address {
|
||||
"ByID" { $_identifiers = @($id); break }
|
||||
"ByIP" { $_identifiers = ("search",$IP); break }
|
||||
"ByHostName" { $_identifiers = ("search_hostname",$HostName); break }
|
||||
"ByHostBase" { $_identifiers = ("search_hostbase",$HostBase); break }
|
||||
"ByTag" { $_identifiers = ("tags",$TagId,[PS.IPAM.controllers]::addresses); break }
|
||||
"BySubnetId" {
|
||||
if ($IP) {
|
||||
|
||||
@@ -1,16 +1,34 @@
|
||||
function Get-FirstFreeIP {
|
||||
[CmdletBinding(DefaultParameterSetName="ByID")]
|
||||
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}"})]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$CIDR,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
||||
[parameter(
|
||||
Mandatory=$true,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
Position=0,
|
||||
ParameterSetName="ByID"
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[int]
|
||||
$Id,
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetObject")]
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
Position=0,
|
||||
ParameterSetName="BySubnetObject"
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[PS.IPAM.Subnetwork]
|
||||
$SubnetObject
|
||||
|
||||
@@ -2,7 +2,13 @@ function Get-L2Domain {
|
||||
[CmdletBinding(DefaultParameterSetName="ByID")]
|
||||
[OutputType([PS.IPAM.Domain])]
|
||||
param (
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
Position=0,
|
||||
ParameterSetName="ByID"
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[int]
|
||||
$Id
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
function Get-Nameserver {
|
||||
[CmdletBinding(DefaultParameterSetName="ByID")]
|
||||
param (
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
ValueFromPipelineByPropertyName=$true,
|
||||
Position=0,
|
||||
ParameterSetName="ByID"
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[int]
|
||||
$Id
|
||||
|
||||
@@ -2,11 +2,21 @@ function Get-Section {
|
||||
[CmdletBinding(DefaultParameterSetName="NoParams")]
|
||||
[OutputType([PS.IPAM.Section])]
|
||||
param (
|
||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,Position=0,ParameterSetName="ByID")]
|
||||
[parameter(
|
||||
Mandatory=$false,
|
||||
ValueFromPipeline=$true,
|
||||
Position=0,
|
||||
ParameterSetName="ByID"
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[int]
|
||||
$Id,
|
||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,Position=0,ParameterSetName="ByName")]
|
||||
[parameter(
|
||||
Mandatory=$true,
|
||||
ValueFromPipeline=$true,
|
||||
Position=0,
|
||||
ParameterSetName="ByName"
|
||||
)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string]
|
||||
$Name
|
||||
|
||||
Reference in New Issue
Block a user