Forum Discussion
4 Replies
Hi,
looks like you can create multiple new nodes as part of a new pool.
Creating, disabling, enabling, and deleting a node
To create a new node, use the following command syntax:
POST /mgmt/tm/ltm/node/ -d '{"name":"","partition":"","address":""}'
For example, to create a new node named test_node on the Common partition, type the following command:
POST /mgmt/tm/ltm/node/ -d '{"name":"test_node","partition":"Common","address":"10.99.5.2"}'
To create a new pool using new nodes, use the following command syntax:
POST /mgmt/tm/ltm/pool/ -d '{"name":"","partition":"","monitor":"//","members":[{"name":"","address":""}],"members":[{"name":":","address":""}]}'
Excellent reference:
K13225405: Common iControl REST API command examples
https://support.f5.com/csp/article/K13225405
- youssef1Cumulonimbus
Hello,
First of you have to generate your Authentication token using this command:
curl -k -X POST -H "Content-Type: application/json" -d '{"username":"restapiuser","password":"restapiuser","loginProviderName": "tmos"}' https://management-IP/mgmt/shared/authn/login
You will receive a json, which includes a token. we will use it later for all our other rest API call.
..............{"token":"2MBFDOIJEFEKJ97DSDSDDSETU"...............
node creation:
curl -k -X POST -H "Content-Type: application/json" -H "X-F5-Auth-Token:2MBFDOIJEFEKJ97DSDSDDSETU" -d '{"name":"","address":""}' https://management-IP/mgmt/tm/ltm/node
Monitor creation:
curl -k -X POST -H "Content-Type: application/json" -H "X-F5-Auth-Token:2MBFDOIJEFEKJ97DSDSDDSETU" -d '{"name":"my-monitor-api","send":"GET / HTTP/1.1\r\nHost: mymonitor.domain.com\r\nConnection: Close\r\n\r\n","recv":""}' https://management-ip/mgmt/tm/ltm/monitor/http
Pool Creation:
curl -k -X POST -H "Content-Type: application/json" -H "X-F5-Auth-Token:2MBFDOIJEFEKJ97DSDSDDSETU" -d '{"name":"my-pool-api","monitor":"/Common/my-monitor-api"}' https://management-IP/mgmt/tm/ltm/pool
For more information you have a good doc below:
https://support.f5.com/csp/article/K51731137p1
let me know if you need more details.
regards,
- Andy_McGrathCumulonimbus
I don't think you can do create multiple nodes from the iControl REST API within a single request but you could script it using something like Python and the F5-SDK or with the use of Ansible.
Example Ansible playbook below, you would need to have the F5 device listed in the Ansible
file and namedhosts
.f5
--- - name: Run tasks on Active LTM hosts: f5 connection: local gather_facts: True vars: f5Provider: server: "{{inventory_hostname}}" server_port: 443 user: admin password: admin validate_certs: no transport: rest nodelist: - {name: 'test01', address: '10.0.0.1'} - {name: 'test02', address: '10.0.0.2'} - {name: 'test03', address: '10.0.0.3'} - {name: 'test04', address: '10.0.0.4'} tasks: - name: Add nodes bigip_node: provider: "{{f5Provider}}" partition: test address: "{{ item.address }}" name: "{{ item.name }}" loop: "{{nodelist}}" delegate_to: localhost notify: Save configuration handlers: - name: Save configuration bigip_config: save: yes delegate_to: localhost
NOTE: this is create four nodes in the
partition and then triggering a configuration save.test
- Lee_SutcliffeNacreous
The REST API doesn't permit 'bulk imports' So whilst the suggestions buy Tiziano and Youseff are correct, you would need to repeat the process as REST API uses an imperative model - think of it as multiple remote tmsh commands that need to be executed in a given order.
The easiest way to bulk import would be to consider Ansible, whilst the SDK under the hood will send multiple commands - it appears more declarative in nature.
--- - name: Setup hosts: f5 connection: local gather_facts: True vars: f5Provider: server: "{{inventory_hostname}}" user: "{{f5User}}" password: "{{f5Pass}}" validate_certs: no transport: rest nodelist: - {name: 'test01', address: '8.8.8.8', priority_group: 1, state: 'present'} - {name: 'test02', address: '8.8.4.4', priority_group: 1, state: 'present'} environment: F5_SERVER: "{{ inventory_hostname }}" F5_USER: "{{ f5Provider.user }}" F5_PASSWORD: "{{ f5Provider.password }}" F5_VALIDATE_CERTS: "{{ f5Provider.validate_certs }}" F5_SERVER_PORT: "{{ f5Provider.server_port }}" tasks: - name: Add pool 'test_pool' bigip_pool: lb_method: least-connections-member name: test_pool monitor_type: single monitors: - /Common/gateway_icmp priority_group_activation: 0 delegate_to: localhost notify: Save configuration - name: Add nodes bigip_node: address: "{{ item.address }}" name: "{{ item.name }}" loop: "{{ nodelist }}" delegate_to: localhost notify: Save configuration - name: Add pool members to Pool 'test_pool' bigip_pool_member: pool: test_pool address: "{{ item.address }}" name: "{{ item.name }}" port: 53 priority_group: "{{ item.priority_group }}" state: "{{ item.state }}" loop: "{{ nodelist }}" delegate_to: localhost notify: Save configuration