Commit 5f21302c authored by anarcat's avatar anarcat Committed by anarcat

fix zone deletion, add documentation, update todos

parent 875d9422
......@@ -19,24 +19,6 @@ provision-zone create-host www.foobar.com
should another similar record to the same zonefile.
Bugs:
1. since the rewrite of the parser, some fields in the SOA are
missing (retry, refresh, etc) because we lack the context from the
server (switching to create_config() shoudl fix that)
2. the internal data structure is confusing and not efficient. here's
a proposed change:
$zonefile = array('www' => array('a' => array('1.2.3.3', '1.2.3.4')),
'@' => array('SOA' => array('hostmaster' => 'localhost', 'email' => 'admin.localhost', 'serial' => '2010082301', 'refresh' => 21600 3600 604800 86400 )'),
'A' => array('1.2.3.3'),
'MX' => array('mail.localhost'),
'NS' => array('localhost', 'ns2.localhost'),
)
);
(patched, needs testing and verification)
4. removing the last record in a zonefile doesn't remove the zone
Caveats:
1. there's duplicate storage altogether: we could parse zonefiles and
......@@ -48,8 +30,4 @@ Todo:
1. we need slave configuration (ie. modify the slaves configuration
so that they sync with the master, so just act on create_zone())
2. for this we need to define the services (ie. the slaves too) in
the frontend and add NS records when the zonefile is created
3. we need to hook the zones into the bind configuration (see the
commented line in create_zone())
4. we need to reload bind when that is done
2. we need to reload bind when changes are done, ideally only once per zone
......@@ -78,6 +78,43 @@ class provisionConfig_dns_zone_store extends provisionConfig_data_store {
}
}
/**
* Representation of a DNS zonefile
*
* This is the internal representation of a zonefile. It can be
* extended by other subclasses to implement various engines, but it
* has its own internal storage (through
* provisionConfig_dns_zone_store).
*
* It assumes a certain structure in the records of the store.
*
* @example
*
* <code>
* $zonefile = array('www' => array('a' => array('1.2.3.3', '1.2.3.4')),
* '@' => array('SOA' => array('hostmaster' => 'localhost', 'email' => 'admin.localhost', 'serial' => '2010082301', 'refresh' => 21600 ... )'),
* 'A' => array('1.2.3.3'),
* 'MX' => array('mail.localhost'),
* 'NS' => array('localhost', 'ns2.localhost'),
* )
* );
* </code>
*
* The zonefile's serial number is incremented automaticall when the
* file is written (in process()). Note how the structure of the SOA
* record is different from the others. First, it is a key-value
* map. Second, it represents only one DNS record (whereas the other
* entries represent as many entries as there are entries in the
* array.
*
* To edit those records, some care need to be taken. Look at the
* implementation of rr-add, rr-delete and rr-modify for examples of
* how it should properly be done, in drush_dns_provision_zone().
*
* @see drush_dns_provision_zone()
* @see increment_serial()
* @see provisionConfig_dns_zone_store
*/
class provisionConfig_dns_zone extends provisionConfig_dns {
public $template = 'zone.tpl.php';
public $description = 'Zone-wide DNS configuration';
......@@ -104,12 +141,54 @@ class provisionConfig_dns_zone extends provisionConfig_dns {
// lock the store until we are done generating our config.
$this->store->lock();
parent::write();
$this->store->write();
if ($this->is_empty()) {
$this->unlink();
} else {
parent::write();
$this->store->write();
}
$this->store->close();
}
/**
* this destroys this zonefile, without any checks
*
* It actually removes the zonefile, the internal storage and the
* record in the server config.
*/
function unlink() {
// remove the zonefile
if (parent::unlink()) {
// remove the master record
// XXX: need to do this for slaves too
$this->server->service('dns')->config('server')->record_del($zone)->write();
// remove the zonefile storage
$this->store->unlink();
}
$this->store->unlock();
}
/**
* test to see if the
*/
function is_empty() {
$records = $this->config('zone', $zone)->merge_records();
// if there is any record that is not SOA or NS, this is
// considered empty
foreach ($records as $name => $record) {
if ($name != '@') {
return FALSE;
} else {
foreach ($record as $type => $destination) {
if ($type != 'SOA' && $type != 'NS' && !is_null($destination)) {
return FALSE;
}
}
}
}
return TRUE;
}
}
......
......@@ -245,7 +245,7 @@ class provisionService_dns extends provisionService {
* This completely drops a zone, without any checks.
*/
function delete_zone($zone) {
$this->config('server')->record_del($zone)->write();
$this->config('zone', $zone)->unlink();
}
/**
......@@ -316,11 +316,6 @@ class provisionService_dns extends provisionService {
// remove the records from the zone store
$this->config('zone', $zone)->
record_set($sub, array('A' => null))->write();
// XXX: need to guess the number of records left now and remove only if
// there are no more records
//$this->delete_zone($zone);
$this->delete_config('host');
}
}
......
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