Commit 797299a1 authored by Adrian Rossouw's avatar Adrian Rossouw

working provision-zone delete and create zone commands. generates the data...

working provision-zone delete and create zone commands. generates the data store correctly, and uses locking.
parent 9f0be0f6
......@@ -256,6 +256,5 @@ class provisionConfig_bind_zone extends provisionConfig {
class provisionConfig_bind_server extends provisionConfig_dns_server {
function zone_declaration() {
return 'zone "' . $this->data['name'] . '" { type master; file "' . $this->bind_zone_master_path . '/' . $this->data['name'] . '"; allow-query { any; }; };';
}
}
......@@ -46,7 +46,13 @@ class provisionConfig_dns_server extends provisionConfig_dns {
}
function write() {
// lock the store until we are done generating our config.
$this->store->lock();
parent::write();
$this->store->write();
$this->store->close();
if (isset($this->data['application_name'])) {
$file = $this->data['application_name'] . '.conf';
// We link the app_name.conf file on the remote server to the right version.
......
......@@ -32,11 +32,16 @@ function drush_dns_provision_zone($action, $zone, $name = null, $type = null, $d
$status = d()->service('dns')->delete_host($zone);
break;
case 'verify':
case 'create':
$status = d()->service('dns')->create_zone($zone);
case 'create':
$config = d()->service('dns')->get_config('server');
$config->store->records[$zone] = $zone;
$config->write();
## $status = d()->service('dns')->create_zone($zone);
break;
case 'delete':
$status = d()->service('dns')->delete_zone($zone);
$config = d()->service('dns')->get_config('server');
$config->store->records[$zone] = FALSE;
$config->write();
break;
case 'rr-add':
$status = d()->service('dns')->add_record($zone, $name, $type, $destination);
......@@ -77,7 +82,7 @@ class provisionService_dns_basic extends provisionService_dns {
parent::init();
// Path for storing data store config files.
$this->server->dns_data_path = $this->server->aegir_root . '/dns.d';
$this->server->dns_data_path = $this->server->aegir_root . '/config/dns.d';
if (!is_null($this->application_name)) {
$app_dir = "{$this->server->config_path}/{$this->application_name}";
......
conf-dir=<?php print "$dns_zoned_path"; ?>
<?php
foreach ($records as $key => $name) {
printf("conf-file=%s/%s.zone\n", $dns_zoned_path, $name);
}
?>
#conf-dir=<?php print "$dns_zoned_path"; ?>
......@@ -48,7 +48,7 @@ class provisionConfig {
/**
* The data store.
*/
protected $store = NULL;
public $store = NULL;
/**
* Forward $this->... to $this->owner->...
......@@ -88,6 +88,7 @@ class provisionConfig {
if (!is_null($this->data_store_class) && class_exists($this->data_store_class)) {
$class = $this->data_store_class;
$this->store = new $class($owner, $data);
}
}
......@@ -108,6 +109,9 @@ class provisionConfig {
* This is a stub to be implemented by subclasses.
*/
function process() {
if (is_object($this->store)) {
$this->data['records'] = array_filter(array_merge($this->store->loaded_records, $this->store->records));
}
return true;
}
......@@ -415,15 +419,14 @@ class provisionConfig_data_store extends provisionConfig {
protected $fp = null;
public $records = array();
protected $loaded_records = array();
public $loaded_records = array();
protected $mode = 0400;
protected $mode = 0700;
function __construct($owner, $data = array()) {
parent::__construct($owner, $data);
$this->init_records = $data;
$this->load_data();
}
......@@ -433,8 +436,8 @@ class provisionConfig_data_store extends provisionConfig {
}
function open() {
if (!$this->fp) {
$this->fp = fopen($this->filename(), "w");
if (!is_resource($this->fp)) {
$this->fp = fopen($this->filename(), "w+");
}
}
......@@ -453,18 +456,17 @@ class provisionConfig_data_store extends provisionConfig {
$this->lock();
fwrite($this->fp, $text);
fflush($this->fp);
$this->close();
}
function unlock() {
if ($this->locked && $this->fp) {
if ($this->locked && is_resource($this->fp)) {
flock($this->fp, LOCK_UN);
$this->locked = FALSE;
}
}
function close() {
if ($this->fp) {
if (is_resource($this->fp)) {
fclose($this->fp);
}
}
......@@ -475,12 +477,15 @@ class provisionConfig_data_store extends provisionConfig {
// from under us.
if (file_exists($this->filename()) && is_readable($this->filename())) {
include($this->filename());
$this->loaded_records = ${$this->key};
$data_key = $this->key;
if (isset(${$data_key}) && is_array(${$data_key})) {
$this->loaded_records = ${$data_key};
}
}
}
}
function process() {
$this->data['records'] = array_merge($this->loaded_records, $this->records);
$this->data['records'] = array_filter(array_merge($this->loaded_records, $this->records));
}
}
......@@ -38,6 +38,13 @@ class provisionService extends provisionChainedState {
return false;
}
function get_config($config) {
foreach ((array) $this->configs[$config] as $class) {
return new $class($this->context, $this->config_data($config));
}
return false;
}
/**
* Generate a configuration file.
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment