hosting_dns.service.inc

Provide the hosting serivce classes for DNS integration.

Classes

Namesort descending Description
hostingService_dns DNS service base class.
hostingService_dns_bind An implementation of the dns service type, registered with hook_hosting_service.
hostingService_dns_bind_slave Slave-specific servers
hostingService_dns_dnsmasq An implementation of the dns service type, registered with hook_hosting_service.
hostingService_dns_master Helper class to factor together master functionality

File

dns/hosting_dns.service.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Provide the hosting serivce classes for DNS integration.
  5. */
  6. /**
  7. * DNS service base class.
  8. */
  9. class hostingService_dns extends hostingService {
  10. public $service = 'dns';
  11. }
  12. /**
  13. * Helper class to factor together master functionality
  14. *
  15. * This mostly consists of master->slave mapping
  16. */
  17. class hostingService_dns_master extends hostingService_dns {
  18. function view(&$render) {
  19. parent::view($render);
  20. if (sizeof($this->slave_servers)) {
  21. $render['slave_servers'] = array(
  22. '#type' => 'item',
  23. '#title' => t('Slave servers'),
  24. '#value' => theme('item_list', array('items' => array_map('_hosting_node_link', array_intersect_key($this->slave_servers, hosting_get_servers('dns'))))),
  25. );
  26. }
  27. }
  28. function form(&$form) {
  29. parent::form($form);
  30. $servers = hosting_get_servers('dns');
  31. // Exclude the current server from the list of possible slaves.
  32. if (isset($this->server->nid)) {
  33. unset($servers[$this->server->nid]);
  34. }
  35. if (sizeof($servers)) {
  36. $form['slave_servers'] = array(
  37. '#title' => t('Slave DNS servers'),
  38. '#type' => 'checkboxes',
  39. '#options' => $servers,
  40. '#default_value' => isset($this->slave_servers) ? $this->slave_servers : array(),
  41. );
  42. }
  43. else {
  44. $form['slave_server'] = array(
  45. '#type' => 'value',
  46. '#value' => array(),
  47. );
  48. }
  49. }
  50. function load() {
  51. parent::load();
  52. $slave_servers = array();
  53. $result = db_query('SELECT slave_nid FROM {hosting_dns_slaves} WHERE master_vid = :master_vid', array(':master_vid' => $this->server->vid));
  54. while ($slave_server = $result->fetch()) {
  55. $slave_servers[] = $slave_server->slave_nid;
  56. }
  57. $this->setValues(array('slave_servers' => drupal_map_assoc($slave_servers)));
  58. }
  59. function insert() {
  60. parent::insert();
  61. if (is_array($this->slave_servers)) {
  62. foreach (array_filter($this->slave_servers) as $slave_server) {
  63. $record = array(
  64. 'master_nid' => $this->server->nid,
  65. 'master_vid' => $this->server->vid,
  66. 'slave_nid' => $slave_server,
  67. );
  68. drupal_write_record('hosting_dns_slaves', $record);
  69. }
  70. }
  71. }
  72. function delete() {
  73. parent::delete();
  74. db_delete('hosting_dns_slaves')
  75. ->condition('master_nid', $this->server->nid)
  76. ->execute();
  77. }
  78. function delete_revision() {
  79. parent::delete_revision();
  80. db_delete('hosting_dns_slaves')
  81. ->condition('master_vid', $this->server->vid)
  82. ->execute();
  83. }
  84. function context_options($task_type, $ref_type, &$task) {
  85. parent::context_options($task_type, $ref_type, $task);
  86. if (is_array($this->slave_servers) && sizeof($this->slave_servers)) {
  87. $task->context_options['slave_servers'] = implode(',', array_values(array_map('hosting_context_name', array_intersect_key($this->slave_servers, hosting_get_servers('dns')))));
  88. }
  89. }
  90. }
  91. /**
  92. * An implementation of the dns service type, registered with hook_hosting_service.
  93. */
  94. class hostingService_dns_dnsmasq extends hostingService_dns_master {
  95. public $type = 'dnsmasq';
  96. public $has_restart_cmd = TRUE;
  97. function default_restart_cmd() {
  98. return "sudo /etc/init.d/dnsmasq restart";
  99. }
  100. }
  101. /**
  102. * An implementation of the dns service type, registered with hook_hosting_service.
  103. */
  104. class hostingService_dns_bind extends hostingService_dns_master {
  105. public $type = 'bind';
  106. public $has_restart_cmd = TRUE;
  107. function default_restart_cmd() {
  108. return "sudo /etc/init.d/bind restart";
  109. }
  110. }
  111. /**
  112. * Slave-specific servers
  113. */
  114. class hostingService_dns_bind_slave extends hostingService_dns {
  115. public $type = 'bind_slave';
  116. public $has_restart_cmd = TRUE;
  117. function default_restart_cmd() {
  118. return "sudo /etc/init.d/bind restart";
  119. }
  120. }