Forum Discussion

M_125189's avatar
M_125189
Icon for Nimbostratus rankNimbostratus
Feb 28, 2013

ps Get-f5.LTMvirtualserverrule

Hi,

 

I am trying to see what are my irules attache to my Virtual server. When I run get-f5.LTMRule It returns all my iRules in my LTM.But when I'm trying to run get-f5.LTMvirtualserverrule -virtualserver myserver It just do nothing! I have 2 rules attached to my server but why it doesn't return anything? :(

 

7 Replies

  • What version are you running? This behavior occurs in 11.x when the partition is not included in the virtual server name value..i.e...

     

     

    Get-F5.LTMVirtualServerRule -virtualserver /Common/your_virtual_server_name
  • Thank you Tim You saved my day.

     

    But now I have another problem. I add first rule, It works fine but when I try to add the second irule it wont add it and give me the erorr that says the priority must be uniq. The thing is when I add and delete rules from LTM GUI I can add them fine, no error but PS gives me this message ???!!!! Tim ?Steve? anyone?
  • Can you post the code you are using to add the iRule to the virtual? You should specify a priority in the VirtualServerRule parameter.

     

    I've got a CodeShare item I posted a while ago that uses the add_rule() method. I'm defaulting to a 500 priority in the rule addition so you'll have to change that depending on which iRule you want to have priority.

     

    https://devcentral.f5.com/wiki/iControl.PsProvisionVEForLocalDev.ashx

     

    -Joe

     

  • Im using command ADD-F5.LTMvirtualserverRule -virtualserver myserver -rule myrule

     

    The thing is we already have bunch of iRules in our LTM with no priority number! we used to go to the LTM GUI and change the priority using up and down buttons. Now i have to automate this process!!!! they want me to do it with PS commands.As soon as I add the first one The second one cant be added! but LTM doesnt have anyproblem with this!

     

    Thank you Joe
  • Ok, that cmdlet wasn't built with support for the priorites. Just in case you didn't know, there's a cmdlet named Get-F5.iControl that returns you a list of all the native interfaces and their methods. Look at the Create-iRule() function in the above sample. Here's a stripped down version of that function without any error checking.

     

    function Create-iRule()

     

    {

     

    param([string]$virtual, [string]$rule_name, [int]$priority);

     

     

    Create Parameters

     

    $virtual_servers = @($virtual);

     

    $rule = New-Object -TypeName iControl.LocalLBVirtualServerVirtualServerRule;

     

    $rule.rule_name = $rule_name;

     

    $rule.priority = $priority;

     

    $rules = @($rule);

     

     

    (Get-F5.iControl).LocalLBVirtualServer.add_rule(

     

    $virtual_servers,

     

    $rules

     

    );

     

    }

     

    Not sure how you initialized the CmdLet you were using but you may have to make a call to Initialize-F5.iControl before doing this.

     

    Hope this helps...

     

    -Joe

     

     

  • Hi Joe,

     

    Sorry fot asking all these stupid questions, But I am so new to this and I need help cuz I have to get this done asap.

     

    Is there any way to add and remove iRules from a virtual server from cmdlet? considering that the iRules I have don't have priority numbers. I have to be able to add remove and priortize my iRules attached to my virtual server via Powershell commnads or scripts.
  • From PowerShell, you can use the Get-F5.iControl cmdlet to get access to all of the iControl API defined in the API Reference at: https://devcentral.f5.com/wiki/iControl.APIReference.ashx

     

    Here's a function that you can use to remove an iRule

     

     

    function Remove-iRule()

     

    {

     

    param([string]$virtual, [string]$rule_name);

     

     

    Create Parameters

     

    $virtual_servers = @($virtual);

     

    $rule = New-Object -TypeName iControl.LocalLBVirtualServerVirtualServerRule;

     

    $rule.rule_name = $rule_name;

     

    $rule.priority = 0;

     

    $rules = @($rule);

     

     

    (Get-F5.iControl).LocalLBVirtualServer.remove_rule(

     

    $virtual_servers,

     

    $rules

     

    );

     

    }

     

    It's basically the same function as the one above, but using the remove_rule method.

     

     

    For the remove_rule function, the priority parameter int eh VirtualServerRule parameter is ignored.

     

     

    The other Cmdlet's in the PowerShell library were included for some sample use cases but they don't cover everything. For use cases outside of those included, we recommend using the Get-F5.iControl cmdlet to return the core API interfaces object and acting on that. You can build local script functions that mimic your use cases and use them according.

     

     

    In looking for feature ability, I'd get familiar with the iControl API from the above APIReference link first. You can then get to all those methods from the Get-F5.iControl cmdlet.

     

     

    Hope this helps...

     

     

    -Joe