diff --git a/frontend/classes/class.node.php b/frontend/classes/class.node.php index 9b40043..5ca3633 100644 --- a/frontend/classes/class.node.php +++ b/frontend/classes/class.node.php @@ -59,9 +59,22 @@ class Node extends CPHPDatabaseRecordClass } } - public function GetContainers() + public function __get($name) { - var_dump($this->ssh->RunCommand("vzlist -a")); + switch($name) + { + case "sRealHostname": + return $this->GetHostname(); + break; + default: + return null; + break; + } + } + + public function GetHostname() + { + return $this->ssh->RunCommandCached("hostname")->stdout; } } diff --git a/frontend/classes/class.sshconnector.php b/frontend/classes/class.sshconnector.php index da38445..b9114a9 100644 --- a/frontend/classes/class.sshconnector.php +++ b/frontend/classes/class.sshconnector.php @@ -28,6 +28,8 @@ class SshConnector extends CPHPBaseClass public $helper = "~/runhelper"; + private $cache = ""; + public function RunCommand($command, $throw_exception) { try @@ -54,6 +56,20 @@ class SshConnector extends CPHPBaseClass } } + public function RunCommandCached($command, $throw_exception) + { + if(!isset($this->cache[$command])) + { + $result = $this->RunCommand($command, $throw_exception); + $this->cache[$command] = $result; + return $result; + } + else + { + return $this->cache[$command]; + } + } + public function Connect() { $options = array( diff --git a/frontend/test.php b/frontend/test.php index eb8a076..7da11e5 100644 --- a/frontend/test.php +++ b/frontend/test.php @@ -13,5 +13,10 @@ $settings['master_privkey'] = "/etc/cvm/key"; $settings['master_pubkey'] = "/etc/cvm/key.pub"; $sNode = new Node(1); -var_dump($sNode->GetContainers()); +var_dump($sNode->sRealHostname); +var_dump($sNode->sRealHostname); +var_dump($sNode->sRealHostname); +var_dump($sNode->sRealHostname); +var_dump($sNode->sRealHostname); +var_dump($sNode->sRealHostname); ?>