From 613c8550fe275f506ae7ff7e7c206c9255d4c5df Mon Sep 17 00:00:00 2001 From: Wes Carroll Date: Sun, 24 Feb 2019 21:26:40 -0500 Subject: [PATCH] Create Add-ZertoPeerSite and tests --- Tests/Public/Add-ZertoPeerSite.Tests.ps1 | 22 +++++++++++++++ ZertoApiWrapper/Public/Add-ZertoPeerSite.ps1 | 29 ++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 Tests/Public/Add-ZertoPeerSite.Tests.ps1 create mode 100644 ZertoApiWrapper/Public/Add-ZertoPeerSite.ps1 diff --git a/Tests/Public/Add-ZertoPeerSite.Tests.ps1 b/Tests/Public/Add-ZertoPeerSite.Tests.ps1 new file mode 100644 index 0000000..06aa6f8 --- /dev/null +++ b/Tests/Public/Add-ZertoPeerSite.Tests.ps1 @@ -0,0 +1,22 @@ +$moduleFileName = "ZertoApiWrapper.psm1" +$filePath = (Split-Path -Parent $MyInvocation.MyCommand.Path) -replace 'Tests', 'ZertoApiWrapper' +$fileName = (Split-Path -Leaf $MyInvocation.MyCommand.Path ) -replace '.Tests.', '.' +$modulePath = $filePath -replace "Public", "" +Import-Module $modulePath\$moduleFileName -Force + +$userName = "zerto\build" +$password = ConvertTo-SecureString -String "ZertoBuild" -AsPlainText -Force +$credential = New-Object -TypeName System.Management.Automation.PSCredential($userName, $password) + +# $credential = Import-Clixml -Path C:\ZertoScripts\Creds.xml +$zertoServer = "192.168.1.100" +$zertoPort = "7669" + +Describe "Add-ZertoPeerSite" { + it "file should exist" { + "$filePath\$fileName" | should exist + } + it "module should have a function called Add-ZertoPeerSite" { + get-command Add-ZertoPeerSite | should be $true + } +} \ No newline at end of file diff --git a/ZertoApiWrapper/Public/Add-ZertoPeerSite.ps1 b/ZertoApiWrapper/Public/Add-ZertoPeerSite.ps1 new file mode 100644 index 0000000..9413f88 --- /dev/null +++ b/ZertoApiWrapper/Public/Add-ZertoPeerSite.ps1 @@ -0,0 +1,29 @@ +function Add-ZertoPeerSite { + [cmdletbinding( SupportsShouldProcess = $true )] + param( + [parameter( + Mandatory = $true, + HelpMessage = "Target Hostname or IP address to pair the localsite to." + )] + [string]$targetHost, + [Parameter( + HelpMessage = "Target communication port. Default is 9081" + )] + [int]$targetPort = 9081 + ) + + begin { + $baseUri = "peersites" + $body = @{"HostName" = $targetHost; "Port" = $targetPort} + } + + process { + if ($PSCmdlet.ShouldProcess("Pairing with Site $targetHost")) { + Invoke-ZertoRestRequest -uri $baseUri -body $($body | ConvertTo-Json) -method "POST" + } + } + + end { + # Nothing to do + } +} \ No newline at end of file