Changeset 1348 in ProjectBuilder for devel/pb/bin/pb


Ignore:
Timestamp:
Oct 26, 2011, 11:28:44 AM (12 years ago)
Author:
Bruno Cornec
Message:

r4374@localhost: bruno | 2011-10-25 12:10:59 +0200

  • Add mkbmpath parameter and document it
  • Create a new VE.pm module to host pb_ve_launch (from pb code now reusable for pbmkbm)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r1340 r1348  
    3636use ProjectBuilder::Filter;
    3737use ProjectBuilder::Changelog;
     38use ProjectBuilder::VE;
    3839
    3940# Global variables
     
    20692070    my $create = shift || 0;        # By default do not create a VM/VE/RM
    20702071    my $snapme = shift || 0;        # By default do not snap a VM/VE/RM
     2072    my $usesnap = shift || 1;       # By default study the usage of the snapshot feature of VM/VE/RM    my $create = shift || 0;        # By default do not create a VM/VE/RM
     2073    my $snapme = shift || 0;        # By default do not snap a VM/VE/RM
    20712074    my $usesnap = shift || 1;       # By default study the usage of the snapshot feature of VM/VE/RM
     2075
    20722076
    20732077    # If creation or snapshot creation mode, no snapshot usable
     
    20822086
    20832087    my $pbos = pb_distro_get_context($v);
    2084     my $arch = pb_get_arch();
    2085 
     2088   
    20862089    # Launch the VMs/VEs
    20872090    if ($vtype eq "vm") {
     
    22092212        return($vmexist,$vmpid);
    22102213    } elsif ($vtype eq "ve") {
    2211         # VE here
    2212         # Get distro context
    2213         my $pbos = pb_distro_get_context($v);
    2214 
    2215         # Get VE context
    2216         my ($ptr,$vepath) = pb_conf_get("vetype","vepath");
    2217         my $vetype = $ptr->{$ENV{'PBPROJ'}};
    2218 
    2219         # We can probably only get those params now we have the distro context
    2220         my ($rbsb4pi,$rbspi,$vesnap,$oscodename,$osmindep,$verebuild,$rbsmirrorsrv) = pb_conf_get_if("rbsb4pi","rbspi","vesnap","oscodename","osmindep","verebuild","rbsmirrorsrv");
    2221 
    2222         # We need to avoid umask propagation to the VE
    2223         umask 0022;
    2224 
    2225         if (($vetype eq "chroot") || ($vetype eq "schroot")) {
    2226             # Architecture consistency
    2227             if ($arch ne $pbos->{'arch'}) {
    2228                 die "Unable to launch a VE of architecture $pbos->{'arch'} on a $arch platform" if (($pbos->{'arch'} eq "x86_64") && ($arch =~ /i?86/));
    2229             }
    2230 
    2231             my ($verpmtype,$vedebtype) = pb_conf_get("verpmtype","vedebtype");
    2232             if (($create != 0) || ((defined $verebuild) && ($verebuild->{$ENV{'PBPROJ'}} =~ /true/i)) || ($pbforce == 1)) {
    2233                 my ($rbsopt1) = pb_conf_get_if("rbsopt");
    2234 
    2235                 # We have to rebuild the chroot
    2236                 if ($pbos->{'type'} eq "rpm") {
    2237 
    2238                     # Which tool is used
    2239                     my $verpmstyle = $verpmtype->{$ENV{'PBPROJ'}};
    2240 
    2241                     # Get potential rbs option
    2242                     my $rbsopt = "";
    2243                     if (defined $rbsopt1) {
    2244                         if (defined $rbsopt1->{$verpmstyle}) {
    2245                             $rbsopt = $rbsopt1->{$verpmstyle};
    2246                         } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) {
    2247                             $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}};
    2248                         } else {
    2249                             $rbsopt = "";
    2250                         }
    2251                     }
    2252 
    2253                     my $postinstall = pb_get_postinstall($pbos,$rbspi,$verpmstyle);
    2254                     if ($verpmstyle eq "rinse") {
    2255                         # Need to reshape the mirrors generated with local before-post-install script
    2256                         my $b4post = "--before-post-install ";
    2257                         my $postparam = pb_distro_get_param($pbos,$rbsb4pi);
    2258                         if ($postparam eq "") {
    2259                             $b4post = "";
    2260                         } else {
    2261                             $b4post .= $postparam;
    2262                         }
    2263 
    2264                         # Need to reshape the package list for pb
    2265                         my $addpkgs;
    2266                         $postparam = "";
    2267                         $postparam .= pb_distro_get_param($pbos,$osmindep);
    2268                         if ($postparam eq "") {
    2269                             $addpkgs = "";
    2270                         } else {
    2271                             my $pkgfile = "$ENV{'PBTMP'}/addpkgs.lis";
    2272                             open(PKG,"> $pkgfile") || die "Unable to create $pkgfile";
    2273                             foreach my $p (split(/,/,$postparam)) {
    2274                                 print PKG "$p\n";
    2275                             }
    2276                             close(PKG);
    2277                             $addpkgs = "--add-pkg-list $pkgfile";
    2278                         }
    2279 
    2280                         my $rinseverb = "";
    2281                         $rinseverb = "--verbose" if ($pbdebug gt 0);
    2282                         my ($rbsconf) = pb_conf_get("rbsconf");
    2283 
    2284                         my $command = pb_check_req("rinse",0);
    2285                         pb_system("sudo $command --directory \"$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}\" --arch \"$pbos->{'arch'}\" --distribution \"$pbos->{'name'}-$pbos->{'version'}\" --config \"$rbsconf->{$ENV{'PBPROJ'}}\" $b4post $postinstall $rbsopt $addpkgs $rinseverb","Creating the rinse VE for $pbos->{'name'}-$pbos->{'version'} ($pbos->{'arch'})", "verbose");
    2286                     } elsif ($verpmstyle eq "rpmbootstrap") {
    2287                         my $rbsverb = "";
    2288                         foreach my $i (1..$pbdebug) {
    2289                             $rbsverb .= " -v";
    2290                         }
    2291                         my $addpkgs = "";
    2292                         my $postparam = "";
    2293                         $postparam .= pb_distro_get_param($pbos,$osmindep);
    2294                         if ($postparam eq "") {
    2295                             $addpkgs = "";
    2296                         } else {
    2297                             $addpkgs = "-a $postparam";
    2298                         }
    2299                         my $command = pb_check_req("rpmbootstrap",0);
    2300                         pb_system("sudo $command $rbsopt $postinstall $addpkgs $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'} $rbsverb","Creating the rpmbootstrap VE for $pbos->{'name'}-$pbos->{'version'} ($pbos->{'arch'})", "verbose");
    2301                     } elsif ($verpmstyle eq "mock") {
    2302                         my ($rbsconf) = pb_conf_get("rbsconf");
    2303                         my $command = pb_check_req("mock",0);
    2304                         pb_system("sudo $command --init --resultdir=\"/tmp\" --configdir=\"$rbsconf->{$ENV{'PBPROJ'}}\" -r $v $rbsopt","Creating the mock VE for $pbos->{'name'}-$pbos->{'version'} ($pbos->{'arch'})");
    2305                         # Once setup we need to install some packages, the pb account, ...
    2306                         pb_system("sudo $command --install --configdir=\"$rbsconf->{$ENV{'PBPROJ'}}\" -r $v su","Configuring the mock VE");
    2307                     } else {
    2308                         die "Unknown verpmtype type $verpmstyle. Report to dev team";
    2309                     }
    2310                 } elsif ($pbos->{'type'} eq "deb") {
    2311                     my $vedebstyle = $vedebtype->{$ENV{'PBPROJ'}};
    2312 
    2313                     my $codename = pb_distro_get_param($pbos,$oscodename);
    2314                     my $postparam = "";
    2315                     my $addpkgs;
    2316                     $postparam .= pb_distro_get_param($pbos,$osmindep);
    2317                     if ($postparam eq "") {
    2318                         $addpkgs = "";
    2319                     } else {
    2320                         $addpkgs = "--include $postparam";
    2321                     }
    2322                     my $debmir = "";
    2323                     $debmir .= pb_distro_get_param($pbos,$rbsmirrorsrv);
    2324 
    2325                     # Get potential rbs option
    2326                     my $rbsopt = "";
    2327                     if (defined $rbsopt1) {
    2328                         if (defined $rbsopt1->{$vedebstyle}) {
    2329                             $rbsopt = $rbsopt1->{$vedebstyle};
    2330                         } elsif (defined $rbsopt1->{$ENV{'PBPROJ'}}) {
    2331                             $rbsopt = $rbsopt1->{$ENV{'PBPROJ'}};
    2332                         } else {
    2333                             $rbsopt = "";
    2334                         }
    2335                     }
    2336    
    2337                     # debootstrap works with amd64 not x86_64
    2338                     my $debarch = $pbos->{'arch'};
    2339                     $debarch = "amd64" if ($pbos->{'arch'} eq "x86_64");
    2340                     if ($vedebstyle eq "debootstrap") {
    2341                         my $dbsverb = "";
    2342                         $dbsverb = "--verbose" if ($pbdebug gt 0);
    2343 
    2344                         # Some perl modules are in Universe on Ubuntu
    2345                         $rbsopt .= " --components=main,universe" if ($pbos->{'name'} eq "ubuntu");
    2346 
    2347                         pb_system("sudo /usr/sbin/debootstrap $dbsverb $rbsopt --arch=$debarch $addpkgs $codename \"$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}\" $debmir","Creating the debootstrap VE for $pbos->{'name'}-$pbos->{'version'} ($pbos->{'arch'})", "verbose");
    2348                         # debootstrap doesn't create an /etc/hosts file
    2349                         if (! -f "$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/etc/hosts" ) {
    2350                             pb_system("sudo cp /etc/hosts $vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}/etc/hosts");
    2351                         }
    2352                     } else {
    2353                         die "Unknown vedebtype type $vedebstyle. Report to dev team";
    2354                     }
    2355                 } elsif ($pbos->{'type'} eq "ebuild") {
    2356                     die "Please teach the dev team how to build gentoo chroot";
    2357                 } else {
    2358                     die "Unknown distribution type $pbos->{'type'}. Report to dev team";
    2359                 }
    2360             }
    2361             # Fix modes to allow access to the VE for pb user
    2362             pb_system("sudo chmod 755 $vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'} $vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'} $vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}","Fixing permissions");
    2363 
    2364             # Test if an existing snapshot exists and use it if appropriate
    2365             # And also use it of no local extracted VE is present
    2366             if ((-f "$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz") &&
    2367                 (((defined $vesnap->{$v}) && ($vesnap->{$v} =~ /true/i)) ||
    2368                     ((defined $vesnap->{$ENV{'PBPROJ'}}) && ($vesnap->{$ENV{'PBPROJ'}} =~ /true/i)) ||
    2369                     ($pbsnap eq 1) ||
    2370                     (! -d "$vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}"))) {
    2371                         pb_system("sudo rm -rf $vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'} ; sudo mkdir -p $vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'} ; sudo tar xz  -C $vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'} -f $vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz","Extracting snapshot of $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}.tar.gz under $vepath->{$ENV{'PBPROJ'}}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}");
    2372             }
    2373             # Nothing more to do for VE. No real launch
    2374         } else {
    2375             die "VE of type $vetype not supported. Report to the dev team";
    2376         }
     2214        pb_ve_launch($v,$create,$pbforce,$pbsnap);
    23772215    } else {
    23782216        # RM here
     
    36783516}
    36793517
    3680 #
    3681 # Return the postinstall line if needed
    3682 #
    3683 
    3684 sub pb_get_postinstall {
    3685 
    3686 my $pbos = shift;
    3687 my $rbspi = shift;
    3688 my $vestyle = shift;
    3689 my $post = "";
    3690 
    3691 # Do we have a local post-install script
    3692 if ($vestyle eq "rinse") {
    3693     $post = "--post-install ";
    3694 } elsif ($vestyle eq "rpmbootstrap") {
    3695     $post = "-s ";
    3696 }
    3697 
    3698 my $postparam = pb_distro_get_param($pbos,$rbspi);
    3699 if ($postparam eq "") {
    3700     $post = "";
    3701 } else {
    3702     $post .= $postparam;
    3703 }
    3704 return($post);
    3705 }
    3706 
    37073518# Manages VM/RM SSH port communication
    37083519sub pb_get_port {
Note: See TracChangeset for help on using the changeset viewer.