Commit 2744a722 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

[#8] enforce minimal disk and memory size on creation

parent a582b061
......@@ -53,7 +53,7 @@ has 'readonly' => (
# Method Modifiers
#
#
before 'create_domain' => \&_check_readonly;
before 'create_domain' => \&_check_create_domain;
sub _check_readonly {
my $self = shift;
......@@ -159,4 +159,30 @@ sub ip {
return '127.0.0.1';
}
sub _check_memory {
my $self = shift;
my %args = @_;
return if !exists $args{memory};
die "ERROR: Low memory '$args{memory}' required 128 Mb " if $args{memory} < 128*1024;
}
sub _check_disk {
my $self = shift;
my %args = @_;
return if !exists $args{disk};
die "ERROR: Low Disk '$args{disk}' required 1 Gb " if $args{disk} < 1024*1024;
}
sub _check_create_domain {
my $self = shift;
$self->_check_readonly(@_);
$self->_check_memory(@_);
$self->_check_disk(@_);
}
1;
......@@ -245,6 +245,8 @@ sub create_volume {
if ($size) {
my ($prev_size) = $doc->findnodes('/volume/capacity/text()')->[0]->getData();
confess "Size '$size' too small" if $size < 1024*512;
warn "Creating a disk ".int($prev_size/(1024*1024*1024))." -> ".int($size/(1024*1024*1024));
$doc->findnodes('/volume/allocation/text()')->[0]->setData(int($size*0.9));
$doc->findnodes('/volume/capacity/text()')->[0]->setData($size);
}
......
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