Manage AlternC's virtual machine (Containers) start/stop using our own inetd-based protocol.
More...
|
| m_lxc () |
| Constructor, initialize the class informations from AlternC's variables. More...
|
|
| hook_menu () |
| HOOK: add the "Console Access" to AlternC's main menu. More...
|
|
| hook_admin_del_member () |
| HOOK: remove VM history for AlternC account. More...
|
|
| start ($login=FALSE, $pass=FALSE, $uid=FALSE) |
| START a Virtual Machine on the remote VM manager for user $login having hashed password $pass and uid $uid. More...
|
|
| getvm ($login=FALSE) |
|
| stop () |
| Stop the currently running VM. More...
|
|
| start () |
|
|
| sendMessage ($params) |
| Send a message to a remote VM manager instance $params are the parameters to send as serialized data to the listening server. More...
|
|
Manage AlternC's virtual machine (Containers) start/stop using our own inetd-based protocol.
- Copyright
- AlternC-Team 2000-2017 https://alternc.com/
Definition at line 28 of file m_lxc.php.
◆ getvm()
m_lxc::getvm |
( |
|
$login = FALSE | ) |
|
Definition at line 165 of file m_lxc.php.
169 $message = array(
'action' =>
'get',
'login' =>
$login);
174 return unserialize(
$res);
sendMessage($params)
Send a message to a remote VM manager instance $params are the parameters to send as serialized data ...
References $login, $mem, $res, and sendMessage().
Referenced by start(), and stop().
◆ hook_admin_del_member()
m_lxc::hook_admin_del_member |
( |
| ) |
|
HOOK: remove VM history for AlternC account.
Definition at line 69 of file m_lxc.php.
71 $msg->log(
"lxc",
"alternc_del_member");
72 $db->query(
"DELETE FROM vm_history WHERE uid= ?", array(
$cuid));
References $cuid, $db, and $msg.
◆ hook_menu()
HOOK: add the "Console Access" to AlternC's main menu.
Definition at line 52 of file m_lxc.php.
57 'title' => _(
"Console access"),
◆ m_lxc()
Constructor, initialize the class informations from AlternC's variables.
Definition at line 41 of file m_lxc.php.
42 $this->IP =
variable_get(
'lxc_ip',
'',
"IP address of the Alternc's LXC server. If empty, no LXC server.", array(
'desc' =>
'IP address',
'type' =>
'ip'));
43 $this->PORT =
variable_get(
'lxc_port',
'6504',
"Port of the Alternc's LXC server", array(
'desc' =>
'Port',
'type' =>
'integer'));
44 $this->KEY =
variable_get(
'lxc_key',
'',
"Shared key with the Alternc's LXC server", array(
'desc' =>
'Shared key',
'type' =>
'string'));
45 $this->maxtime =
variable_get(
'lxc_maxtime',
'4',
"How many hours do we allow to have a server before shutting it down", array(
'desc' =>
'Max time',
'type' =>
'integer'));
variable_get($name, $default=null, $createit_comment=null)
Return a persistent variable.
References variable_get().
◆ sendMessage()
m_lxc::sendMessage |
( |
|
$params | ) |
|
|
private |
Send a message to a remote VM manager instance $params are the parameters to send as serialized data to the listening server.
Return the unserialized response data, if the message has been sent successfully or FALSE if an error occurred. In that case $error[] is set.
Definition at line 84 of file m_lxc.php.
86 $fp = @fsockopen($this->IP, $this->PORT, $errno,
$errstr, $this->TIMEOUT);
88 $this->error[] =
'Unable to connect';
92 $params[
'server'] = $L_FQDN;
95 $moreparams =
$hooks->invoke(
"lxc_params", array($params));
96 foreach ($moreparams as
$p) {
97 foreach (
$p as $k => $v) {
102 $message = serialize($params);
103 if (fwrite($fp, $message .
"\n") < 0) {
104 $this->error[] =
'Unable to send data';
107 $resp = fgets($fp, 8192);
110 $data = @unserialize($resp);
112 if (isset($data[
'error']) && $data[
'error'] > 0) {
113 $this->error[] = $data[
'msg'];
References $errstr, $hooks, $KEY, and $p.
Referenced by getvm(), start(), and stop().
◆ start() [1/2]
m_lxc::start |
( |
|
$login = FALSE , |
|
|
|
$pass = FALSE , |
|
|
|
$uid = FALSE |
|
) |
| |
START a Virtual Machine on the remote VM manager for user $login having hashed password $pass and uid $uid.
Definition at line 125 of file m_lxc.php.
128 if ($this->
getvm() !== FALSE) {
129 $msg->raise(
"ERROR",
'lxc', _(
'VM already started'));
135 $pass = $pass ? $pass :
$mem->user[
'pass'];
138 $message = array(
'action' =>
'start',
'login' =>
$login,
'pass' => $pass,
'uid' =>
$uid);
139 $message[
'mysql_host'] = $mysql->dbus->Host;
142 if (
$res === FALSE) {
145 $data = unserialize(
$res);
146 $error = (int) $data[
'error'];
147 $hostname = $data[
'hostname'];
148 $message = $data[
'msg'];
149 $date_start =
'NOW()';
153 $msg->raise(
"ERROR",
'lxc', _($message));
156 $db->query(
"INSERT INTO vm_history (ip,date_start,uid,serialized_object) VALUES (?, ?, ?, ?);", array($hostname, $date_start,
$uid,
$res));
References $db, $error, $login, $mem, $msg, $res, $uid, getvm(), and sendMessage().
◆ start() [2/2]
◆ stop()
◆ $error
◆ $IP
◆ $KEY
◆ $maxtime
◆ $PORT
◆ $TIMEOUT
The documentation for this class was generated from the following file: