Example #1
0
		private static void InsertNewPool(Pool pool)
		{
			F5Interfaces.LocalLBPool.create(
				new[] { pool.Name },
				new[] { (LocalLBLBMethod)pool.LoadBalancingMethod },
				new[] { pool.Members.Select(x => new CommonIPPortDefinition { address = x.Address, port = x.Port }).ToArray() });
			F5Interfaces.LocalLBPool.set_monitor_association(
				new[] {new LocalLBPoolMonitorAssociation
				{
					pool_name = pool.Name,
					monitor_rule = new LocalLBMonitorRule
					{
						quorum = 0,
						type = LocalLBMonitorRuleType.MONITOR_RULE_TYPE_SINGLE,
						monitor_templates = pool.Monitors.ToArray()
					}
				}});
		}
Example #2
0
		public static void ApplyPool(Pool pool)
		{
			var existingPool = FindPool(pool.Name);
			if (existingPool == null)
			{
				InsertNewPool(pool);
			}
			else
			{
				UpdatePool(pool);
			}
		}
Example #3
0
		private static void UpdatePool(Pool pool)
		{
			F5Interfaces.LocalLBPool.remove_monitor_association(new[] { pool.Name });
			var members = F5Interfaces.LocalLBPool.get_member(new[] { pool.Name }).First().ToArray();
			F5Interfaces.LocalLBPool.remove_member(
				new[] { pool.Name },
				new[] { members });

			F5Interfaces.LocalLBPool.set_lb_method(
				new[] { pool.Name },
				new[] { (LocalLBLBMethod)pool.LoadBalancingMethod });
			F5Interfaces.LocalLBPool.add_member(
				new[] { pool.Name },
				new[] { pool.Members.Select(x => new CommonIPPortDefinition { address = x.Address, port = x.Port }).ToArray() });
			F5Interfaces.LocalLBPool.set_monitor_association(
				new[] {new LocalLBPoolMonitorAssociation
				{
					pool_name = pool.Name,
					monitor_rule = new LocalLBMonitorRule
					{
						quorum = 0,
						type = LocalLBMonitorRuleType.MONITOR_RULE_TYPE_SINGLE,
						monitor_templates = pool.Monitors.ToArray()
					}
				}});
		}
Example #4
0
		public static Pool FindPool(string name)
		{
			var poolName = F5Interfaces.LocalLBPool.get_list().FirstOrDefault(x => x == name);
			if (poolName == null)
				return null;
			var loadBalancingMethod = F5Interfaces.LocalLBPool.get_lb_method(new[] { poolName }).FirstOrDefault();
			var members = F5Interfaces.LocalLBPool.get_member(new[] { poolName }).FirstOrDefault();
			var monitorAssociations = F5Interfaces.LocalLBPool.get_monitor_association(new[] { poolName }).FirstOrDefault();

			var pool = new Pool
			{
				Name = poolName,
				LoadBalancingMethod = (LoadBalancingMethod)loadBalancingMethod,
				Members = members == null
					? new List<PoolMember>()
					: members.Select(x => new PoolMember { Address = x.address, Port = x.port }),
				Monitors = monitorAssociations == null
					? new List<string>()
					: monitorAssociations.monitor_rule.monitor_templates.ToList()
			};

			return pool;
		}