1、前提:

操作F5设备需要导包iControl-13.1.0.jar(这里是我自己使用的,具体的根据自己情况而定),通过API进行对F5设备进行操作。

2、自定义连接池

自己构建一个连接池,避免每次对F5进行操作(增、删、查)时候都创建连接

package com.sino.apprelation.ltm.config;

import com.google.common.collect.Maps;

import iControl.Interfaces;

import lombok.extern.slf4j.Slf4j;

import org.springframework.stereotype.Component;

import java.util.Map;

import java.util.Set;

/**

* @Description: F5连接池配置

* @Author: liu

* @Version: 1.0

* @Create Date Time: 2022-06-21 14:47

* @Update Date Time:

* @see

*/

@Component

@Slf4j

public class F5ConnectionPoolConfig {

//用于存放f5的连接数据

private Map f5InterfacesMap = Maps.newHashMap();

public Map getF5InterfacesMap() {

return f5InterfacesMap;

}

public void setF5InterfacesMap(Map f5InterfacesMap) {

this.f5InterfacesMap = f5InterfacesMap;

}

public synchronized Interfaces createF5ConnectionPool(String f5_ip, String userName, String passWord) {

Map f5InterfacesMap = getF5InterfacesMap();

if (f5InterfacesMap == null) {

Interfaces f5Interfaces = new Interfaces(f5_ip, userName, passWord);

//存入到map中

f5InterfacesMap.put(f5_ip, f5Interfaces);

return f5Interfaces;

} else {

Set f5KeySet = f5InterfacesMap.keySet();

if (f5KeySet.contains(f5_ip)) {

return f5InterfacesMap.get(f5_ip);

} else {

Interfaces f5Interfaces = new Interfaces(f5_ip, userName, passWord);

//存入到map中

f5InterfacesMap.put(f5_ip, f5Interfaces);

return f5Interfaces;

}

}

}

}

3、测试

以删除VS、Snat、poolName为例子(其他的操作可调用具体的API),测试demo为了更好的学会使用。

package com.sino.apprelation.ltm;

import com.sino.apprelation.ltm.config.F5ConnectionPoolConfig;

import com.sino.apprelation.ltm.service.LtmVsPoolService;

import iControl.*;

import lombok.extern.slf4j.Slf4j;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.boot.test.context.SpringBootTest;

import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)

@SpringBootTest

@Slf4j

public class F5InfoDeleteTest {

@Autowired

private F5ConnectionPoolConfig f5ConnectionPoolConfig;

@Test

public void test() throws Exception {

//vs名称

String[] vsName = {"ebank_3666_vs"};

//snat的名称和ip

String[] snat_pools = {"ebank_01_3666_snat"};

//pool_name 和 poolMember 初始化

String[] pool_name = {"ebank_01_3666_pool"};

//通过连接池创建连接

Interfaces f5Interfaces = f5ConnectionPoolConfig.createF5ConnectionPool("192.168.XXX.XXX", "admin", "admin");

//直接创建连接

// Interfaces f5Interfaces = new Interfaces("192.168.XXX.XXX", "admin", "admin");

//vs初始化

LocalLBVirtualServerBindingStub localLBVirtualServer = f5Interfaces.getLocalLBVirtualServer();

//SNAT初始化

LocalLBSNATPoolBindingStub localLBSNATPool = f5Interfaces.getLocalLBSNATPool();

//Pool初始化

LocalLBPoolBindingStub localLBPool = f5Interfaces.getLocalLBPool();

//删除下发失败的 vs信息

localLBVirtualServer.delete_virtual_server(vsName);

//删除snat的poolName和节点信息

localLBSNATPool.delete_snat_pool(snat_pools);

//删除poolName

localLBPool.delete_pool(pool_name);

}

}

注意:node节点信息是公用的,删除的时候只需要删除vsName、poolName 和snatName即可,不要删除节点信息,避免造成不必要的错误!!!

希望以上内容能够帮助到大家!!!

相关链接

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: