Commit c4c9edc0 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

New base now works

parent 58d30b75
......@@ -6,7 +6,6 @@
<vcpu placement='static'>1</vcpu>
<os>
<type arch='i686' machine='pc-i440fx-trusty'>hvm</type>
<boot dev='hd'/>
</os>
<features>
<acpi/>
......@@ -24,6 +23,7 @@
<source file='/var/lib/libvirt/images/trusty.img'/>
<target dev='vda' bus='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
<boot order='1'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
......@@ -31,6 +31,7 @@
<target dev='hdc' bus='ide'/>
<readonly/>
<address type='drive' controller='0' bus='1' target='0' unit='0'/>
<boot order='2'/>
</disk>
<controller type='usb' index='0'>
<address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
......
......@@ -7,7 +7,7 @@
<allocation unit='bytes'>5395775488</allocation>
<target>
<path>/var/lib/libvirt/images/__name__.img</path>
<format type='raw'/>
<format type='qcow2'/>
<permissions>
<mode>0600</mode>
<owner>0</owner>
......
......@@ -26,10 +26,12 @@ if ($help) {
exit;
}
our $CONFIG = { rvd_back => {pid_file => '/var/run/rvd_back.pid'}};
$CONFIG = LoadFile($FILE_CONFIG) or die "$! $FILE_CONFIG"
my $CONFIG = LoadFile($FILE_CONFIG) or die "$! $FILE_CONFIG"
if -e $FILE_CONFIG;
$CONFIG->{rvd_back}->{pid_file} = '/var/run/rvd_back.pid'
if !$CONFIG->{rvd_back}->{pid_file};
our $DB;
our $TIMEOUT = 120;
......@@ -151,14 +153,14 @@ any '/bases' => sub {
sub new_base {
my $c = shift;
my @error = ();
my $name = $c->param('name');
my $ram = ($c->param('ram') or 2);
my $disk = ($c->param('disk') or 8);
if ($c->param('submit')) {
push @error,("Name is mandatory") if !defined $name;
push @error,("Name is mandatory") if !$c->param('name');
return req_new_base($c) if !@error;
}
$c->render(template => 'bootstrap/new_base'
,name => $name
,name => $c->param('name')
,ram => $ram
,disk => $disk
,image => _list_images()
......@@ -166,7 +168,33 @@ sub new_base {
);
};
sub req_new_base {
my $c = shift;
my $sth = $DB->dbh->prepare(
"INSERT INTO bases_req (name, id_iso, date_req, created) "
." VALUES (?,?,now(),'n')"
);
$sth->execute($c->param('name'), $c->param('id_iso'));
$sth->finish;
$sth=$DB->dbh->prepare("SELECT last_insert_id() ");
$sth->execute;
my ($id) = $sth->fetchrow;
my ($uri,$error) = wait_req_up($id);
if ($uri) {
$c->redirect_to($uri);
$c->render(template => 'bootstrap/run', url => $uri , name => $c->param('name')
,login => $c->session('login'));
} else {
$c->render(template => 'fail', name => $c->param('name'), error => $error);
}
}
sub _search_req_base_error {
my $name = shift;
}
sub access_denied {
my $c = shift;
$c->render(data => "Access denied");
......@@ -210,11 +238,12 @@ sub provisiona {
}
sub wait_node_up {
my ($c, $name) = @_;
my ($c, $name, $table) = @_;
$table = 'domains' if !$table;
my $dbh = $DB->dbh;
my $sth = $dbh->prepare(
"SELECT created, error, uri FROM domains where name=?"
"SELECT created, error, uri FROM $table where name=?"
);
for (1 .. $TIMEOUT) {
......@@ -230,6 +259,26 @@ sub wait_node_up {
}
}
sub wait_req_up {
my ($id, $table) = @_;
$table = 'bases_req' if !$table;
my $dbh = $DB->dbh;
my $sth = $dbh->prepare(
"SELECT created, error, uri FROM $table where id=?"
);
for (1 .. $TIMEOUT) {
sleep 1;
$sth->execute($id);
my ($created, $error, $uri ) = $sth->fetchrow;
warn "$_ : ".$created." ".($error or '');
return ($uri) if $created !~ /n/i;
return (undef,$error) if $error;
}
}
sub raise_node {
my ($c, $id_base, $name) = @_;
......
CREATE TABLE `bases_req` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL,
`date_req` datetime DEFAULT NULL,
`date_changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`created` char(1) DEFAULT NULL,
`error` varchar(255) DEFAULT NULL,
`id_iso` int(11) NOT NULL,
`uri` varchar(255),
PRIMARY KEY (`id`)
);
......@@ -10,7 +10,7 @@
<form method="post">
<input type="text" size="20" name="name" value="<%= $name %>"><br/>
% if (keys %$image) {
boot CD: <select name="id_image">
boot CD: <select name="id_iso">
% for my $option (sort keys %$image) {
<option value="<%= $option %>"><%= $image->{$option}->{name} %></option>
% }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment