Changeset 141


Ignore:
Timestamp:
Sep 13, 2007, 2:47:30 AM (12 years ago)
Author:
bruno
Message:

First completely good version for VM management

File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r140 r141  
    3434my $pbtag;                  # Global Tag variable
    3535my $pbver;                  # Global Version variable
     36my $pbscript;               # Name of the script
    3637my %pbver;                  # per package
    3738my %pbtag;                  # per package
     
    4344my $LOG = \*STDOUT;
    4445
    45 getopts('hl:m:p:qr:tv',\%opts);
     46getopts('hl:m:p:qr:s:tv',\%opts);
    4647
    4748my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
     
    7576if (defined $opts{'m'}) {
    7677    $ENV{'PBVM'} = $opts{'m'};
     78}
     79if (defined $opts{'s'}) {
     80    $pbscript = $opts{'s'};
    7781}
    7882
     
    117121    pb_cms2build();
    118122    pb_build2vm();
     123} elsif ($action =~ /^launchvm$/) {
     124    pb_launchvm();
    119125} elsif ($action =~ /^clean$/) {
    120126} else {
     
    456462        # Change pgben to make the next send2ssh happy
    457463        open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
    458         my $made = "";
    459464        foreach my $p (split(/ +/,$src)) {
    460465            my $j = basename($p);
    461466            pb_system("scp -p -P $port $mac:\'$bdir/$p\' $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Package recovery of $j in $tdir from $mac");
    462             $made = "$made $odir/$over/$j";
    463         }
    464         print KEEP "$made\n";
     467        }
     468        print KEEP "$odir/$over/*\n";
    465469        close(KEEP);
    466470        #pb_system("ssh -q -p $port $mac \"rm -rf dirname("$sshdir->{$ENV{'PBPROJ'}}"); sudo /usr/bin/poweroff\"","VM cleanup and halt on $mac");
    467471        pb_send2ssh("Packages","$odir"."_"."$over");
    468         #pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
    469     }
    470 }
    471 
     472        pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
     473    }
     474}
     475
     476sub launchvm {
     477    my ($vm,$all) = pb_get_vm();
     478
     479    # Prepare the script to be executed on the VM
     480    # in $ENV{'PBDESTDIR'}/pbscript
     481    copy($pbscript,"$ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
     482    chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
     483
     484    foreach my $v (@$vm) {
     485        # Launch the VMs
     486        my ($ptr,$vmopt,$vmport,$vmpath) = pb_conf_get("vmtype","vmopt","vmport","vmpath");
     487        my $vmtype = $ptr->{$ENV{'PBPROJ'}};
     488        if (defined $vmopt->{$ENV{'PBPROJ'}}) {
     489            $ENV{'PBVMOPT'} = $vmopt->{$ENV{'PBPROJ'}};
     490        } else {
     491            $ENV{'PBVMOPT'} = "";
     492        }
     493
     494        my $cmd;
     495        if ($vmtype eq "qemu") {
     496            my $arch = `uname -m`;
     497            chomp($arch);
     498            my $qemucmd;
     499            my $qemucmd32;
     500            my $qemucmd64;
     501            if ($arch eq "x86_64") {
     502                $qemucmd32 = "/usr/bin/qemu-system-i386";
     503                $qemucmd64 = "/usr/bin/qemu";
     504            } else {
     505                $qemucmd32 = "/usr/bin/qemu";
     506                $qemucmd64 = "/usr/bin/qemu-system-x86_64";
     507            }
     508            if ($v =~ /_64/) {
     509                $qemucmd = "$qemucmd64 -no-kqemu";
     510            } else {
     511                $qemucmd = "$qemucmd32";
     512            }
     513            if (! -f "$vmpath->{$ENV{'PBPROJ'}}/$v.qemu") {
     514                print "Unable to find VM $vmpath->{$ENV{'PBPROJ'}}/$v.qemu";
     515                next;
     516            }
     517            $cmd = "$qemucmd $ENV{'PBVMOPT'} -redir tcp:$vmport->{$ENV{'PBPROJ'}}:10.0.2.15:22 $vmpath->{$ENV{'PBPROJ'}}/$v.qemu"
     518        } elsif ($vmtype eq "xen") {
     519        } elsif ($vmtype eq "vmware") {
     520        } else {
     521            die "VM of type $vmtype not supported. Report to the dev team";
     522        }
     523        pb_system("$cmd &","Launching the VM");
     524        pb_system("sleep 300","Waiting for it to come up");
     525
     526        # Gather all required files to send them to the VM and launch the build thourgh pbscript
     527        pb_send2ssh("VMs","$v","vmhost","vmlogin","pbrc","vmport");
     528    }
     529}
    472530sub pb_build2vm {
    473531    my ($vm,$all) = pb_get_vm();
     
    610668    print "pb (aka project-builder) Version $projectbuilderver-$projectbuilderrev\n";
    611669    print "\n";
    612     print "Syntax: pb [-vhqt][-r pbroot][-p project][-m \"mach-1[,...]\"] <action> [<pkg1>...]\n";
     670    print "Syntax: pb [-vhqt][-r pbroot][-p project][[-s script] -m \"mach-1[,...]\"] <action> [<pkg1>...]\n";
    613671    print "\n";
    614672    print "-h : This help file\n";
     
    617675    print "-v : Verbose mode\n";
    618676    print "\n";
    619     print "-m machine : Name of the virtual Machines you want\n";
     677    print "-m machine : Name of the Virtual Machines you want\n";
    620678    print "             to build on (space separated). All if none precised\n";
    621679    print "             (or use the env variable PBVM)       \n";
     680    print "\n";
     681    print "-s script  : Name of the script you want\n";
     682    print "             to execute on the related VMs.\n";
    622683    print "\n";
    623684    print "-p project : Name of the project you're working on\n";
     
    646707    print "\t           VM supported are QEMU                 \n";
    647708    print "\n";
     709    print "\tlaunchvm:  Launch a virtual machine and execute potentially\n";
     710    print "\t           a script on it\n";
     711    print "\n";
    648712    print "\tcms2vm:    cms2build + build2vm\n";
    649713    print "\n";
Note: See TracChangeset for help on using the changeset viewer.