You are here

function hosting_ip_allocate in Hosting 7.3

Same name and namespace in other branches
  1. 6.2 server/hosting.ip.inc \hosting_ip_allocate()
  2. 7.4 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 114
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) {
      $id = db_insert('hosting_ssl_cert_ips')
        ->fields(array(
        'cid' => $cert->cid,
        'ip_address' => $ip,
      ))
        ->execute();
    }
  }
  db_query("UNLOCK TABLES");
  return $ips;
}