Skip to content

Commit

Permalink
Allow to specify number of cpus of the virtual machines
Browse files Browse the repository at this point in the history
  • Loading branch information
jacalvo committed Sep 29, 2015
1 parent 79514eb commit b57e0cd
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 9 deletions.
1 change: 1 addition & 0 deletions ChangeLog
@@ -1,4 +1,5 @@
HEAD
+ Allow to specify number of cpus of the virtual machines
+ Show test type in console output
+ Added anste-snapshot tool
+ Add -jump-to option similar to -reuse but starting directly from
Expand Down
1 change: 1 addition & 0 deletions data/images/test.yaml
@@ -1,6 +1,7 @@
name: imageName
desc: imageDesc
memory: imageMemory
cpus: imageCpus
swap: imageSwap
arch: imageArch
size: imageSize
Expand Down
5 changes: 5 additions & 0 deletions src/ANSTE/Deploy/HostDeployer.pm
Expand Up @@ -81,10 +81,15 @@ sub new
if (not $memory) {
$memory = $host->baseImage()->memory();
}
my $cpus = $host->cpus();
if (not $cpus) {
$cpus = $host->baseImage()->cpus();
}
my $swap = $host->baseImage()->swap();
my $image = new ANSTE::Image::Image(name => $hostname,
memory => $memory,
swap => $swap,
cpus => $cpus,
ip => $ip);
$image->setNetwork($host->network());

Expand Down
2 changes: 2 additions & 0 deletions src/ANSTE/Image/Commands.pm
Expand Up @@ -116,6 +116,7 @@ sub create
my $ip = $self->ip();
my $memory = $image->memory();
my $swap = $image->swap();
my $cpus = $image->cpus();
my $method = $image->installMethod();
my $source = $image->installSource();
my $dist = $image->installDist();
Expand All @@ -128,6 +129,7 @@ sub create
ip => $ip,
memory => $memory,
swap => $swap,
cpus => $cpus,
method => $method,
source => $source,
dist => $dist,
Expand Down
4 changes: 4 additions & 0 deletions src/ANSTE/Image/Image.pm
Expand Up @@ -39,6 +39,7 @@ use ANSTE::Exceptions::MissingArgument;
# name - *optional* String with the image hostname.
# ip - *optional* String with the image IP address.
# memory - *optional* String with the image memory size.
# cpus - *optional* String with the image cpus number.
# swap - *optional* String with the swap partition size.
#
# Returns:
Expand All @@ -60,6 +61,9 @@ sub new # returns new Image object
if (exists $params{memory}) {
$self->{memory} = $params{memory};
}
if (exists $params{cpus}) {
$self->{cpus} = $params{cpus};
}
if (exists $params{swap}) {
$self->{swap} = $params{swap};
}
Expand Down
9 changes: 7 additions & 2 deletions src/ANSTE/Image/t/Image.t
Expand Up @@ -18,18 +18,23 @@ use warnings;

use ANSTE::Image::Image;

use Test::More tests => 5;
use Test::More tests => 7;

my $image = new ANSTE::Image::Image(name => 'Name',
ip => '192.168.0.150',
memory => '256M');
memory => '256M',
cpus => 2);

is($image->name(), 'Name', 'image->name == Name');
is($image->ip(), '192.168.0.150', 'image->ip == 192.168.0.150');
is($image->memory(), '256M', 'image->memory == 256M');
is($image->cpus(), '2', 'image->cpus == 2');

$image->setIp('192.168.0.160');
is($image->ip(), '192.168.0.160', 'image set new ip');

$image->setMemory('512M');
is($image->memory(), '512M', 'image set new memory');

$image->setCpus('4');
is($image->cpus(), '4', 'image set cpus');
50 changes: 46 additions & 4 deletions src/ANSTE/Scenario/BaseImage.pm
Expand Up @@ -180,6 +180,43 @@ sub setMemory
$self->{memory} = $memory;
}

# Method: cpus
#
# Gets the number of CPUs
#
# Returns:
#
# string - contains the number of CPUs
#
sub cpus
{
my ($self) = shift;

return $self->{cpus};
}

# Method: setCpus
#
# Sets the number of CPUs
#
# Parameters:
#
# cpus - String with the number of CPUs
#
# Exceptions:
#
# <ANSTE::Exceptions::MissingArgument> - throw if argument is not present
#
sub setCpus
{
my ($self, $cpus) = @_;

defined $cpus or
throw ANSTE::Exceptions::MissingArgument('cpus');

$self->{cpus} = $cpus;
}

# Method: size
#
# Gets the size of the image.
Expand Down Expand Up @@ -702,20 +739,26 @@ sub _loadFromYAML
my $desc = $image->{desc};
$self->setDesc($desc);

my $memory= $image->{memory};
my $memory = $image->{memory};
if ($memory) {
$self->setMemory($memory);
}

my $cpus = $image->{cpus};
unless ($cpus) {
$cpus = 1;
}
$self->setCpus($cpus);

my $size = $image->{size};
$self->setSize($size);

my $arch= $image->{arch};
my $arch = $image->{arch};
if ($arch) {
$self->setArch($arch);
}

my $swap= $image->{swap};
my $swap = $image->{swap};
if ($swap) {
$self->setSwap($swap);
}
Expand Down Expand Up @@ -775,7 +818,6 @@ sub _loadFromYAML
if ($files) {
$self->files()->loadYAML($files);
}

}

sub _addScriptsFromYAML
Expand Down
43 changes: 43 additions & 0 deletions src/ANSTE/Scenario/Host.pm
Expand Up @@ -208,6 +208,44 @@ sub setMemory
$self->{memory} = $memory;
}

# Method: cpus
#
# Gets the number of CPUs
#
# Returns:
#
# string - contains the number of CPUs
#
sub cpus
{
my ($self) = shift;

return $self->{cpus};
}

# Method: setCpus
#
# Sets the number of CPUs
#
# Parameters:
#
# cpus - String with the number of CPUs
#
# Exceptions:
#
# <ANSTE::Exceptions::MissingArgument> - throw if argument is not present
#
sub setCpus
{
my ($self, $cpus) = @_;

defined $cpus or
throw ANSTE::Exceptions::MissingArgument('cpus');

$self->{cpus} = $cpus;
}


# Method: baseImage
#
# Gets the object with the information of the base image of the host.
Expand Down Expand Up @@ -555,6 +593,11 @@ sub loadYAML
$self->setMemory($memory);
}

my $cpus = $host->{cpus};
if ($cpus) {
$self->setCpus($cpus);
}

my $network = $host->{network};
if ($network) {
$self->network()->loadYAML($network);
Expand Down
4 changes: 3 additions & 1 deletion src/ANSTE/Scenario/t/LoadImage.t
Expand Up @@ -19,7 +19,7 @@ use warnings;
use ANSTE::Scenario::BaseImage;
use ANSTE::Config;

use Test::More tests => 27;
use Test::More tests => 28;

sub testImage # (image)
{
Expand All @@ -37,6 +37,8 @@ sub testImage # (image)
is($arch, 'imageArch', 'image arch = imageArch');
my $swap = $image->swap();
is($swap, 'imageSwap', 'image swap = imageSwap');
my $cpus = $image->cpus();
is($cpus, 'imageCpus', 'image cpus = imageCpus');

my $installMethod = $image->installMethod();
is($installMethod, 'copy', 'image installMethod = copy');
Expand Down
4 changes: 3 additions & 1 deletion src/ANSTE/Scenario/t/Scenario.t
Expand Up @@ -19,7 +19,7 @@ use warnings;
use ANSTE::Scenario::Scenario;
use ANSTE::Config;

use Test::More tests => 54;
use Test::More tests => 55;

use constant SCENARIO => 'test.yaml';

Expand Down Expand Up @@ -94,6 +94,8 @@ sub testBaseImage # (image)
is($desc, 'imageDesc', 'desc = imageDesc');
my $memory = $image->memory();
is($memory, 'imageMemory', 'memory = imageMemory');
my $cpus = $image->cpus();
is($cpus, 'imageCpus', 'cpus = imageCpus');
my $size = $image->size();
is($size, 'imageSize', 'size = imageSize');
my $method = $image->installMethod();
Expand Down
3 changes: 2 additions & 1 deletion src/ANSTE/Virtualizer/Virt.pm
Expand Up @@ -799,6 +799,7 @@ sub _createImageConfig
my $config = ANSTE::Config->instance();
my $name = $image->name();
my $memory = $image->memory() * 1024;
my $vcpu = $image->cpus();
my $arch = `arch`;
chomp ($arch);

Expand All @@ -807,7 +808,7 @@ sub _createImageConfig
my $imageConfig = "<domain type='kvm'>\n";
$imageConfig .= "\t<name>$name</name>\n";
$imageConfig .= "\t<memory>$memory</memory>\n";
$imageConfig .= "\t<vcpu>1</vcpu>\n";
$imageConfig .= "\t<vcpu>$vcpu</vcpu>\n";
$imageConfig .= "\t<os><type arch='$arch'>hvm</type></os>\n";
$imageConfig .= "\t<features><acpi/></features>\n";
$imageConfig .= "\t<clock sync='localtime'/>\n";
Expand Down

0 comments on commit b57e0cd

Please sign in to comment.