joel74 / POSH-LTM-Rest

PowerShell module and scripts for working with F5's LTM REST API
MIT License
78 stars 49 forks source link

Fix error in New-VirtualServer when -PersistenceProfiles is empty and added -SecurityLogProfiles and -PolicyNames #168

Closed lxscaut closed 6 years ago

lxscaut commented 6 years ago

Currently New-VirtualServer crashes with the following error message, when no or an empty -PersistenceProfiles is given:

Invoke-F5RestMethod : "400 Bad Request: one or more configuration identifiers must be provided
At C:\Program Files\WindowsPowerShell\Modules\f5-ltm\1.4.239\Public\New-VirtualServer.ps1:160 char:7
+       Invoke-F5RestMethod -Method POST -Uri "$URI" `
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-F5RestMethod

I've fixed that, by only adding it to the JSONBody if defined.

Background: We have a special case where we really do not want any persistence profiles set on a bunch of our virtual servers for a specific WebApp.

lxscaut commented 6 years ago

Also added two new parameters to New-VirtualServer: -SecurityLogProfiles and -PolicyNames Both have been successfully tested in our environment.

joel74 commented 6 years ago

Thanks, sammyxx. I'll review this in the next day or two. I appreciate the contribution.

lxscaut commented 6 years ago

Here is another commit that fixes a few things:

lxscaut commented 6 years ago

@joel74: My changes did not break the build. It seems that there is a problem with the build script or the AppVeyor container. Please have a look.

joel74 commented 6 years ago

Hi. Something was up with appveyor. The ScriptAnalyzer PS module is a standard one, so I don't know why it failed to import on that run. It worked when I reran it.

joel74 commented 6 years ago

I wasn't able to test the security log profiles portion, as I don't have that set up. I believe that depends on the AFM module. If you can include some output from your tests with that, that would be helpful.

I think at some point we'll need to clean up which properties are set by adding to a local virtual server object and then passed to the Set-VirtualServer function, and which are passed in as named params. It's a bit confusing having a mix of both, but we can leave that for a later date. Thanks for the contribution!

mcurole commented 6 years ago

Joel, you should contact your sales rep about getting some VE Lab Edition licenses. They are throttled heavily but are licensed for all modules. List price is $100 each

lxscaut commented 6 years ago

@joel74 : Sure! I've built a module around your module where I create hundrets of virtual servers, where I can't show you the output as it contains sensible information, but I've setup a small test-case for you and made a screenshot: f5_securitylogprofiles

Is this suitable for you, or do you need anything else?

Kind regards, Sammy

joel74 commented 6 years ago

Thanks, sammyxx. That works for me. mcurole, I appreciate the suggestion. I do already have a couple lab licenses that I'm using to test various LTM versions. My issue with testing something that uses the AFM module is more about the fact that I have no experience working with that module. Cheers, Joel