- 
      
 - 
        
Save shoemoney/9bf085c72ad8c0c658fc39559855bda2 to your computer and use it in GitHub Desktop.  
    Programmatic HAProxy Configuration Using the Data Plane API
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | userlist dataplane-api | |
| user dataplaneapi password $5$oui1y1Q7o$VXoOr7Ns9WLyDFkWH0LTu9oysn/zyYhF4mSQHe9Ba5D | |
| program api | |
| command /opt/hapee-extras/sbin/hapee-dataplane-api --host 192.168.122.14 --port 5555 -c /etc/hapee-2.0/hapee-lb.cfg -u dataplane-api -b /opt/hapee-2.0/sbin/hapee-lb -r "service hapee-2.0-lb reload" --reload-delay 5 -m /var/run/hapee-2.0/hapee-lb.sock --log-to=file --log-file=/var/log/hapee-runtime-api.log | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $ curl -X GET \ | |
| -s \ | |
| --user dataplaneapi:example \ | |
| 192.168.122.14:5555/v1/services/haproxy/configuration/frontends | python -m json.tool | |
| { | |
| "_version": 1, | |
| "data": [ | |
| { | |
| "default_backend": "be_app", | |
| "name": "fe_main" | |
| } | |
| ] | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $ curl -X POST \ | |
| -s \ | |
| --user dataplaneapi:example \ | |
| 192.168.122.14:5555/v1/services/haproxy/transactions?version=1 | python -m json.tool | |
| { | |
| "_version": 1, | |
| "id": "633e5ed4-8407-4e8f-9197-270df4c41f67", | |
| "status": "in_progress" | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $ curl -X POST \ | |
| -s \ | |
| -H "Content-Type: application/json" \ | |
| --user dataplaneapi:example \ | |
| -d'{"name": "be_site", "mode": "http", "httpchk": { "method": "HEAD", "uri": "/", "version": "HTTP/1.0" }}' \ | |
| 192.168.122.14:5555/v1/services/haproxy/configuration/backends?transaction_id=633e5ed4-8407-4e8f-9197-270df4c41f67 | python -m json.tool | |
| { | |
| "httpchk": { | |
| "method": "HEAD", | |
| "uri": "/", | |
| "version": "HTTP/1.0" | |
| }, | |
| "mode": "http", | |
| "name": "be_site" | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $ curl -X POST \ | |
| -s \ | |
| -H "Content-Type: application/json" \ | |
| --user dataplaneapi:example \ | |
| -d'{"name": "srv1", "address": "192.168.122.1", "port": 80, "check": "enabled", "max-connections": 100}' \ | |
| '192.168.122.14:5555/v1/services/haproxy/configuration/servers?backend=be_site&transaction_id=633e5ed4-8407-4e8f-9197-270df4c41f67' | python -m json.tool | |
| { | |
| "address": "192.168.122.1", | |
| "check": "enabled", | |
| "name": "srv1", | |
| "port": 80 | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $ curl -X POST \ | |
| -s -H "Content-Type: application/json" \ | |
| --user dataplaneapi:example \ | |
| -d'{"name": "fe_site", "default_backend": "be_site", "mode": "http", "httplog": true}' \ | |
| '192.168.122.14:5555/v1/services/haproxy/configuration/frontends?transaction_id=633e5ed4-8407-4e8f-9197-270df4c41f67' | python -m json.tool | |
| { | |
| "default_backend": "be_site", | |
| "httplog": true, | |
| "mode": "http", | |
| "name": "fe_site" | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $ curl -X POST \ | |
| -s \ | |
| -H "Content-Type: application/json" \ | |
| --user dataplaneapi:example \ | |
| -d'{"name": "ssl", "address": "192.168.122.14", "port": 443, "ssl": true, "ssl_certificate": "/etc/hapee-2.0/certs/ssl.pem"}' \ | |
| '192.168.122.14:5555/v1/services/haproxy/configuration/binds?frontend=fe_site&transaction_id=633e5ed4-8407-4e8f-9197-270df4c41f67' | python -m json.tool | |
| { | |
| "address": "192.168.122.14", | |
| "name": "ssl", | |
| "port": 443, | |
| "ssl": true, | |
| "ssl_certificate": "/etc/hapee-2.0/certs/ssl.pem" | |
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $ curl -X PUT \ | |
| -H "Content-Type: application/json" \ | |
| --user dataplaneapi:example \ | |
| "192.168.122.64:5555/v1/services/haproxy/transactions/633e5ed4-8407-4e8f-9197-270df4c41f67"| python -m json.tool | |
| { | |
| "_version": 1, | |
| "id": "633e5ed4-8407-4e8f-9197-270df4c41f67", | |
| "status": "success" | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment