From 36bb121df9f8bc76d81341586b61f41a8f85814c Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sun, 29 Apr 2012 07:34:56 +0200 Subject: [PATCH] Node class and test --- frontend/classes/class.node.php | 27 ++++++++++++++++++++++++-- frontend/cphp/class.databaserecord.php | 2 +- frontend/test.php | 10 ++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/frontend/classes/class.node.php b/frontend/classes/class.node.php index ae262a5..9b40043 100644 --- a/frontend/classes/class.node.php +++ b/frontend/classes/class.node.php @@ -24,7 +24,8 @@ class Node extends CPHPDatabaseRecordClass 'Name' => "Name", 'Hostname' => "Hostname", 'PrivateKey' => "CustomPrivateKey", - 'PublicKey' => "CustomPublicKey" + 'PublicKey' => "CustomPublicKey", + 'User' => "User" ), 'numeric' => array( 'Port' => "Port" @@ -36,7 +37,29 @@ class Node extends CPHPDatabaseRecordClass public $ssh = null; - public function GetNodes() + protected function EventConstructed() + { + global $settings; + + $this->ssh = new SshConnector(); + + $this->ssh->host = $this->sHostname; + $this->ssh->port = $this->sPort; + $this->ssh->user = $this->sUser; + + if($this->HasCustomKey === true) + { + $this->ssh->key = $this->sPrivateKey; + $this->ssh->pubkey = $this->sPublicKey; + } + else + { + $this->ssh->key = $settings['master_privkey']; + $this->ssh->pubkey = $settings['master_pubkey']; + } + } + + public function GetContainers() { var_dump($this->ssh->RunCommand("vzlist -a")); } diff --git a/frontend/cphp/class.databaserecord.php b/frontend/cphp/class.databaserecord.php index cc9c82b..fdbacef 100644 --- a/frontend/cphp/class.databaserecord.php +++ b/frontend/cphp/class.databaserecord.php @@ -398,5 +398,5 @@ abstract class CPHPDatabaseRecordClass extends CPHPBaseClass // Define events - public function EventConstructed() { } + protected function EventConstructed() { } } diff --git a/frontend/test.php b/frontend/test.php index dc4f048..eb8a076 100644 --- a/frontend/test.php +++ b/frontend/test.php @@ -2,10 +2,16 @@ $_CVM = true; require("includes/include.base.php"); -$ssh = new SshConnector(); +/*$ssh = new SshConnector(); $ssh->host = "cvm-vz.cryto.net"; $ssh->key = "/etc/cvm/key"; $ssh->pubkey = "/etc/cvm/key.pub"; -var_dump($ssh->RunCommand("df -h", true)); +var_dump($ssh->RunCommand("df -h", true));*/ + +$settings['master_privkey'] = "/etc/cvm/key"; +$settings['master_pubkey'] = "/etc/cvm/key.pub"; + +$sNode = new Node(1); +var_dump($sNode->GetContainers()); ?>