function hosting_ip_allocate in Hosting 6.2
Same name and namespace in other branches
- 7.4 server/hosting.ip.inc \hosting_ip_allocate()
- 7.3 server/hosting.ip.inc \hosting_ip_allocate()
Allocate an IP for a given site on a given server.
1 call to hosting_ip_allocate()
- hosting_ssl_save_key in web_server/
ssl/ hosting_ssl.nodeapi.inc - Store the SSL Cert key in the database.
File
- server/
hosting.ip.inc, line 108 - General IP address CRUD routines.
Code
function hosting_ip_allocate($cert, $site) {
// make sure the IP is not allocated while we pick ours
db_query("LOCK TABLES {hosting_ssl_cert_ips} WRITE, {hosting_ip_addresses} WRITE");
$platform = node_load($site->platform);
$server = node_load($platform->web_server);
// IP allocation for master server
$ips = array();
// IP allocation for nodes in the cluster
// XXX: this should be in classes, see below
switch ($server->services['http']->type) {
case 'pack':
foreach ($server->services['http']->master_servers as $s) {
$ips[] = hosting_server_ip_allocate($s);
}
foreach ($server->services['http']->slave_servers as $s) {
$ips[] = hosting_server_ip_allocate($s);
}
break;
case 'cluster':
foreach ($server->services['http']->web_servers as $s) {
$ips[] = hosting_server_ip_allocate($s);
}
break;
default:
$ips = array(
hosting_server_ip_allocate($server->nid),
);
}
foreach ($ips as $ip) {
if (!$ip) {
// IP allocation failed, unlock tables and return false
db_query("UNLOCK TABLES");
return $ip;
}
}
// IP allocation succeeded, actually insert all required entries
foreach ($ips as $ip) {
if ($ip) {
db_query("INSERT INTO {hosting_ssl_cert_ips} (cid, ip_address) VALUES (%d, %d)", $cert->cid, $ip);
}
}
db_query("UNLOCK TABLES");
return $ips;
}