Added DNS migration

This commit is contained in:
Deon George
2012-07-12 15:10:53 +10:00
parent 42c7f29665
commit 0a211b4677
6 changed files with 204 additions and 150 deletions

View File

@@ -23,6 +23,7 @@ class Controller_Task_Host extends Controller_Task {
case 'getdns':
case 'getreseller':
case 'gettraffic':
case 'migrate':
case 'provision':
$this->so = ORM::factory('service',$this->request->param('id'));
@@ -71,7 +72,7 @@ class Controller_Task_Host extends Controller_Task {
if ($result->loaded())
$this->verify('c',$result);
print_r($result);
echo (string)$result->_object;
}
/**
@@ -83,7 +84,7 @@ class Controller_Task_Host extends Controller_Task {
if ($result->loaded())
$this->verify('d',$result);
print_r($result);
echo (string)$result->_object;
}
/**
@@ -95,16 +96,16 @@ class Controller_Task_Host extends Controller_Task {
#if ($result->loaded())
# $this->verify('d',$result);
print_r($result);
echo (string)$result->_object;
}
/**
* Get Reseller
* Get Reseller
*/
public function action_getreseller() {
$result = $this->hpo->cmd_getreseller($this->so);
print_r($result);
echo (string)$result->_object;
}
/**
@@ -113,7 +114,97 @@ class Controller_Task_Host extends Controller_Task {
public function action_gettraffic() {
$result = $this->hpo->cmd_gettraffic($this->so);
print_r($result);
echo (string)$result->_object;
}
public function action_migrate() {
if (! preg_match('/^[0-9]+:[0-9]+-[0-9]+$/',$ids=$this->request->param('id')))
throw new Kohana_Exception('Need to specify 2 site for a service to migrate, ie: svc:a-b');
list($sid,$svrs) = preg_split('/:/',$ids,2);
list($fsid,$tsid) = preg_split('/-/',$svrs,2);
$so = ORM::factory('service',$sid);
if (! $so->loaded())
throw new Kohana_Exception('Service :sid doesnt exist?',array(':sid'=>$sid));
printf("Migrate: %s\n",$so->plugin()->name());
// Validation, make sure the target is as configured
if ($so->plugin()->host_server_id != $tsid)
throw new Kohana_Exception('Service :sid is defined to server :tsid?',array(':sid'=>$sid,':tsid'=>$tsid));
// Validation, make sure the target is defined
$domain = clone $this->hpo->cmd_getdomain($this->so);
if (! $domain->loaded())
throw new Kohana_Exception('Service :sid is not on server :tsid?',array(':sid'=>$sid,':tsid'=>$tsid));
// Temporarily set our host_server_id to $fsid
$hpo = ORM::factory('host_server',$fsid);
if (! $hpo->loaded())
throw new Kohana_Exception('Host server :fsid not defined?',array(':fsid'=>$fsid));
$result = $hpo->plugin()->cmd_getdns($this->so);
// During migration we are only interested in the data.
$k = array(
'host_plugin_plesk_10'=>array('type','host','value','opt'), // From PLESK 9.
);
$t = array(
'host_plugin_plesk_10'=>array('domain_id'=>array('site-id'=>'id')), // From PLESK 9.
);
$f = array(
'host_plugin_plesk_10'=>array('host'=>'NODOMAIN','value'=>'NOTRAILDOT'),
);
$dns = $this->hpo->newitem($this->so,'dns');
foreach ($result->_object->get('result',FALSE) as $key => $o) {
$rec = $o->data->collapse();
$add = $dns->add_node('add_rec');
// Translate old values to new ones.
foreach ($t[strtolower(get_class($this->hpo))] as $a=>$b) {
if (isset($rec[$a])) {
unset($rec[$a]);
foreach ($b as $c=>$d) {
$add->add_node($c,$domain->$d->value());
}
}
}
// Import the values we are interested in
foreach ($k[strtolower(get_class($this->hpo))] as $a=>$b)
if (isset($rec[$b])) {
if (isset($f[strtolower(get_class($this->hpo))][$b])) {
switch ($f[strtolower(get_class($this->hpo))][$b]) {
case 'NODOMAIN':
$rec[$b] = preg_replace('/.?'.$so->plugin()->name().'.$/i','',$rec[$b]);
break;
case 'NOTRAILDOT':
$rec[$b] = preg_replace('/.$/','',$rec[$b]);
break;
default:
throw new Kohana_Exception('Unknown filter action :filter',array(':filter'=>$f[strtolower(get_class($this->hpo))][$b]));
}
}
$add->add_node($b,$rec[$b]);
}
}
printf("DNS: %s\n",(string)$dns);
$result = $this->hpo->add_dnsdata($this->so,$dns);
echo (string)$result->_object;
}
/**