Changeset 262 in ProjectBuilder for devel/pb/bin


Ignore:
Timestamp:
Oct 27, 2007, 2:18:22 AM (16 years ago)
Author:
Bruno Cornec
Message:

Fix bug #7 where .pbrc nearly empty wasn't working

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r239 r262  
    4444my $pbport;                 # Port to use to connect to the VM
    4545my $newver;                 # New version to create
     46my $iso;                    # ISO iage for the VM to create
    4647my $LOG = \*STDOUT;
    4748
    48 getopts('a:hl:m:P:p:qr:s:tvV:',\%opts);
     49getopts('a:hi:l:m:P:p:qr:s:tvV:',\%opts);
    4950
    5051my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
     
    9091if (defined $opts{'V'}) {
    9192    $newver = $opts{'V'};
     93}
     94if (defined $opts{'i'}) {
     95    $iso = $opts{'i'};
    9296}
    9397
     
    136140    pb_build2vm();
    137141} elsif ($action =~ /^launchvm$/) {
    138     pb_launchvm($ENV{'PBVM'});
     142    pb_launchvm($ENV{'PBVM'},0);
    139143} elsif ($action =~ /^script2vm$/) {
    140144    pb_script2vm($pbscript);
    141145} elsif ($action =~ /^newver$/) {
    142146    pb_newver();
     147} elsif ($action =~ /^newvm$/) {
     148    pb_launchvm($ENV{'PBVM'},1);
    143149} elsif ($action =~ /^clean$/) {
    144150} else {
     
    600606    foreach my $v (@$vm) {
    601607        # Launch the VM
    602         my ($vmexist,$vmpid) = pb_launchvm($v);
     608        my ($vmexist,$vmpid) = pb_launchvm($v,0);
    603609
    604610        # Gather all required files to send them to the VM
     
    611617sub pb_launchvm {
    612618    my $vm = shift;
    613 
     619    my $create = shift || 0;        # By default do not create a VM
     620
     621    die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
    614622    die "No VM defined, unable to launch" if (not defined $vm);
    615623    # Keep only the first VM in case many were given
     
    617625
    618626    # Launch the VMs
    619     my ($ptr,$vmopt,$vmport,$vmpath,$vmtmout) = pb_conf_get("vmtype","vmopt","vmport","vmpath","vmtmout");
     627    my ($ptr,$vmopt,$vmport,$vmpath,$vmtmout,$vmsize) = pb_conf_get("vmtype","vmopt","vmport","vmpath","vmtmout","vmsize");
    620628    my $vmtype = $ptr->{$ENV{'PBPROJ'}};
     629    if (not defined $ENV{'PBVMOPT'}) {
     630        $ENV{'PBVMOPT'} = "";
     631    }
    621632    if (defined $vmopt->{$ENV{'PBPROJ'}}) {
    622         $ENV{'PBVMOPT'} = $vmopt->{$ENV{'PBPROJ'}};
    623     } else {
    624         $ENV{'PBVMOPT'} = "";
     633        $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}";
    625634    }
    626635    my $nport = $vmport->{$ENV{'PBPROJ'}};
     
    648657        }
    649658        $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$vm.qemu";
    650         if (! -f "$vmm") {
    651             die "Unable to find VM $vmm";
     659        if ($create != 0) {
     660            $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
    652661        }
    653662        $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm"
     
    661670    my $vmpid = 0;
    662671    if (! $vmexist) {
     672        if ($create != 0) {
     673            pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
     674        }
     675        if (! -f "$vmm") {
     676            die "Unable to find VM $vmm";
     677        }
    663678        pb_system("$cmd &","Launching the VM $vmm");
    664679        pb_system("sleep $vmtmout->{$ENV{'PBPROJ'}}","Waiting for VM $vm to come up");
     
    708723    foreach my $v (@$vm) {
    709724        # Launch the VM
    710         my ($vmexist,$vmpid) = pb_launchvm($v);
     725        my ($vmexist,$vmpid) = pb_launchvm($v,0);
    711726
    712727        # Gather all required files to send them to the VM
     
    715730    }
    716731}
     732
    717733
    718734sub pb_newver {
     
    888904    print "\t           and executes a script on it                 \n";
    889905    print "\n";
    890     print "\tnewver:    Create a new version of the project derived \n";
    891     print "\t           from the current one                        \n";
    892     print "\n";
    893 }
     906    print "\tnewvm:     Create a new virtual machine\n";
     907    print "\n";
     908    print "\tnewver:    Create a new version of the project derived \n";
     909    print "\t           from the current one                        \n";
     910    print "\n";
     911}
Note: See TracChangeset for help on using the changeset viewer.