Implemented command cacheing

feature/node-rewrite
Sven Slootweg 13 years ago
parent 36bb121df9
commit fa2e12afc6

@ -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;
} }
} }

@ -28,6 +28,8 @@ class SshConnector extends CPHPBaseClass
public $helper = "~/runhelper"; public $helper = "~/runhelper";
private $cache = "";
public function RunCommand($command, $throw_exception) public function RunCommand($command, $throw_exception)
{ {
try 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() public function Connect()
{ {
$options = array( $options = array(

@ -13,5 +13,10 @@ $settings['master_privkey'] = "/etc/cvm/key";
$settings['master_pubkey'] = "/etc/cvm/key.pub"; $settings['master_pubkey'] = "/etc/cvm/key.pub";
$sNode = new Node(1); $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);
?> ?>

Loading…
Cancel
Save