Added Deploy method for Container class

feature/node-rewrite
Sven Slootweg 13 years ago
parent 8b854b7385
commit 027f20c53d

@ -22,7 +22,8 @@ class Container extends CPHPDatabaseRecordClass
public $prototype = array(
'string' => array(
'Hostname' => "Hostname",
'InternalId' => "InternalId"
'InternalId' => "InternalId",
'RootPassword' => "RootPassword"
),
'numeric' => array(
'NodeId' => "NodeId",
@ -30,7 +31,8 @@ class Container extends CPHPDatabaseRecordClass
'VirtualizationType' => "VirtualizationType",
'DiskSpace' => "DiskSpace",
'GuaranteedRam' => "GuaranteedRam",
'BurstableRam' => "BurstableRam"
'BurstableRam' => "BurstableRam",
'CpuCount' => "CpuCount"
),
'node' => array(
'Node' => "NodeId"
@ -39,6 +41,77 @@ class Container extends CPHPDatabaseRecordClass
'Template' => "TemplateId"
)
);
public function Deploy()
{
$sGuaranteedRamPages = $this->sGuaranteedRam * 256;
$sBurstableRamPages = $this->sBurstableRam * 256;
$sRootPassword = random_string(20);
$this->uRootPassword = $sRootPassword;
$this->InsertIntoDatabase();
$command = shrink_command("vzctl create {$this->sInternalId}
--ostemplate {$this->sTemplate->sTemplateName}
");
$result = $this->sNode->ssh->RunCommand($command, false);
if($result->returncode == 0)
{
// TODO: set sensible values depending on container resource configuration
// http://wiki.openvz.org/UBC_consistency_check
$command = shrink_command("vzctl set {$this->sInternalId}
--onboot yes
--setmode restart
--hostname {$this->sHostname}
--nameserver 8.8.8.8
--nameserver 8.8.4.4
--numproc {$this->sCpuCount}
--vmguarpages {$sGuaranteedRamPages}:unlimited
--privvmpages {$sBurstableRamPages}:{$sBurstableRamPages}
--quotatime 0
--diskspace {$this->sDiskSpace}M:{$this->sDiskSpace}M
--userpasswd root:{$sRootPassword}
--kmemsize 14372700:14790164
--lockedpages 256:256
--shmpages 21504:21504
--physpages 0:unlimited
--oomguarpages 26112:unlimited
--numtcpsock 360:360
--numflock 188:206
--numpty 16:16
--numsiginfo 256:256
--tcpsndbuf 1720320:2703360
--tcprcvbuf 1720320:2703360
--othersockbuf 1126080:2097152
--dgramrcvbuf 262144:262144
--numothersock 360:360
--numfile 9312:9312
--dcachesize 3409920:3624960
--numiptent 128:128
--diskinodes 200000:220000
--avnumproc 180:180
--save
");
$result = $this->sNode->ssh->RunCommand($command, false);
if($result->returncode == 0)
{
return true;
}
else
{
// TODO: Throw exception for failed container configuration
}
}
else
{
// TODO: throw exception for failed container creation
}
}
}
?>

@ -16,4 +16,11 @@ function split_whitespace($input)
return preg_split("/\s+/", $input);
}
function shrink_command($command)
{
$command = preg_replace("/(\t+|\n)/", " ", $command);
$command = str_replace("/r", "", $command);
return $command;
}
?>

@ -16,6 +16,8 @@ $settings['master_pubkey'] = "/etc/cvm/key.pub";
var_dump($sNode->sDiskFree, $sNode->sDiskUsed, $sNode->sRealHostname);*/
$sContainer = new Container(1);
$sContainer->Deploy();
// returncode 127 = failed (CT ID missing?)
pretty_dump($sContainer);
?>

Loading…
Cancel
Save