added configuration for the VM (in json format to keep it simple to have embedded arrays), and modified the running script to switch from hard coded conf to a sample one

This commit is contained in:
François Serman 2013-04-17 22:00:06 +00:00
parent c98cbe7f8a
commit d02fa25e6c
3 changed files with 106 additions and 0 deletions

2
.gitattributes vendored
View File

@ -456,6 +456,7 @@ debian/po/nl.po -text
debian/po/pt.po -text debian/po/pt.po -text
debian/po/templates.pot -text debian/po/templates.pot -text
debian/rules -text debian/rules -text
etc/alternc-lxc/vms.json -text
etc/alternc/alternc-sudoers -text etc/alternc/alternc-sudoers -text
etc/alternc/alternc.ini -text etc/alternc/alternc.ini -text
etc/alternc/apache2-ssl.conf -text etc/alternc/apache2-ssl.conf -text
@ -622,6 +623,7 @@ tests/mechdump.pm -text
tests/test_demo.pl -text tests/test_demo.pl -text
tests/whois_test.php -text tests/whois_test.php -text
tools/alternc_get_path -text tools/alternc_get_path -text
tools/alternc_lxc -text
tools/get_account_by_domain -text tools/get_account_by_domain -text
tools/get_domains_by_account -text tools/get_domains_by_account -text
tools/top_ftp_users -text tools/top_ftp_users -text

24
etc/alternc-lxc/vms.json Normal file
View File

@ -0,0 +1,24 @@
{
"vm1":{
"hostname":"vm1.test.fr",
"network":{
"eth0":{
"link":"brdummy",
"ip":"10.50.0.2\/24"
},
"eth1":{
"link":"brdummy2",
"ip":"10.55.0.2\/24"
}
}
},
"vm2":{
"hostname":"vm2.test.fr",
"network":{
"eth0":{
"link":"brdummy",
"ip":"10.51.0.2\/24"
}
}
}
}

80
tools/alternc_lxc Executable file
View File

@ -0,0 +1,80 @@
#!/usr/bin/php
<?php
require_once("/var/lib/alternc-lxc/alternc_lxc.class.php");
function help() {
echo "Actions:\n";
echo " * ".$_SERVER['SCRIPT_NAME']." start login password_hash UID\n";
echo " * ".$_SERVER['SCRIPT_NAME']." stop vm\n";
echo " * ".$_SERVER['SCRIPT_NAME']." stopall\n";
echo " * ".$_SERVER['SCRIPT_NAME']." monit\n";
echo " * ".$_SERVER['SCRIPT_NAME']." list\n";
echo " * ".$_SERVER['SCRIPT_NAME']." lock\n";
echo " * ".$_SERVER['SCRIPT_NAME']." unlock\n";
echo "\n";
}
# Must be launched as root
if (shell_exec("/usr/bin/id -u") != 0 ) {
echo "Script must be launch as root.\n";
die();
}
# There must be at least one parameters
if (empty($argv[1])) {
help();
die();
}
$filename = '/etc/alternc-lxc/vms.json';
$conf = json_decode(file_get_contents($filename), TRUE);
$lxc = new alternc_lxc();
$lxc->conf=$conf;
# Here we go
switch ($argv[1]) {
case "start":
if (empty($argv[2]) || empty($argv[3]) || empty($argv[4])) {
help();
die();
}
$r = $lxc->start_vm($argv[2], $argv[3], $argv[4]);
echo serialize($r);
break;
case "stopall":
$r=$lxc->stopall_vm();
echo serialize($r);
break;
case "stop":
if (empty($argv[2])) {
help();
die();
}
$r=$lxc->stop_vm($argv[2]);
echo serialize($r);
break;
case "unlock":
$r=$lxc->unlock();
echo serialize($r);
break;
case "lock":
$r=$lxc->lock();
echo serialize($r);
break;
case "monit":
$r=$lxc->monit();
echo serialize($r);
break;
case "list":
$r=$lxc->listvm();
echo "$r";
break;
default:
help();
die();
}
?>