Forum Discussion
hassar10_35518
Nimbostratus
Feb 27, 2008console app
Sorry to bother you again, BUT I was wondering if one could guide on how to do
A console application (.NET), which will take two parameters, pool name and array of node list and then add those nodes to the given pool
Is this do able using F5 SDK
2 Replies
- To build a console app, do the following:
1. Start Visual Studio
2. Hit the New.Project menu and select a C Console Application. Name it and save.
3. Add the iControl Assembly (iControl.dll) as a resource to the project (along with System.Web and System.Web.Services).
I typically can't commit to writing custom code but since this took all of 3 minutes to do, I'll pass along the entire program code.
Replace your Project.cs with this code:using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace cstest { class Program { public iControl.Interfaces m_interfaces = new iControl.Interfaces(); public string m_bigip = null; public long m_port = 443; public string m_user = null; public string m_pass = null; public bool Run(string[] args) { bool bSuccess = false; if (args.Length > 3) { m_bigip = args[0]; m_user = args[1]; m_pass = args[2]; bSuccess = m_interfaces.initialize(m_bigip, m_user, m_pass); } if (bSuccess) { if (args.Length > 5) { String pool = args[3]; String[] members = new string[args.Length - 4]; for (int i = 4; i < args.Length; i++) { members[i - 4] = args[ i ]; } bSuccess = addMembersToPool(pool, members); } } return bSuccess; } public bool addMembersToPool(string pool, string[] members) { bool bSuccess = false; iControl.CommonIPPortDefinition[] member_defs = new iControl.CommonIPPortDefinition[members.Length]; for(int i=0; i { String [] seps = members[ i ].Split(new char [] {':'}); member_defs[ i ] = new iControl.CommonIPPortDefinition(); member_defs[ i ].address = seps[ 0 ]; member_defs[ i ].port = Convert.ToInt32(seps[ 1 ]); } iControl.CommonIPPortDefinition [][] member_def_lists = new iControl.CommonIPPortDefinition[ 1 ][]; member_def_lists[ 0 ] = member_defs; try { m_interfaces.LocalLBPool.add_member( new string [] {pool}, member_def_lists); bSuccess = true; } catch(Exception ex) { Console.WriteLine(ex.Message.ToString()); } return bSuccess; } static void Main(string[] args) { Program p = new Program(); p.Run(args); } } }
If you want to make a method to remove members from a pool, just copy the function addMembersToPool and replace the LocallBPool.add_member with LocalLBPool.remove_member and you should be set.
Hope this helps...
-Joe - JRahm
Admin
BTW, the args.Length should be greater than 4 not 5. Otherwise you'd need at least two pool members for the update.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects