dns.drush.inc

DNS provisioning module.

The goal of this module is to manage DNS zonefiles and Resource Records (RRs), for sites that are about to be created. It uses the provision API to tie into the right places in the site creation work flow.

Functions

Namesort descending Description
dns_drush_command Implementation of hook_drush_command().
dns_drush_init Implements hook_drush_init().
dns_provision_register_autoload Register our directory as a place to find provision classes.
dns_provision_services Implements hook_provision_services().
drush_dns_provision_zone

File

dns/dns.drush.inc
View source
  1. <?php
  2. // $Id: dns.drush.inc,v 1.4 2009/03/20 16:13:24 adrian Exp $
  3. /**
  4. * @file
  5. * DNS provisioning module.
  6. *
  7. * The goal of this module is to manage DNS zonefiles and Resource Records
  8. * (RRs), for sites that are about to be created. It uses the provision API to
  9. * tie into the right places in the site creation work flow.
  10. */
  11. //include_once(dirname(__FILE__) . '/../provision.service.inc');
  12. /**
  13. * Register our directory as a place to find provision classes.
  14. */
  15. function dns_provision_register_autoload() {
  16. static $loaded = FALSE;
  17. if (!$loaded) {
  18. $loaded = TRUE;
  19. provision_autoload_register_prefix('Provision_', dirname(__FILE__));
  20. }
  21. }
  22. /**
  23. * Implements hook_drush_init().
  24. */
  25. function dns_drush_init() {
  26. dns_provision_register_autoload();
  27. }
  28. /**
  29. * Implementation of hook_drush_command().
  30. */
  31. function dns_drush_command() {
  32. $items['provision-zone'] = array(
  33. 'arguments' => array('operation' => dt('The operation to perform on a zone (verify, delete, rr-add, rr-delete)')),
  34. 'description' => dt('Manipulate a zonefile'),
  35. 'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
  36. );
  37. return $items;
  38. }
  39. function drush_dns_provision_zone($action, $zone, $name = null, $type = null, $destination = null) {
  40. switch ($action) {
  41. case 'create-host':
  42. $status = d()->service('dns')->create_host($zone);
  43. break;
  44. case 'delete-host':
  45. $status = d()->service('dns')->delete_host($zone);
  46. break;
  47. case 'verify':
  48. case 'create':
  49. $status = d()->service('dns')->create_zone($zone);
  50. break;
  51. case 'delete':
  52. $status = d()->service('dns')->delete_zone($zone);
  53. break;
  54. case 'rr-add':
  55. $record = d()->service('dns')->config('zone', $zone)->record_get($name);
  56. if (!is_array($record[$type])) {
  57. $record[$type] = array();
  58. }
  59. $record[$type] = array_merge($record[$type], array($destination));
  60. $status = d()->service('dns')->config('zone', $zone)->record_set($name, $record)->write();
  61. break;
  62. case 'rr-modify':
  63. $status = d()->service('dns')->config('zone', $zone)->record_set($name, array($type => array($destination)))->write();
  64. break;
  65. case 'rr-delete':
  66. if ($type) {
  67. $status = d()->service('dns')->config('zone', $zone)->record_set($name, array($type => NULL))->write();
  68. } else {
  69. $status = d()->service('dns')->config('zone', $zone)->record_set($name, NULL)->write();
  70. }
  71. break;
  72. default:
  73. $status = drush_set_error('DRUSH_WRONG_ARGUMENT', dt("wrong argument provided to provision-zone"));
  74. break;
  75. }
  76. // XXX: we shouldn't reload zones unless we have actually done changes, but return values of the above functions are always FALSE
  77. d()->service('dns')->parse_configs();
  78. return $status;
  79. }
  80. /**
  81. * Implements hook_provision_services().
  82. */
  83. function dns_provision_services() {
  84. dns_provision_register_autoload();
  85. return array('dns' => NULL);
  86. }