Haproxy call
This commit is contained in:
@@ -515,18 +515,35 @@ class Provision extends BaseController
|
||||
$provisionUID = $pr->uid;
|
||||
log_message('critical', "***** ***** Configure URL $provisionURL to Point to ::: $provisionServer:$provisionPort ");
|
||||
// Here call haproxy actions
|
||||
list ($res, $message) = $this->configureHaproxyURL($provisionURL,$provisionServer,$provisionPort);
|
||||
// TODO: Check $res for errors
|
||||
$mysql_close = "UPDATE members_products WHERE SET url_status = 1 WHERE uid:;text = '$provisionUID' ";
|
||||
log_message('critical', "***** ***** Conclude if all Okay => $mysql_close ");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function haproxy() {
|
||||
public function haproxy():string {
|
||||
list ($res, $message) = $this->configureHaproxyURL("23607.devprov.mermsemr.com","172.16.4.91","6603");
|
||||
var_dump($message);
|
||||
log_message('critical',"Message => '".$message."'");
|
||||
return "Message:<br/>".$message;
|
||||
}
|
||||
|
||||
public function configureHaproxyURL($provisionURL, $provisionServer, $provisionPort) {
|
||||
$message = "";
|
||||
$base_url = 'http://172.16.4.99:5555';
|
||||
$username = 'admin';
|
||||
$password = 'Hapr0xy001';
|
||||
|
||||
list($status_code1, $cfgver) = $this->getHaProxyCfgVer($base_url,$username,$password);
|
||||
log_message('critical',"provisionURL => $provisionURL");
|
||||
log_message('critical',"provisionServer => $provisionServer");
|
||||
log_message('critical',"provisionPort => $provisionPort");
|
||||
|
||||
$status_code = [];
|
||||
|
||||
// 200
|
||||
list($status_code[0], $cfgver) = $this->getHaProxyCfgVer($base_url,$username,$password);
|
||||
$cfgver0 = trim($cfgver);
|
||||
|
||||
// Add backend
|
||||
@@ -549,8 +566,9 @@ curl -XPOST --user admin:Hapr0xy001 \
|
||||
}' \
|
||||
"http://172.16.4.99:5555/v3/services/haproxy/configuration/backends?version=$CFGVER" > backend.txt
|
||||
*/
|
||||
$backend = "backend".$cfgver0;
|
||||
$data = [
|
||||
"name" => "backend".$cfgver0,
|
||||
"name" => $backend,
|
||||
"mode" => "http",
|
||||
"http_connection_mode" => "httpclose",
|
||||
"forwardfor" => [
|
||||
@@ -562,12 +580,108 @@ curl -XPOST --user admin:Hapr0xy001 \
|
||||
]
|
||||
];
|
||||
$uri = '/v3/services/haproxy/configuration/backends?version=' . $cfgver0;
|
||||
list($status_code2, $result) = $this->getHaProxyPost($base_url,$username,$password,$uri,$data);
|
||||
// 202
|
||||
list($status_code[1], $result) = $this->getHaProxyPost($base_url,$username,$password,$uri,$data);
|
||||
|
||||
list($status_code3, $cfgver) = $this->getHaProxyCfgVer($base_url,$username,$password);
|
||||
$cfgver1 = trim($cfgver);
|
||||
// TODO: check the status code
|
||||
|
||||
return "<pre>CFGVER=$cfgver0\n($status_code2) $result\nCFGVER=$cfgver1</pre>";
|
||||
// 200
|
||||
list($status_code[2], $cfgver) = $this->getHaProxyCfgVer($base_url,$username,$password);
|
||||
$cfgver = trim($cfgver);
|
||||
|
||||
// Add Server
|
||||
/*
|
||||
#https://www.haproxy.com/documentation/dataplaneapi/community/?v=v3#post-/services/haproxy/configuration/backends/-parent_name-/servers
|
||||
curl -XPOST --user admin:Hapr0xy001 \
|
||||
-H 'Content-Type: application/json' -H 'Accept: application/json' \
|
||||
-d '{
|
||||
"name": "server'$CFGVER'",
|
||||
"address": "172.16.4.92",
|
||||
"port": 4401,
|
||||
"check": "enabled",
|
||||
"health_check_port": 4401
|
||||
}' \
|
||||
"http://172.16.4.99:5555/v3//services/haproxy/configuration/backends/$BACKEND/servers?version=$CFGVER" > server.txt
|
||||
*/
|
||||
# test => "server4"
|
||||
$server = "server".$cfgver0;
|
||||
$data = [
|
||||
"name" => $server,
|
||||
"address" => $provisionServer,
|
||||
"port" => (int)$provisionPort,
|
||||
"check" => "enabled",
|
||||
"health_check_port" => (int)$provisionPort
|
||||
];
|
||||
$uri = '/v3/services/haproxy/configuration/backends/'.$backend.'/servers?version=' . $cfgver;
|
||||
// 202
|
||||
list($status_code[3], $result) = $this->getHaProxyPost($base_url,$username,$password,$uri,$data);
|
||||
|
||||
// TODO: check the status code
|
||||
|
||||
// 200
|
||||
list($status_code[4], $cfgver) = $this->getHaProxyCfgVer($base_url,$username,$password);
|
||||
$cfgver = trim($cfgver);
|
||||
|
||||
// Add a new ACL to "http" frontend
|
||||
/*
|
||||
# https://www.haproxy.com/documentation/dataplaneapi/community/?v=v3#post-/services/haproxy/configuration/frontends/-parent_name-/acls/-index-
|
||||
curl -X POST --user admin:Hapr0xy001 \
|
||||
-H 'Content-Type: application/json' -H 'Accept: application/json' \
|
||||
-d '{
|
||||
"acl_name": "acl'$CFGVER'",
|
||||
"criterion": "req.hdr(Host)",
|
||||
"value": "23233.devprov.mermsemr.com"
|
||||
}' \
|
||||
"http://172.16.4.99:5555/v3/services/haproxy/configuration/frontends/http/acls/0?version=$CFGVER"
|
||||
*/
|
||||
$acl = "acl".$cfgver0;
|
||||
$data = [
|
||||
"acl_name" => $acl,
|
||||
"criterion" => "req.hdr(Host)",
|
||||
"value" => $provisionURL
|
||||
];
|
||||
$uri = '/v3/services/haproxy/configuration/frontends/http/acls/0?version=' . $cfgver;
|
||||
// 202
|
||||
list($status_code[5], $result) = $this->getHaProxyPost($base_url,$username,$password,$uri,$data);
|
||||
|
||||
// TODO: check the status code
|
||||
|
||||
// 200
|
||||
list($status_code[6], $cfgver) = $this->getHaProxyCfgVer($base_url,$username,$password);
|
||||
$cfgver = trim($cfgver);
|
||||
|
||||
// Add a new Backend Switching Rule to "http" frontend for "use_backend"
|
||||
/*
|
||||
# https://www.haproxy.com/documentation/dataplaneapi/community/?v=v3#post-/services/haproxy/configuration/frontends/-parent_name-/backend_switching_rules/-index-
|
||||
curl -X POST --user admin:Hapr0xy001 \
|
||||
-H 'Content-Type: application/json' -H 'Accept: application/json' \
|
||||
-d '{
|
||||
"name": "'$BACKEND'",
|
||||
"cond": "if",
|
||||
"cond_test": "'$ACL'"
|
||||
}' \
|
||||
"http://172.16.4.99:5555/v3/services/haproxy/configuration/frontends/http/backend_switching_rules/0?version=$CFGVER" > use_backend.txt
|
||||
*/
|
||||
$data = [
|
||||
"name" => $backend,
|
||||
"cond" => "if",
|
||||
"cond_test" => $acl
|
||||
];
|
||||
$uri = '/v3/services/haproxy/configuration/frontends/http/backend_switching_rules/0?version=' . $cfgver;
|
||||
// 202
|
||||
list($status_code[7], $result) = $this->getHaProxyPost($base_url,$username,$password,$uri,$data);
|
||||
|
||||
// TODO: check the status code
|
||||
|
||||
// 200
|
||||
list($status_code[8], $cfgver) = $this->getHaProxyCfgVer($base_url,$username,$password);
|
||||
$cfgver = trim($cfgver);
|
||||
|
||||
$codes = "";
|
||||
foreach ($status_code as $i=>$code) {
|
||||
$codes .= "\n$i => $code";
|
||||
}
|
||||
return [$status_code[7],"<pre>FIRST CFGVER=$cfgver0\n\n--- CODES: ----$codes\n\nLAST CFGVER=$cfgver</pre>"];
|
||||
}
|
||||
|
||||
private function getHaproxyPost($base_url,$username,$password,$uri,$data) {
|
||||
|
||||
Reference in New Issue
Block a user