internal F5PoolMemberState(string PoolName, CommonIPPortDefinition Member) { this.pool = PoolName; this.address = Member.address; this.port = Member.port; this.state = string.Empty; }
internal F5LTMVirtualServerMembers(string VirtualServerName, string DefaultPool, CommonIPPortDefinition VirtualServerMember, LocalLBObjectStatus VirtualServerInfo) { this.virtualServer = VirtualServerName; this.virtualServerDefaultPool = DefaultPool; this.virtualServerMember = VirtualServerMember; this.objectStatus = VirtualServerInfo; }
/// <summary> /// This Method communicates with the F5, and adds a new Pool, along with its member list and TCP Port address /// </summary> /// <param name="poolName">The name of the Pool we are verifying to exist</param> /// <param name="memberList">The computer name which we would like to add to the pool, this can be a ";" delimited list of members</param> /// <param name="memberPort">The TCP port which this pool will be working on.</param> private void AddLBPool(string poolName, string memberList, long memberPort) { if (isF5Connected && isAdminUser) { if (!CheckLBPoolExists(poolName)) { String[] memberArray = memberList.Split(new char[] { ';' }); CommonIPPortDefinition[][] poolMembers = new CommonIPPortDefinition[memberArray.Length][]; for (int i = 0; i < memberArray.Length; i++) { // Create an object for each member and port CommonIPPortDefinition newMember = new CommonIPPortDefinition(); newMember.address = memberArray[i]; newMember.port = memberPort; // Now update the array of poolMembers with the new member information for pool creation poolMembers[i] = new CommonIPPortDefinition[1]; poolMembers[i][0] = new CommonIPPortDefinition(); poolMembers[i][0] = newMember; } Connection.LocalLBPool.create(new string[] { poolName }, new LocalLBLBMethod[] { LocalLBLBMethod.LB_METHOD_ROUND_ROBIN }, poolMembers); } } else { throw new Exception("We do not have privilages to add a pool"); } }
/// <summary> /// The number of current connections on a pool member /// </summary> /// <param name="poolName">The name of the pool</param> /// <param name="member">The name of the member we are going to Query for current connections</param> /// <returns>Long, the current number of connections on a member</returns> private long GetLBPoolMemberActiveConnections(string poolName, string member) { long activeConnections = 0; CommonIPPortDefinition[][] searchMember = new CommonIPPortDefinition[1][]; searchMember[0] = new CommonIPPortDefinition[1]; searchMember[0][0] = new CommonIPPortDefinition(); searchMember[0][0] = parseMember(member); if (isF5Connected) { LocalLBPoolMemberMemberStatistics[] memberStatistics = Connection.LocalLBPoolMember.get_statistics(new string[] { poolName }, searchMember); foreach (CommonStatistic memberStat in memberStatistics[0].statistics[0].statistics) { if (memberStat.type == CommonStatisticType.STATISTIC_SERVER_SIDE_CURRENT_CONNECTIONS) { activeConnections = memberStat.value.low; } } } else { throw new Exception("We are not connected to the F5!"); } return(activeConnections); }
internal F5LTMPoolMembers(string PoolName, CommonIPPortDefinition Member) { this.nodePool = PoolName; this.nodeMember.address = Member.address; this.nodeMember.port = Member.port; this.nodeState = string.Empty; this.nodeActiveConnections = 0; }
internal F5LBPoolMember(string PoolName, CommonIPPortDefinition Member, string MemberState) { this.nodePool = PoolName; this.nodeMember.address = Member.address; this.nodeMember.port = Member.port; this.nodeState = MemberState; this.nodeActiveConnections = 0; }
// Function to query the Pool and its member of the status of the object and return this back to the user. public LocalLBObjectStatus GetPoolMemberStatus(string poolName, CommonIPPortDefinition memberName) { foreach (LocalLBPoolMemberMemberObjectStatus[] F5Member in Connection.LocalLBPoolMember.get_object_status(new string[] { poolName })) { if (F5Member[0].member.address.Equals(memberName.address) && F5Member[0].member.port == memberName.port) { return(F5Member[0].object_status); } } return(new LocalLBObjectStatus()); }
public CommonIPPortDefinition parseMember(String member) { CommonIPPortDefinition ipPort = null; String[] sSplit = member.Split(new char[] { ':' }); if (2 == sSplit.Length) { ipPort = new CommonIPPortDefinition(); ipPort.address = sSplit[0]; ipPort.port = Convert.ToInt32(sSplit[1]); } return(ipPort); }
/// <summary> /// Set a member of a pool to specified state /// </summary> /// <param name="poolName">The name of the pool</param> /// <param name="poolMember">The name of the member we are looking to change state of for a pool</param> /// <param name="poolMemberState">The state we would like to set the member to be Enabled|Disabled|Forced Offline</param> public void SetLBPoolMember(string poolName, string poolMember, string poolMemberState) { // Convert the Pool Member into a format we can work with CommonIPPortDefinition memberNode = parseMember(poolMember); if (isF5Connected) { LocalLBPoolMemberMemberMonitorState[][] monitor_states = new LocalLBPoolMemberMemberMonitorState[1][]; monitor_states[0] = new LocalLBPoolMemberMemberMonitorState[1]; monitor_states[0][0] = new LocalLBPoolMemberMemberMonitorState(); monitor_states[0][0].member = new CommonIPPortDefinition(); monitor_states[0][0].member = memberNode; LocalLBPoolMemberMemberSessionState[][] session_states = new LocalLBPoolMemberMemberSessionState[1][]; session_states[0] = new LocalLBPoolMemberMemberSessionState[1]; session_states[0][0] = new LocalLBPoolMemberMemberSessionState(); session_states[0][0].member = new CommonIPPortDefinition(); session_states[0][0].member = memberNode; switch (poolMemberState) { case "Enabled": monitor_states[0][0].monitor_state = CommonEnabledState.STATE_ENABLED; session_states[0][0].session_state = CommonEnabledState.STATE_ENABLED; break; case "Disabled": monitor_states[0][0].monitor_state = CommonEnabledState.STATE_ENABLED; session_states[0][0].session_state = CommonEnabledState.STATE_DISABLED; break; case "Forced Offline": monitor_states[0][0].monitor_state = CommonEnabledState.STATE_DISABLED; session_states[0][0].session_state = CommonEnabledState.STATE_DISABLED; break; default: break; } Connection.LocalLBPoolMember.set_monitor_state(new string[] { poolName }, monitor_states); Connection.LocalLBPoolMember.set_session_enabled_state(new string[] { poolName }, session_states); } else { throw new Exception("We are not connected to the F5!"); } }
public void showPoolMemberState(String pool_name, String member) { CommonIPPortDefinition ipPort = parseMember(member); LocalLBPoolMemberMemberSessionState [][] session_states = m_interfaces.LocalLBPoolMember.get_session_enabled_state(new string[] { pool_name }); Console.WriteLine("POOL '" + pool_name + "' MEMBER STATUS"); for (int i = 0; i < session_states[0].Length; i++) { if (session_states[0][i].member.address.Equals(ipPort.address) && session_states[0][i].member.port == ipPort.port) { Console.WriteLine(" " + member + " : " + session_states[0][i].session_state); } } }
public void setPoolMemberState(String pool_name, String member, String state) { CommonIPPortDefinition ipPort = parseMember(member); if (null != ipPort) { LocalLBPoolMemberMemberSessionState [][] session_states = new LocalLBPoolMemberMemberSessionState[1][]; session_states[0] = new LocalLBPoolMemberMemberSessionState[1]; session_states[0][0] = new LocalLBPoolMemberMemberSessionState(); session_states[0][0].member = new CommonIPPortDefinition(); session_states[0][0].member = ipPort; session_states[0][0].session_state = parseState(state); m_interfaces.LocalLBPoolMember.set_session_enabled_state(new string[] { pool_name }, session_states); Console.WriteLine("Setting state to " + session_states[0][0].session_state); } }
/// <summary> /// Remove a member for a Load Balancer Pool /// </summary> /// <param name="poolName">The name of the pool</param> /// <param name="member">The name of the member we are going to remove from the pool</param> public void RemoveLBPoolMember(string poolName, string poolMember) { CommonIPPortDefinition[][] newMember = new CommonIPPortDefinition[1][]; newMember[0] = new CommonIPPortDefinition[1]; newMember[0][0] = new CommonIPPortDefinition(); newMember[0][0] = parseMember(poolMember); if (isF5Connected && isAdminUser) { Connection.LocalLBPool.remove_member(new string[] { poolName }, newMember); } else { throw new Exception("We do not have privilages to remove a member to a pool"); } }
public List <F5PoolMemberState> GetPoolMemberState(string poolName, CommonIPPortDefinition nodeName) { // Now - Sanity Check time; lets go back and ask the F5 what is the current status of this member and its pool // So we can report back to real staus to the pipeline List <F5PoolMemberState> poolMemberState = new List <F5PoolMemberState>(); //string memberState = string.Empty; LocalLBPoolMemberMemberSessionState[][] bigIPPoolMemberState = F5Connection.LocalLBPoolMember.get_session_enabled_state(new string[] { poolName }); LocalLBPoolMemberMemberMonitorStatus[][] bigIPPoolMemberMonitor = F5Connection.LocalLBPoolMember.get_monitor_status(new string[] { poolName }); for (int i = 0; i < bigIPPoolMemberState[0].Length; i++) { if (bigIPPoolMemberState[0][i].member.address.Equals(nodeName.address) && bigIPPoolMemberState[0][i].member.port == nodeName.port) { F5PoolMemberState memberState = new F5PoolMemberState(poolName, bigIPPoolMemberState[0][i].member, ""); string state = string.Empty; if (bigIPPoolMemberMonitor[0][i].monitor_status == LocalLBMonitorStatus.MONITOR_STATUS_FORCED_DOWN) { // Monitor State = Disabled memberState.State = "Offline Forced"; } else if (bigIPPoolMemberState[0][i].session_state == CommonEnabledState.STATE_ENABLED) { // Session State = Enabled // Monitor State = Enabled memberState.State = "Enabled"; } else { // Session State = Disabled // Monitor State = Enabled memberState.State = "Disabled"; } poolMemberState.Add(memberState); } } return(poolMemberState); }
/// <summary> /// Add a member to a Load Balancer Pool /// </summary> /// <param name="poolName">The name of the pool</param> /// <param name="member">The name of the member we are going to add to the pool</param> public void AddLBPoolMember(string poolName, string poolMember) { // Before we add the poolMember to the pool, we need to check first if there is a node already inplace for the this member // Now we can proceed and add the new poolMember CommonIPPortDefinition[][] newMember = new CommonIPPortDefinition[1][]; newMember[0] = new CommonIPPortDefinition[1]; newMember[0][0] = new CommonIPPortDefinition(); newMember[0][0] = parseMember(poolMember); if (isF5Connected && isAdminUser) { Connection.LocalLBPool.add_member(new string[] { poolName }, newMember); } else { throw new Exception("We do not have privilages to add a members to a pool"); } }
public long GetCurrentMemberConnections(string poolName, string memberName) { CommonIPPortDefinition[][] activeMember = new CommonIPPortDefinition[1][]; activeMember[0][0] = parseMember(memberName); long activeConnections = 1; while (activeConnections > 0) { LocalLBPoolMemberMemberStatistics[] memberStatistics = Connection.LocalLBPoolMember.get_statistics(new string[] { poolName }, activeMember); foreach (CommonStatistic memberStat in memberStatistics[0].statistics[0].statistics) { if (memberStat.type == CommonStatisticType.STATISTIC_SERVER_SIDE_CURRENT_CONNECTIONS) { activeConnections = memberStat.value.low; } } } return(activeConnections); }
public void Execute(IOpalisRequest request, IOpalisResponse response) { // Prepaire the Paramaters provided for use poolName = request.Inputs["Pool Name"].AsString(); memberName = request.Inputs["Member Name"].AsString(); CommonIPPortDefinition nodeName = parseMember(memberName); // Open a connection to the F5 if (F5BigIP.Connect(connection.Host, connection.UserName, connection.Password)) { List <F5PoolMemberState> memberState = F5BigIP.GetPoolMemberState(poolName, nodeName); int count = response.WithFiltering().PublishRange(memberState); //List<string> poolMemberNames = new List<string>(); //IEnumerable bigIPPoolData = GetF5PoolMembers(poolMemberNames); //int numPools = response.WithFiltering().PublishRange(bigIPPoolData); //response.Publish("Pool Members Count", numPools); } }
/* ------------------------------------------------------------------------------------------------------------ * F5 Pool Member Management Methods * * Public - Get the details for a member of a specified Pool * Private - Get the current active connections for a pool member * Public - Set a Member of a Load Balancer Pool * Private - Add a new Member to a Load Balancer Pool * Private - Delete a specified member for a Load Balancer Pool * */ /// <summary> /// Get the details for a member on a specified pool /// </summary> /// <param name="poolName">The name of the pool</param> /// <param name="member">The name of the member we are going to Query for details</param> /// <returns>Pool Member List, deails on the member of a pool</returns> public List <F5LTMPoolMembers> GetLBPoolMember(string poolName, string poolMember) { // Convert the Pool Member into a format we can work with CommonIPPortDefinition member = parseMember(poolMember); // Create a list of F5 Pools Member Objects List <F5LTMPoolMembers> F5PoolMembers = new List <F5LTMPoolMembers>(); if (isF5Connected) { // Query the F5 for the Session State and Monitor State of the Members in this pool LocalLBPoolMemberMemberSessionState[][] bigIPPoolMemberState = Connection.LocalLBPoolMember.get_session_enabled_state(new string[] { poolName }); LocalLBPoolMemberMemberMonitorStatus[][] bigIPPoolMemberMonitor = Connection.LocalLBPoolMember.get_monitor_status(new string[] { poolName }); // Now, loop trough the Elements in the Array, 1 per Pool Member, and update the Pool Member Object each time with the information we have. for (int i = 0; i < bigIPPoolMemberState[0].Length; i++) { if (bigIPPoolMemberState[0][i].member.address.Equals(member.address) && bigIPPoolMemberState[0][i].member.port == member.port) { F5LTMPoolMembers memberState = new F5LTMPoolMembers(poolName, bigIPPoolMemberState[0][i].member, ""); memberState.state = CalculateNodeState(bigIPPoolMemberMonitor[0][i].monitor_status, bigIPPoolMemberState[0][i].session_state); memberState.activeConnections = this.GetLBPoolMemberActiveConnections(poolName, bigIPPoolMemberState[0][i].member.address + ":" + bigIPPoolMemberState[0][i].member.port); // Add the member and its details into the object list. F5PoolMembers.Add(memberState); } } } else { throw new Exception("We are not connected to the F5!"); } return(F5PoolMembers); }
public void Execute(IOpalisRequest request, IOpalisResponse response) { // Open a connection to the F5 bool bInitialized = F5Connection.initialize(connection.Host, connection.UserName, connection.Password); // Parse the Inputs for this Method memberAddress = request.Inputs["Member Name"].AsString(); memberPort = request.Inputs["Member Port"].AsString(); memberState = request.Inputs["Member State"].AsString(); //Define and Set the Correct State flags to represent the requested Member State setting CommonEnabledState monitorState; CommonEnabledState sessionState; switch (memberState) { case "Enabled": monitorState = CommonEnabledState.STATE_ENABLED; sessionState = CommonEnabledState.STATE_ENABLED; break; case "Disabled": monitorState = CommonEnabledState.STATE_DISABLED; sessionState = CommonEnabledState.STATE_ENABLED; break; case "Forced Offline": monitorState = CommonEnabledState.STATE_DISABLED; sessionState = CommonEnabledState.STATE_DISABLED; break; default: // We should never get here, but if we do we will let the node go active monitorState = CommonEnabledState.STATE_ENABLED; sessionState = CommonEnabledState.STATE_ENABLED; break; } // We do not know the name of the pool we are going to modify, so we will instead need to gather a list of all known pools // from this list, we will then request a list of all the know Node/Member names which are asscoiated with the pools String[] bigIPPoolNames = F5Connection.LocalLBPool.get_list(); CommonIPPortDefinition[][] bigIPNodeNames = F5Connection.LocalLBPool.get_member(bigIPPoolNames); // Now, we need to create to instances; one for both the monitor state and the session state. // Each of these will be single member 2 dimensional array. LocalLBPoolMemberMemberMonitorState[][] monitor_states = new LocalLBPoolMemberMemberMonitorState[1][]; monitor_states[0] = new LocalLBPoolMemberMemberMonitorState[1]; monitor_states[0][0] = new LocalLBPoolMemberMemberMonitorState(); monitor_states[0][0].member = new CommonIPPortDefinition(); LocalLBPoolMemberMemberSessionState[][] session_states = new LocalLBPoolMemberMemberSessionState[1][]; session_states[0] = new LocalLBPoolMemberMemberSessionState[1]; session_states[0][0] = new LocalLBPoolMemberMemberSessionState(); session_states[0][0].member = new CommonIPPortDefinition(); // Now, lets create some storage variables to contain the name of the Pool we determine this node is related to // and also the node itself, we will then loop trough all the pools, and its members looking for a match to the node/member // which the user has presented to us to update with the new state setting. string poolName = string.Empty; CommonIPPortDefinition nodeName = new CommonIPPortDefinition(); List <string> poolMemberNames = new List <string>(); for (int i = 0; i < bigIPPoolNames.Length; i++) { for (int j = 0; j < bigIPNodeNames[i].Length; i++) { nodeName = bigIPNodeNames[i][j]; if (nodeName.address.Equals(memberAddress) && nodeName.port == long.Parse(memberPort)) { // Cool - We just located the member/node which were were asked to update monitor_states[0][0].member = nodeName; monitor_states[0][0].monitor_state = monitorState; session_states[0][0].member = nodeName; session_states[0][0].session_state = sessionState; poolName = bigIPPoolNames[i]; F5Connection.LocalLBPoolMember.set_monitor_state(new string[] { poolName }, monitor_states); F5Connection.LocalLBPoolMember.set_session_enabled_state(new string[] { poolName }, session_states); // Now that we have a match, lets take the information we have, and ask the F5 to report the new status // of this member back to us, so that we can update the pipeline, with currentl information poolMemberNames.Add(GetF5PoolMemberState(poolName, nodeName)); } } } // Now - Sanity Check time; lets go back and ask the F5 what is the current status of this member and its pool // So we can report back to real staus to the pipeline //List<string> poolMemberNames = new List<string>(); //LocalLBPoolMemberMemberSessionState[][] bigIPPoolMemberState = F5Connection.LocalLBPoolMember.get_session_enabled_state(new string[] { poolName }); //LocalLBPoolMemberMemberMonitorStatus[][] bigIPPoolMemberMonitor = F5Connection.LocalLBPoolMember.get_monitor_status(new string[] { poolName }); //for (int i = 0; i < bigIPPoolMemberState[0].Length; i++) //{ // if (bigIPPoolMemberState[0][i].member.address.Equals(nodeName.address) && bigIPPoolMemberState[0][i].member.port == nodeName.port) // { // string state = string.Empty; // if (bigIPPoolMemberMonitor[0][i].monitor_status == LocalLBMonitorStatus.MONITOR_STATUS_FORCED_DOWN) // // Monitor State = Disabled // state = "Offline Forced"; // else // if (bigIPPoolMemberState[0][i].session_state == CommonEnabledState.STATE_ENABLED) // // Session State = Enabled // // Monitor State = Enabled // state = "Enabled"; // else // // Session State = Disabled // // Monitor State = Enabled // state = "Disabled"; // poolMemberNames.Add(poolName + ";" + bigIPPoolMemberState[0][i].member.address + ";" + bigIPPoolMemberState[0][i].member.port.ToString() + ";" + state); // } //} IEnumerable bigIPPoolData = GetF5PoolMembers(poolMemberNames); int numPools = response.WithFiltering().PublishRange(bigIPPoolData); }
public void Execute(IOpalisRequest request, IOpalisResponse response) { // Open a connection to the F5 bool bInitialized = F5Connection.initialize(connection.Host, connection.UserName, connection.Password); poolName = request.Inputs["Pool Name"].AsString(); memberName = request.Inputs["Member Name"].AsString(); memberState = request.Inputs["Member State"].AsString(); CommonIPPortDefinition Node = parseMember(memberName); LocalLBPoolMemberMemberMonitorState[][] monitor_states = new LocalLBPoolMemberMemberMonitorState[1][]; monitor_states[0] = new LocalLBPoolMemberMemberMonitorState[1]; monitor_states[0][0] = new LocalLBPoolMemberMemberMonitorState(); monitor_states[0][0].member = new CommonIPPortDefinition(); monitor_states[0][0].member = Node; LocalLBPoolMemberMemberSessionState[][] session_states = new LocalLBPoolMemberMemberSessionState[1][]; session_states[0] = new LocalLBPoolMemberMemberSessionState[1]; session_states[0][0] = new LocalLBPoolMemberMemberSessionState(); session_states[0][0].member = new CommonIPPortDefinition(); session_states[0][0].member = Node; switch (memberState) { case "Enabled": monitor_states[0][0].monitor_state = CommonEnabledState.STATE_ENABLED; session_states[0][0].session_state = CommonEnabledState.STATE_ENABLED; break; case "Disabled": monitor_states[0][0].monitor_state = CommonEnabledState.STATE_ENABLED; session_states[0][0].session_state = CommonEnabledState.STATE_DISABLED; break; case "Forced Offline": monitor_states[0][0].monitor_state = CommonEnabledState.STATE_DISABLED; session_states[0][0].session_state = CommonEnabledState.STATE_DISABLED; break; default: break; } F5Connection.LocalLBPoolMember.set_monitor_state(new string[] { poolName }, monitor_states); F5Connection.LocalLBPoolMember.set_session_enabled_state(new string[] { poolName }, session_states); // List <string> poolMemberNames = new List <string>(); LocalLBPoolMemberMemberSessionState[][] bigIPPoolMemberData = F5Connection.LocalLBPoolMember.get_session_enabled_state(new string[] { poolName }); for (int i = 0; i < bigIPPoolMemberData[0].Length; i++) { if (bigIPPoolMemberData[0][i].member.address.Equals(Node.address) && bigIPPoolMemberData[0][i].member.port == Node.port) { poolMemberNames.Add(poolName + ";" + bigIPPoolMemberData[0][i].member.address + ";" + bigIPPoolMemberData[0][i].member.port.ToString() + ";" + bigIPPoolMemberData[0][i].session_state.ToString()); } } IEnumerable bigIPPoolData = GetF5PoolMembers(poolMemberNames); int numPools = response.WithFiltering().PublishRange(bigIPPoolData); //response.Publish("Pool Members Count", numPools); }