update
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
trigger:
|
||||
- main
|
||||
|
||||
name: 'ITD.Infra-Networking-Infoblox'
|
||||
|
||||
variables:
|
||||
major: 1
|
||||
minor: 2
|
||||
patch: $(Build.BuildID)
|
||||
buildVer: $(major).$(minor).$(Build.BuildID)
|
||||
|
||||
pool: itdwinautop1
|
||||
|
||||
stages:
|
||||
- stage: Build
|
||||
jobs:
|
||||
- job: Build
|
||||
steps:
|
||||
- task: PowerShell@2
|
||||
inputs:
|
||||
filePath: '$(System.DefaultWorkingDirectory)/Build/build.ps1'
|
||||
- task: NuGetCommand@2
|
||||
inputs:
|
||||
command: 'pack'
|
||||
packagesToPack: '$(System.DefaultWorkingDirectory)/ITD.Infra-Networking-Infoblox.nuspec'
|
||||
versioningScheme: byEnvVar
|
||||
versionEnvVar: buildVer
|
||||
buildProperties: 'VERSIONHERE=$(buildVer)'
|
||||
- task: PublishBuildArtifacts@1
|
||||
inputs:
|
||||
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
|
||||
ArtifactName: 'NuGetPackage'
|
||||
publishLocation: 'Container'
|
||||
- stage: Deploy
|
||||
jobs:
|
||||
- job: Deploy
|
||||
steps:
|
||||
- task: DownloadPipelineArtifact@2
|
||||
inputs:
|
||||
buildType: 'current'
|
||||
artifactName: 'NuGetPackage'
|
||||
itemPattern: '**'
|
||||
targetPath: '$(Pipeline.Workspace)'
|
||||
- task: NuGetCommand@2
|
||||
inputs:
|
||||
command: 'push'
|
||||
packagesToPush: '$(Pipeline.Workspace)/ITD.Infra-Networking-Infoblox.$(major).$(minor).$(Build.BuildID).nupkg'
|
||||
nuGetFeedType: external
|
||||
publishFeedCredentials: 'ITD_PwshGallery'
|
||||
@@ -0,0 +1,17 @@
|
||||
$buildVersion = $env:BUILDVER
|
||||
$moduleName = 'ITD.Infra-Networking-Infoblox'
|
||||
|
||||
$manifestPath = Join-Path -Path $env:SYSTEM_DEFAULTWORKINGDIRECTORY -ChildPath "$moduleName.psd1"
|
||||
$modulePath = Join-Path -Path $env:SYSTEM_DEFAULTWORKINGDIRECTORY -ChildPath "$moduleName.psm1"
|
||||
|
||||
## Update build version in manifest
|
||||
$manifestContent = Get-Content -Path $manifestPath -Raw
|
||||
$manifestContent = $manifestContent -replace '<ModuleVersion>', $buildVersion
|
||||
|
||||
## Update functions to export in manifest
|
||||
Import-Module $modulePath
|
||||
$funcStrings = (Get-Module ITD.Infra-Networking-Infoblox).ExportedCommands.Values.Name
|
||||
$funcStrings = "'$($funcStrings -join "','")'"
|
||||
$manifestContent = $manifestContent -replace "<FunctionsToExport>", $funcStrings
|
||||
|
||||
$manifestContent | Set-Content -Path $manifestPath
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0"?>
|
||||
<package>
|
||||
<metadata>
|
||||
<id>ITD.Infra-Networking-Infoblox</id>
|
||||
<version>$VERSIONHERE$</version>
|
||||
<authors>Zack Meier</authors>
|
||||
<description>Functions for Infoblox use</description>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="**" exclude="**\.git\**;**\Build\**" />
|
||||
</files>
|
||||
</package>
|
||||
@@ -0,0 +1,10 @@
|
||||
@{
|
||||
RootModule = 'ITD.Infra-Networking-Infoblox.psm1'
|
||||
ModuleVersion = '<ModuleVersion>'
|
||||
GUID = '32fa3228-dfa3-4cc9-aac8-e14332a46abf'
|
||||
Author = 'Zack Meier'
|
||||
CompanyName = 'State of North Dakota'
|
||||
PowerShellVersion = '5.1'
|
||||
CompatiblePSEditions = 'Desktop','Core'
|
||||
FunctionsToExport = @(<FunctionsToExport>)
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
<#
|
||||
.Synopsis
|
||||
Short description
|
||||
.DESCRIPTION
|
||||
Long description
|
||||
.EXAMPLE
|
||||
Example of how to use this cmdlet
|
||||
.EXAMPLE
|
||||
Another example of how to use this cmdlet
|
||||
#>
|
||||
function Get-ITDIbDNSRecord {
|
||||
[CmdletBinding()]
|
||||
Param
|
||||
(
|
||||
[string[]]
|
||||
$Hostname,
|
||||
|
||||
[PSCredential]
|
||||
$Credential
|
||||
)
|
||||
|
||||
Begin {
|
||||
If (!($Credential)) {
|
||||
$Credential = Get-Credential
|
||||
}
|
||||
}
|
||||
Process {
|
||||
$result = @()
|
||||
ForEach ($h in $hostname) {
|
||||
$x = Invoke-RestMethod -Method Get -Uri "https://infoblox-gmv.ns.nd.gov/wapi/v2.7/record:host?name=$h" -ContentType "application/json" -Credential $Credential
|
||||
If ($x) {
|
||||
$obj = [PSCustomObject]@{
|
||||
'HostName' = $x.ipv4addrs.Host;
|
||||
'IPv4Address' = $x.ipv4addrs.ipv4addr
|
||||
'DHCP' = $x.ipv4addrs.configure_for_dhcp
|
||||
}
|
||||
$result += $obj
|
||||
}
|
||||
}
|
||||
}
|
||||
End {
|
||||
Write-Output $result
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.Synopsis
|
||||
Short description
|
||||
.DESCRIPTION
|
||||
Long description
|
||||
.EXAMPLE
|
||||
Example of how to use this cmdlet
|
||||
.EXAMPLE
|
||||
Another example of how to use this cmdlet
|
||||
#>
|
||||
function New-ITDIbDNSRecord {
|
||||
[CmdletBinding()]
|
||||
Param
|
||||
(
|
||||
[ipaddress]
|
||||
$IPv4Address,
|
||||
|
||||
[string]
|
||||
$Hostname,
|
||||
|
||||
[PSCredential]
|
||||
$Credential
|
||||
)
|
||||
|
||||
Begin {
|
||||
If (!($Credential)) {
|
||||
$Credential = Get-Credential
|
||||
}
|
||||
|
||||
$Uri = "https://infoblox-gmv.ns.nd.gov/wapi/v2.7/record:host"
|
||||
$IPs = @([PSCustomObject]@{'ipv4addr' = $IPv4Address })
|
||||
}
|
||||
Process {
|
||||
$obj = [PSCustomObject]@{
|
||||
'ipv4addrs' = $IPs;
|
||||
'name' = $Hostname;
|
||||
'view' = "default";
|
||||
}
|
||||
$postJson = $obj | ConvertTo-Json
|
||||
Invoke-RestMethod -Uri $Uri -Method Post -Body $postJson -ContentType "application/json" -Credential $Credential
|
||||
}
|
||||
End {
|
||||
}
|
||||
}
|
||||
|
||||
function Get-IPs {
|
||||
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[array]
|
||||
$Subnets
|
||||
)
|
||||
|
||||
foreach ($subnet in $subnets) {
|
||||
|
||||
#Split IP and subnet
|
||||
$IP = ($Subnet -split "\/")[0]
|
||||
$SubnetBits = ($Subnet -split "\/")[1]
|
||||
|
||||
#Convert IP into binary
|
||||
#Split IP into different octects and for each one, figure out the binary with leading zeros and add to the total
|
||||
$Octets = $IP -split "\."
|
||||
$IPInBinary = @()
|
||||
foreach ($Octet in $Octets) {
|
||||
#convert to binary
|
||||
$OctetInBinary = [convert]::ToString($Octet, 2)
|
||||
|
||||
#get length of binary string add leading zeros to make octet
|
||||
$OctetInBinary = ("0" * (8 - ($OctetInBinary).Length) + $OctetInBinary)
|
||||
|
||||
$IPInBinary = $IPInBinary + $OctetInBinary
|
||||
}
|
||||
$IPInBinary = $IPInBinary -join ""
|
||||
|
||||
#Get network ID by subtracting subnet mask
|
||||
$HostBits = 32 - $SubnetBits
|
||||
$NetworkIDInBinary = $IPInBinary.Substring(0, $SubnetBits)
|
||||
|
||||
#Get host ID and get the first host ID by converting all 1s into 0s
|
||||
$HostIDInBinary = $IPInBinary.Substring($SubnetBits, $HostBits)
|
||||
$HostIDInBinary = $HostIDInBinary -replace "1", "0"
|
||||
|
||||
#Work out all the host IDs in that subnet by cycling through $i from 1 up to max $HostIDInBinary (i.e. 1s stringed up to $HostBits)
|
||||
#Work out max $HostIDInBinary
|
||||
$imax = [convert]::ToInt32(("1" * $HostBits), 2) - 1
|
||||
|
||||
$IPs = @()
|
||||
|
||||
#Next ID is first network ID converted to decimal plus $i then converted to binary
|
||||
For ($i = 1 ; $i -le $imax ; $i++) {
|
||||
#Convert to decimal and add $i
|
||||
$NextHostIDInDecimal = ([convert]::ToInt32($HostIDInBinary, 2) + $i)
|
||||
#Convert back to binary
|
||||
$NextHostIDInBinary = [convert]::ToString($NextHostIDInDecimal, 2)
|
||||
#Add leading zeros
|
||||
#Number of zeros to add
|
||||
$NoOfZerosToAdd = $HostIDInBinary.Length - $NextHostIDInBinary.Length
|
||||
$NextHostIDInBinary = ("0" * $NoOfZerosToAdd) + $NextHostIDInBinary
|
||||
|
||||
#Work out next IP
|
||||
#Add networkID to hostID
|
||||
$NextIPInBinary = $NetworkIDInBinary + $NextHostIDInBinary
|
||||
#Split into octets and separate by . then join
|
||||
$IP = @()
|
||||
For ($x = 1 ; $x -le 4 ; $x++) {
|
||||
#Work out start character position
|
||||
$StartCharNumber = ($x - 1) * 8
|
||||
#Get octet in binary
|
||||
$IPOctetInBinary = $NextIPInBinary.Substring($StartCharNumber, 8)
|
||||
#Convert octet into decimal
|
||||
$IPOctetInDecimal = [convert]::ToInt32($IPOctetInBinary, 2)
|
||||
#Add octet to IP
|
||||
$IP += $IPOctetInDecimal
|
||||
}
|
||||
|
||||
#Separate by .
|
||||
$IP = $IP -join "."
|
||||
$IPs += $IP
|
||||
|
||||
|
||||
}
|
||||
$IPs
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Dynamically creates DNS A records
|
||||
.DESCRIPTION
|
||||
Dynamically creates DNS A records based on CIDR input
|
||||
.EXAMPLE
|
||||
New-ITDIbDNSRecordNextAvailableIP -Hostname itdserver1.nd.gov -CIDR 10.11.12.0/23 -Credential $Credential
|
||||
.EXAMPLE
|
||||
New-ITDIbDNSRecordNextAvailableIP -Hostname itdserver2.nd.gov,itdserver3.nd.gov,itdserver4.nd.gov -CIDR 10.11.12.0/23 -Credential $Credential
|
||||
.INPUTS
|
||||
Inputs to this cmdlet (if any)
|
||||
.OUTPUTS
|
||||
Output from this cmdlet (if any)
|
||||
.NOTES
|
||||
General notes
|
||||
.COMPONENT
|
||||
The component this cmdlet belongs to
|
||||
.ROLE
|
||||
The role this cmdlet belongs to
|
||||
.FUNCTIONALITY
|
||||
The functionality that best describes this cmdlet
|
||||
#>
|
||||
function New-ITDIbDNSRecordNextAvailableIP {
|
||||
[CmdletBinding()]
|
||||
Param
|
||||
(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[string[]]
|
||||
$Hostname,
|
||||
|
||||
[Parameter(Mandatory = $true)]
|
||||
[ValidateNotNull()]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[ValidatePattern("^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(3[0-2]|[1-2][0-9]|[0-9]))$")]
|
||||
[string]
|
||||
$CIDR,
|
||||
|
||||
[PSCredential]
|
||||
$Credential
|
||||
)
|
||||
|
||||
begin {
|
||||
$NetworkAddress = $CIDR.split('/')[0]
|
||||
$IPs = Get-IPs -Subnets $CIDR
|
||||
$ExcludeIPs = $IPs | select -First 1
|
||||
}
|
||||
|
||||
process {
|
||||
#$ curl -k -u admin:infoblox -X GET https://10.64.41.6/wapi/v1.1/network?ipv4addr=10.144.2.0
|
||||
try {
|
||||
$networkobj = Invoke-RestMethod -Method Get -Uri "https://infoblox-gmv.ns.nd.gov/wapi/v2.7/network?ipv4addr=$NetworkAddress" -Credential $Credential -ContentType "application/json" -ErrorAction Stop
|
||||
$networkobjref = $networkobj._ref
|
||||
|
||||
#curl -k -u admin:infoblox -X POST https://10.64.41.6/wapi/v1.1/network/ZG5zLm5ldHdvcmskMTAuMTQ0LjIuMC8yNC8w:10.144.2.0/24/default?_function=next_available_ip -H "Content-Type: application/json" -d '{"exclude": ["10.144.2.8", "10.144.2.10"], "num": 6}'
|
||||
$bodyjson = @{num = @($Hostname).count; exclude = @($ExcludeIPs) } | ConvertTo-Json
|
||||
#Invoke-RestMethod -Method Post -Uri ("https://infoblox-gmv.ns.nd.gov/wapi/v2.7/" + $networkobjref + "?_function=next_available_ip") -ContentType "application/json" -Credential $Credential -Body '{"exclude": ["10.11.12.1", "10.11.12.2"], "num": 6}' #WORKS
|
||||
$IPsAvailable = (Invoke-RestMethod -Method Post -Uri ("https://infoblox-gmv.ns.nd.gov/wapi/v2.7/" + $networkobjref + "?_function=next_available_ip") -ContentType "application/json" -Credential $Credential -Body $bodyjson -ErrorAction Stop).Ips
|
||||
|
||||
$IPCount = 0
|
||||
|
||||
ForEach ($hn in $hostname) {
|
||||
if (Get-ITDIbDNSRecord -Hostname $hn -Credential $Credential) {
|
||||
Write-Warning "DNS record already exists"
|
||||
}
|
||||
else {
|
||||
New-ITDIbDNSRecord -IPv4Address $IPsAvailable[$IPCount] -Hostname $hn -Credential $Credential -ErrorAction Stop
|
||||
$IPcount++
|
||||
}
|
||||
}
|
||||
}
|
||||
catch [System.Net.WebException] {
|
||||
Write-Error "webexception error"
|
||||
}
|
||||
}
|
||||
|
||||
end {
|
||||
}
|
||||
}
|
||||
|
||||
function Get-ITDIbVlan {
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(
|
||||
ParameterSetName = 'VlanLookup')]
|
||||
[ValidateRange(0, 4096)]
|
||||
[int[]]
|
||||
$Vlan,
|
||||
|
||||
[Parameter(
|
||||
ParameterSetName = 'CIDRLookup')]
|
||||
[string[]]
|
||||
$CIDR,
|
||||
|
||||
[PSCredential]
|
||||
$Credential
|
||||
)
|
||||
begin {
|
||||
|
||||
}
|
||||
process {
|
||||
$Output = @()
|
||||
|
||||
switch ($PsCmdlet.ParameterSetName) {
|
||||
"VlanLookup" {
|
||||
ForEach ($v in $Vlan) {
|
||||
$InvokeResult = Invoke-RestMethod -Method Get -Uri "https://infoblox-gmv.ns.nd.gov/wapi/v2.11.3/vlan?id=$v&_return_as_object=1&_return_fields=assigned_to,id,name,parent,comment,description" -ContentType "application/json" -Credential $Credential
|
||||
$InvokePSObject = $InvokeResult.result | Select-Object id, Name, Comment, @{n = "AssignedTo"; e = { $_.Assigned_to.split(':')[1] -replace '/default' } }
|
||||
$Output += $InvokePSObject
|
||||
}
|
||||
}
|
||||
"CIDRLookup" {
|
||||
ForEach ($c in $CIDR) {
|
||||
$InvokeResult = Invoke-RestMethod -Method Get -Uri "https://infoblox-gmv.ns.nd.gov/wapi/v2.11.3/vlan?_return_as_object=1&_max_results=-50000&_return_fields=assigned_to,id,name,parent,comment,description" -ContentType "application/json" -Credential $Credential
|
||||
$InvokePSObject = $InvokeResult.result | Select-Object id, Name, Comment, @{n = "AssignedTo"; e = { $_.Assigned_to.split(':')[1] -replace '/default' } }
|
||||
$Output += $InvokePSObject | Where-Object AssignedTo -EQ $c
|
||||
}
|
||||
}
|
||||
"default" {
|
||||
$InvokeResult = Invoke-RestMethod -Method Get -Uri "https://infoblox-gmv.ns.nd.gov/wapi/v2.11.3/vlan?_return_as_object=1&_max_results=-50000&_return_fields=assigned_to,id,name,parent,comment,description" -ContentType "application/json" -Credential $Credential
|
||||
$InvokePSObject = $InvokeResult.result | Select-Object id, Name, Comment, @{n = "AssignedTo"; e = { $_.Assigned_to.split(':')[1] -replace '/default' } }
|
||||
$Output = $InvokePSObject
|
||||
}
|
||||
}
|
||||
}
|
||||
end {
|
||||
Write-Output $Output
|
||||
}
|
||||
}
|
||||
|
||||
function Remove-ITDIbDnsRecord {
|
||||
[CmdletBinding()]
|
||||
param (
|
||||
[string]
|
||||
$ComputerName,
|
||||
|
||||
[PSCredential]
|
||||
$Credential
|
||||
)
|
||||
|
||||
Begin {
|
||||
If (!($Credential)) {
|
||||
$Credential = Get-Credential
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Process {
|
||||
$DNSRecord = Invoke-RestMethod -Method Get -Uri "https://infoblox-gmv.ns.nd.gov/wapi/v2.7/record:host?name=$ComputerName" -ContentType "application/json" -Credential $Credential
|
||||
$UriToDelete = ( "https://infoblox-gmv.ns.nd.gov/wapi/v2.7/" + $DNSRecord._ref )
|
||||
Invoke-RestMethod -Method Delete -Uri $UriToDelete -ContentType "application/json" -Credential $Credential
|
||||
}
|
||||
|
||||
end {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# Introduction
|
||||
TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.
|
||||
|
||||
# Getting Started
|
||||
TODO: Guide users through getting your code up and running on their own system. In this section you can talk about:
|
||||
1. Installation process
|
||||
2. Software dependencies
|
||||
3. Latest releases
|
||||
4. API references
|
||||
|
||||
# Build and Test
|
||||
TODO: Describe and show how to build your code and run the tests.
|
||||
|
||||
# Contribute
|
||||
TODO: Explain how other users and developers can contribute to make your code better.
|
||||
|
||||
If you want to learn more about creating good readme files then refer the following [guidelines](https://docs.microsoft.com/en-us/azure/devops/repos/git/create-a-readme?view=azure-devops). You can also seek inspiration from the below readme files:
|
||||
- [ASP.NET Core](https://github.com/aspnet/Home)
|
||||
- [Visual Studio Code](https://github.com/Microsoft/vscode)
|
||||
- [Chakra Core](https://github.com/Microsoft/ChakraCore)
|
||||
Reference in New Issue
Block a user