Skip to content

Instantly share code, notes, and snippets.

@sbalukoff
Last active February 17, 2016 22:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbalukoff/e6cd600b4a12ee582f5e to your computer and use it in GitHub Desktop.
Save sbalukoff/e6cd600b4a12ee582f5e to your computer and use it in GitHub Desktop.
# Get subnets:
neutron subnet-list
# Create a neutron port:
neutron port-create private
# Make note of the ip_address, port_id and subnet_id for the next command
export PORT_ID=2d9013d7-6088-4198-8271-554db824bb47
export SUBNET_ID=43a17ff1-17d1-486b-bcdd-8d920c4cd668
# Create a loadbalancer:
curl -X POST -H Content-type:application/json -d "{\"name\": \"test_lb\", \"vip\": {\"ip_address\": \"10.0.0.3\", \"port_id\": \"$PORT_ID\", \"subnet_id\": \"$SUBNET_ID\"}}" http://localhost:9876/v1/loadbalancers
# Get loadbalancer list (do this until pending create is no longer pending...):
curl http://localhost:9876/v1/loadbalancers
export LB=dc149fdb-25e7-45ad-9926-423dd986a587
# get listeners:
curl http://localhost:9876/v1/loadbalancers/$LB/listeners
# create listener:
curl -X POST -H Content-type:application/json -d '{"name": "test_listener", "protocol": "HTTP", "protocol_port": 80}' http://localhost:9876/v1/loadbalancers/$LB/listeners
export LISTENER=bd361e18-4d7f-4047-90d8-5d9437201071
# get the above listener's pools:
curl http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/pools
# create pool:
curl -X POST -H Content-type:application/json -d '{"name":"test_pool1", "protocol": "HTTP", "lb_algorithm": "ROUND_ROBIN"}' http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/pools
export POOL1=9aa70a15-65aa-46e3-8805-00886b4da381
# create pool in lb context:
curl -X POST -H Content-type:application/json -d '{"name":"test_pool2", "protocol": "HTTP", "lb_algorithm": "ROUND_ROBIN"}' http://localhost:9876/v1/loadbalancers/$LB/pools
export POOL2=52b8a381-34bc-464b-93ab-9cb83853b699
curl -X POST -H Content-type:application/json -d '{"name":"test_pool3", "protocol": "HTTP", "lb_algorithm": "ROUND_ROBIN"}' http://localhost:9876/v1/loadbalancers/$LB/pools
export POOL3=8491c8db-2e59-4d09-8686-cfb34353df1d
curl -X POST -H Content-type:application/json -d '{"name":"test_pool4", "protocol": "HTTP", "lb_algorithm": "ROUND_ROBIN", "session_persistence": {"type": "SOURCE_IP"}}' http://localhost:9876/v1/loadbalancers/$LB/pools
export POOL4=c0767fa5-8ca0-43d6-a1c6-ca9dbbbf32f8
# Update listener to use different pool2 as default:
curl -X PUT -H Content-type:application/json -d "{\"default_pool_id\": \"$POOL2\"}" http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER
curl -X PUT -H Content-type:application/json -d "{\"default_pool_id\": \"$POOL3\"}" http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER
curl -X PUT -H Content-type:application/json -d "{\"default_pool_id\": \"$POOL4\"}" http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER
# Create second listener that also uses the above pool
curl -X POST -H Content-type:application/json -d "{\"name\": \"test_listener2\", \"protocol\": \"HTTP\", \"protocol_port\": 81, \"default_pool_id\": \"$POOL2\"}" http://localhost:9876/v1/loadbalancers/$LB/listeners
export LISTENER2=409fe78b-d92b-4319-9d91-360736eb1cb9
# Get members:
curl -X GET http://localhost:9876/v1/loadbalancers/$LB/pools/$POOL1/members
# Create a member
curl -X POST -H Content-type:application/json -d '{"ip_address": "10.0.0.50", "protocol_port": 81}' http://localhost:9876/v1/loadbalancers/$LB/pools/$POOL1/members
export MEMBER1=8897fe63-dcb7-4600-9aa7-a65e23a878e5
curl -X POST -H Content-type:application/json -d '{"ip_address": "10.0.0.51", "protocol_port": 80}' http://localhost:9876/v1/loadbalancers/$LB/pools/$POOL1/members
export MEMBER2=ce62a6a9-510d-4ced-944b-5e11498ad59f
# Delete a member
curl -X DELETE http://localhost:9876/v1/loadbalancers/$LB/pools/$POOL1/members/$MEMBER2
# Update a member:
curl -X PUT -H Content-type:application/json -d '{"protocol_port": 82}' http://localhost:9876/v1/loadbalancers/$LB/pools/$POOL1/members/$MEMBER1
# Delete that default pool...
curl -X DELETE http://localhost:9876/v1/loadbalancers/$LB/pools/$POOL1
# Create that pool again...
curl -X POST -H Content-type:application/json -d '{"name":"test_pool1", "protocol": "HTTP", "lb_algorithm": "ROUND_ROBIN"}' http://localhost:9876/v1/loadbalancers/$LB/pools
export POOL1=5fde76da-bb8d-4645-b9df-bc733ee48d5e
# Assign it to LISTENER:
curl -X PUT -H Content-type:application/json -d "{\"default_pool_id\": \"$POOL1\"}" http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER
# Get a pool...
curl -X GET http://localhost:9876/v1/loadbalancers/$LB/pools
# Create session persistence on a pool...
curl -X PUT -H Content-type:application/json -d '{"session_persistence": {"type": "SOURCE_IP"}}' http://localhost:9876/v1/loadbalancers/$LB/pools/$POOL1
# Update session persistence on a pool...
curl -X PUT -H Content-type:application/json -d '{"session_persistence": {"type": "HTTP_COOKIE", "cookie_name": "foobar"}}' http://localhost:9876/v1/loadbalancers/$LB/pools/$POOL1
# Create an l7policy referencing the pool and listener...
curl -X POST -H Content-type:application/json -d "{\"name\":\"test_policy\", \"action\": \"REDIRECT_TO_POOL\", \"position\": 1, \"redirect_pool_id\": \"$POOL4\"}" http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/l7policies
export LP1=fcdfe72a-3e21-41fc-a853-6fdb94816ae3
curl -X POST -H Content-type:application/json -d "{\"name\":\"test_policy2\", \"action\": \"REDIRECT_TO_URL\", \"redirect_url\": \"http://www.example.com\"}" http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/l7policies
export LP2=0d9c8a72-66a4-423d-9c8d-1183ecc6441f
curl -X POST -H Content-type:application/json -d "{\"name\":\"test_policy3\", \"action\": \"REJECT\"}" http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/l7policies
export LP3=0f740ab8-6b0d-4c01-a2bc-0946f8433c05
# Create an l7rule...
curl -X POST -H Content-type:application/json -d '{"type":"PATH", "compare_type": "STARTS_WITH", "value": "/api"}' http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/l7policies/$LP1/l7rules
# Update an l7policy...
curl -X PUT -H Content-type:application/json -d "{\"redirect_pool_id\": \"$POOL3\"}" http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/l7policies/$LP1
# Get an l7policy...
curl -X GET http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/l7policies
# Delete an l7policy...
curl -X DELETE http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/l7policies/$LP3
# Create an l7rule...
curl -X POST -H Content-type:application/json -d '{"type":"PATH", "compare_type": "STARTS_WITH", "value": "/api"}' http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/l7policies/$LP1/l7rules
export LR1=59fbf299-932f-4ec2-ae90-1c53b2e80453
curl -X POST -H Content-type:application/json -d '{"type":"PATH", "compare_type": "STARTS_WITH", "value": "/images"}' http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/l7policies/$LP3/l7rules
export LR2=6384723f-8874-47e3-afb0-40b5634a9835
curl -X POST -H Content-type:application/json -d '{"type":"HEADER", "key": "X-My-Header", "compare_type": "REGEX", "value": ".*thisor that"}' http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/l7policies/$LP1/l7rules
export LR3=1884492c-7dd1-4e15-a53e-1957372f7a68
# Get an l7rule...
curl -X GET http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/l7policies/$LP1/l7rules
# Update an l7rule...
curl -X PUT -H Content-type:application/json -d '{"invert": true}' http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/l7policies/$LP1/l7rules/$LR1
# Delete an l7rule...
curl -X DELETE http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/l7policies/$LP1/l7rules/$LR3
# Create a health monitor:
curl -X POST -H Content-type:application/json -d '{"type": "HTTP", "delay": 5, "timeout": 10, "fall_threshold": 4, "rise_threshold": 2}' http://localhost:9876/v1/loadbalancers/$LB/pools/$POOL1/healthmonitor
curl -X POST -H Content-type:application/json -d '{"type": "HTTP", "delay": 5, "timeout": 10, "fall_threshold": 4, "rise_threshold": 2}' http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/pools/$POOL1/healthmonitor
# Update health monitor:
curl -X PUT -H Content-type:application/json -d '{"rise_threshold": 3}' http://localhost:9876/v1/loadbalancers/$LB/pools/$POOL1/healthmonitor
curl -X PUT -H Content-type:application/json -d '{"rise_threshold": 3}' http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/pools/$POOL1/healthmonitor
# Get a health monitor:
curl -X GET http://localhost:9876/v1/loadbalancers/$LB/pools/$POOL1/healthmonitor
curl -X GET http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/pools/$POOL1/healthmonitor
# Delete a health monitor:
curl -X DELETE http://localhost:9876/v1/loadbalancers/$LB/pools/$POOL1/healthmonitor
curl -X DELETE http://localhost:9876/v1/loadbalancers/$LB/listeners/$LISTENER/pools/$POOL1/healthmonitor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment