Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

Trying to add persistence profile in existing virtual server

I am trying to add persistence profile in an existing Virtual server but not able to do so. It is showing some errors.

Add-PSSnapIn iControlSnapIn
Initialize-F5.iControl -Hostname "hostname" -Username "username" -Password "password"

$virtual_name = New-Object iControl.CommonVirtualServerDefinition
$virtual_name.name="app035"
$virtual_name.address="0.0.0.0"
$virtual_name.port=80
$vir_server = New-Object iControl.LocalLBVirtualServerVirtualServerPersistence
$vir_server.default_profile = $false
$vir_server.profile_name="cookie"

(Get-F5.iControl).LocalLBVirtualServer.add_persistence_profile($virtual_name,$vir_server)

Error this time is -

Exception calling "add_persistence_profile" with "2" argument(s): "Exception caught in 
LocalLB::urn:iControl:LocalLB/VirtualServer::add_persistence_profile()
Exception: Common::OperationFailed
    primary_error_code   : 16908342 (0x01020036)
    secondary_error_code : 0
    error_string         : 01020036:3: The requested virtual server 
(/Common/iControl.CommonVirtualServerDefinition) was not found."
At line:12 char:1
+ (Get-F5.iControl).LocalLBVirtualServer.add_persistence_profile($virtu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : SoapHeaderException

I am making some mistake not sure what exactly is that. Could someone please help me out with this ?

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

I do not know PowerShell, but from the error message, The requested virtual server (/Common/iControl.CommonVirtualServerDefinition) was not found, I would say that the virtual does not exist. Check if exists.

If that's not the case, I suspect the data format of the persistence profile(s). It must be given in array ([]). For example, to perform the task equivalent to the following tmsh command (adding cookie persistence profile to the virtual vs):

tmsh modify ltm virtual vs persist replace-all-with { cookie }

You need to PATCH the /mgmt/tm/ltm/virtual/vs endpoint with the data {"persist":[ {"name":"cookie"} ]}.

A curl call looks like this:

curl -sku <admin>:<adminPass> https://<host>/mgmt/tm/ltm/virtual/vs \
  -X PATCH -H "Content-type: application/json" \
  -d '{"persist":[ {"name":"cookie"} ]}'
0
Comments on this Answer
Comment made 2 days ago by Ansh Jain 56

Thanks Satoshi for your response over this issue. You are right. The persistent profile needs to be passed as an array in powershell. I did the same and issue has been resolved, I forgot to mark it. This is working piece.

$Persistence = New-Object -TypeName iControl.LocalLBVirtualServerVirtualServerPersistence; 
$Persistence.profile_name = 'source_addr' 
$Persistence.default_profile = $true 
$Pers_ProfileA = (, $Persistence); 
$Pers_ProfileAofA = (, $Pers_ProfileA); 

Write-Host "Enabling Source Address Affinity on Virtual Server `"$name`"..."; 

(Get-F5.iControl).LocalLBVirtualServer.add_persistence_profile($name, $Pers_ProfileAofA) 

Reference: https://devcentral.f5.com/questions/looking-for-help-with-add_persistence_profile

0