diff options
-rw-r--r-- | installer/OpenSLX/OSSetup/Engine.pm | 49 | ||||
-rw-r--r-- | installer/OpenSLX/OSSetup/MetaPackager/Base.pm | 4 | ||||
-rw-r--r-- | installer/OpenSLX/OSSetup/MetaPackager/apt.pm | 26 | ||||
-rw-r--r-- | installer/OpenSLX/OSSetup/MetaPackager/smart.pm | 24 | ||||
-rw-r--r-- | installer/OpenSLX/OSSetup/MetaPackager/yum.pm | 26 | ||||
-rw-r--r-- | installer/OpenSLX/OSSetup/MetaPackager/zypper.pm | 28 | ||||
-rw-r--r-- | os-plugins/OpenSLX/OSPlugin/Base.pm | 8 | ||||
-rw-r--r-- | os-plugins/OpenSLX/OSPlugin/Engine.pm | 352 |
8 files changed, 407 insertions, 110 deletions
diff --git a/installer/OpenSLX/OSSetup/Engine.pm b/installer/OpenSLX/OSSetup/Engine.pm index 3dc7d7c2..d3956629 100644 --- a/installer/OpenSLX/OSSetup/Engine.pm +++ b/installer/OpenSLX/OSSetup/Engine.pm @@ -212,7 +212,7 @@ sub initialize $distro->initialize($self); $self->{distro} = $distro; - if ($actionType =~ m{^(install|update|shell)}) { + if ($actionType =~ m{^(install|update|shell|plugin)}) { # setup path to distribution-specific info: my $sharedDistroInfoDir = "$openslxConfig{'base-path'}/share/distro-info/$self->{'distro-name'}"; @@ -261,7 +261,7 @@ sub initialize = "$openslxConfig{'private-path'}/stage1/$self->{'vendor-os-name'}"; vlog(1, "vendor-OS path is '$self->{'vendor-os-path'}'"); - if ($actionType =~ m{^(install|update|shell)}) { + if ($actionType =~ m{^(install|update|shell|plugin)}) { $self->_createPackager(); $self->_createMetaPackager(); } @@ -664,6 +664,27 @@ sub pickKernelFile return $self->{distro}->pickKernelFile(@_); } +sub distroName +{ + my $self = shift; + + return $self->{'distro-name'}; +} + +sub metaPackager +{ + my $self = shift; + + return $self->{'meta-packager'}; +} + +sub busyboxBinary +{ + my $self = shift; + + return $self->{'busybox-binary'}; +} + ################################################################################ ### implementation methods ################################################################################ @@ -789,7 +810,7 @@ sub _configureBestMirrorsForRepository my $allMirrorsFile = "$self->{'shared-distro-info-dir'}/mirrors/$repoInfo->{key}"; - my @allMirrors = string2Array(slurpFile($allMirrorsFile)); + my @allMirrors = string2Array(scalar slurpFile($allMirrorsFile)); my $mirrorsToTryCount = $openslxConfig{'mirrors-to-try-count'} || 20; my $mirrorsToUseCount = $openslxConfig{'mirrors-to-use-count'} || 5; @@ -851,16 +872,25 @@ sub _configureBestMirrorsForRepository !grep { $mirror eq $_ } @tryMirrors; } @allMirrors; - # ... now pick randomly until we have reached the limit or there are + # ... and pick randomly until we have reached the limit or there are # no more unused mirrors left foreach my $count (@tryMirrors..$mirrorsToTryCount-1) { last if !@untriedMirrors; - my $index = int(rand(scalar(@untriedMirrors))); + my $index = int(rand(scalar @untriedMirrors)); my $randomMirror = splice(@untriedMirrors, $index, 1); push @tryMirrors, $randomMirror; vlog(1, "\t$randomMirror\n"); } } + + # just make sure we are not going to try/use more mirros than we have + # available + if ($mirrorsToTryCount > @tryMirrors) { + $mirrorsToTryCount = @tryMirrors; + } + if ($mirrorsToUseCount > $mirrorsToTryCount) { + $mirrorsToUseCount = $mirrorsToTryCount; + } # ... fetch a file from all of these mirrors and measure the time taken ... vlog(0, @@ -938,17 +968,14 @@ sub _speedTestMirror } # now measure the time it takes to download the file - my $tempFile = "$openslxConfig{'temp-path'}/slx-mirror-testfile"; - unlink $tempFile if -e $tempFile; my $wgetCmd - = "$self->{'busybox-binary'} wget -q -O $tempFile $mirror/$file"; + = "$self->{'busybox-binary'} wget -q -O - $mirror/$file >/dev/null"; my $start = time(); if (slxsystem($wgetCmd)) { # just return any large number that is unlikely to be selected return 10000; } my $time = time() - $start; - unlink $tempFile; vlog(0, "\tfetched '$file' in $time seconds\n"); return $time; } @@ -1092,7 +1119,7 @@ try_next_url: foreach my $file (split '\s+', $fileVariantStr) { my $basefile = basename($file); vlog(2, "fetching <$file>..."); - if (slxsystem("wget", "$url/$file") == 0) { + if (slxsystem("wget", "-c", "-O", "$basefile", "$url/$file") == 0) { $foundFile = $basefile; last; } @@ -1589,7 +1616,7 @@ sub _stage1D_installPackageSelection } else { vlog(1, "installing these packages:\n" . join("\n\t", @pkgs)); - $self->{'meta-packager'}->installSelection(join " ", @pkgs); + $self->{'meta-packager'}->installSelection(join " ", @pkgs, 1); } return; } diff --git a/installer/OpenSLX/OSSetup/MetaPackager/Base.pm b/installer/OpenSLX/OSSetup/MetaPackager/Base.pm index dd552071..91b2d087 100644 --- a/installer/OpenSLX/OSSetup/MetaPackager/Base.pm +++ b/installer/OpenSLX/OSSetup/MetaPackager/Base.pm @@ -53,6 +53,10 @@ sub installSelection { } +sub removeSelection +{ +} + 1; ################################################################################ diff --git a/installer/OpenSLX/OSSetup/MetaPackager/apt.pm b/installer/OpenSLX/OSSetup/MetaPackager/apt.pm index 5cfd2655..137bab5e 100644 --- a/installer/OpenSLX/OSSetup/MetaPackager/apt.pm +++ b/installer/OpenSLX/OSSetup/MetaPackager/apt.pm @@ -61,7 +61,8 @@ sub initPackageSources END-OF-HERE spitFile('/etc/kernel-img.conf', $kernelConfig); } - return; + + return 1; } sub setupPackageSource @@ -89,10 +90,11 @@ sub setupPackageSource sub installSelection { - my $self = shift; + my $self = shift; my $pkgSelection = shift; + my $doRefresh = shift || 0; - if (slxsystem("apt-get -y update")) { + if ($doRefresh && slxsystem("apt-get -y update")) { die _tr("unable to update repository info (%s)\n", $!); } if ('/var/cache/debconf/slx-defaults.dat') { @@ -105,7 +107,20 @@ sub installSelection } delete $ENV{DEBCONF_DB_FALLBACK}; delete $ENV{DEBIAN_FRONTEND}; - return; + + return 1; +} + +sub removeSelection +{ + my $self = shift; + my $pkgSelection = shift; + + if (slxsystem("apt-get -y remove $pkgSelection")) { + die _tr("unable to remove selection (%s)\n", $!); + } + + return 1; } sub updateBasicVendorOS @@ -118,7 +133,8 @@ sub updateBasicVendorOS if (slxsystem("apt-get -y upgrade")) { die _tr("unable to update this vendor-os (%s)\n", $!); } - return; + + return 1; } 1;
\ No newline at end of file diff --git a/installer/OpenSLX/OSSetup/MetaPackager/smart.pm b/installer/OpenSLX/OSSetup/MetaPackager/smart.pm index 71d9875c..cbe96009 100644 --- a/installer/OpenSLX/OSSetup/MetaPackager/smart.pm +++ b/installer/OpenSLX/OSSetup/MetaPackager/smart.pm @@ -44,7 +44,7 @@ sub initPackageSources if (slxsystem("smart channel -y --remove-all")) { die _tr("unable to remove existing channels (%s)\n", $!); } - return; + return 1; } sub setupPackageSource @@ -79,21 +79,33 @@ sub setupPackageSource ); } } - return; + return 1; } sub installSelection { - my $self = shift; + my $self = shift; my $pkgSelection = shift; + my $doRefresh = shift || 0; - if (slxsystem("smart update")) { + if ($doRefresh && slxsystem("smart update")) { die _tr("unable to update channel info (%s)\n", $!); } if (slxsystem("smart install -y $pkgSelection")) { die _tr("unable to install selection (%s)\n", $!); } - return; + return 1; +} + +sub removeSelection +{ + my $self = shift; + my $pkgSelection = shift; + + if (slxsystem("smart remove -y $pkgSelection")) { + die _tr("unable to remove selection (%s)\n", $!); + } + return 1; } sub updateBasicVendorOS @@ -107,7 +119,7 @@ sub updateBasicVendorOS } die _tr("unable to update this vendor-os (%s)\n", $!); } - return; + return 1; } 1;
\ No newline at end of file diff --git a/installer/OpenSLX/OSSetup/MetaPackager/yum.pm b/installer/OpenSLX/OSSetup/MetaPackager/yum.pm index 337227ed..7d2bc630 100644 --- a/installer/OpenSLX/OSSetup/MetaPackager/yum.pm +++ b/installer/OpenSLX/OSSetup/MetaPackager/yum.pm @@ -41,7 +41,8 @@ sub initPackageSources slxsystem("rm -f /etc/yum.repos.d/*"); slxsystem("mkdir -p /etc/yum.repos.d"); - return; + + return 1; } sub setupPackageSource @@ -66,18 +67,32 @@ sub setupPackageSource } my $repoFile = "/etc/yum.repos.d/$repoName.repo"; spitFile($repoFile, "$repoDescr\nexclude=$excludeList\n"); - return; + + return 1; } sub installSelection { - my $self = shift; + my $self = shift; my $pkgSelection = shift; if (slxsystem("yum -y install $pkgSelection")) { die _tr("unable to install selection (%s)\n", $!); } - return; + + return 1; +} + +sub removeSelection +{ + my $self = shift; + my $pkgSelection = shift; + + if (slxsystem("yum -y remove $pkgSelection")) { + die _tr("unable to remove selection (%s)\n", $!); + } + + return 1; } sub updateBasicVendorOS @@ -91,7 +106,8 @@ sub updateBasicVendorOS } die _tr("unable to update this vendor-os (%s)\n", $!); } - return; + + return 1; } 1;
\ No newline at end of file diff --git a/installer/OpenSLX/OSSetup/MetaPackager/zypper.pm b/installer/OpenSLX/OSSetup/MetaPackager/zypper.pm index bb50ad4c..04554e70 100644 --- a/installer/OpenSLX/OSSetup/MetaPackager/zypper.pm +++ b/installer/OpenSLX/OSSetup/MetaPackager/zypper.pm @@ -41,7 +41,8 @@ sub initPackageSources # remove any existing channels slxsystem("rm -f /etc/zypp/repos.d/*"); - return; + + return 1; } sub setupPackageSource @@ -61,21 +62,35 @@ sub setupPackageSource die _tr("unable to add repo '%s' (%s)\n", $repoName, $!); } - return; + return 1; } sub installSelection { - my $self = shift; + my $self = shift; my $pkgSelection = shift; + my $doRefresh = shift || 0; - if (slxsystem("zypper --non-interactive refresh")) { + if ($doRefresh && slxsystem("zypper --non-interactive refresh")) { die _tr("unable to update repo info (%s)\n", $!); } if (slxsystem("zypper --non-interactive install $pkgSelection")) { die _tr("unable to install selection (%s)\n", $!); } - return; + + return 1; +} + +sub removeSelection +{ + my $self = shift; + my $pkgSelection = shift; + + if (slxsystem("zypper --non-interactive remove $pkgSelection")) { + die _tr("unable to remove selection (%s)\n", $!); + } + + return 1; } sub updateBasicVendorOS @@ -89,7 +104,8 @@ sub updateBasicVendorOS } die _tr("unable to update this vendor-os (%s)\n", $!); } - return; + + return 1; } 1;
\ No newline at end of file diff --git a/os-plugins/OpenSLX/OSPlugin/Base.pm b/os-plugins/OpenSLX/OSPlugin/Base.pm index 2eef4b82..f1854f2e 100644 --- a/os-plugins/OpenSLX/OSPlugin/Base.pm +++ b/os-plugins/OpenSLX/OSPlugin/Base.pm @@ -44,8 +44,6 @@ vendor-OS) =item - L</Initramfs Interface> (integrating a plugin into an initramfs) -=item - L</Support Interface> (offers each plugin access to OpenSLX services) - =back =head1 MORE INFO @@ -357,10 +355,4 @@ sub setupPluginInInitramfs =back -=head2 Support Interface - -=over - -=cut - 1; diff --git a/os-plugins/OpenSLX/OSPlugin/Engine.pm b/os-plugins/OpenSLX/OSPlugin/Engine.pm index 5db6f9b8..23d3d953 100644 --- a/os-plugins/OpenSLX/OSPlugin/Engine.pm +++ b/os-plugins/OpenSLX/OSPlugin/Engine.pm @@ -25,9 +25,27 @@ use OpenSLX::Basics; use OpenSLX::OSSetup::Engine; use OpenSLX::Utils; -################################################################################ -### interface methods -################################################################################ +=head1 NAME + +OpenSLX::OSPlugin::Engine - driver class for plugin handling. + +=head1 DESCRIPTION + +This class works as a driver for the installation/removal of plugins +into/from a vendor. + +Additionally, it provides the OS-Plugin support interface. + +=head1 PUBLIC METHODS + +=over + +=item new() + +Trivial constructor + +=cut + sub new { my $class = shift; @@ -37,6 +55,13 @@ sub new return bless $self, $class; } +=item initialize($pluginName, $vendorOSName ) + +Sets up basic data (I<$pluginName> and I<$vendorOSName>) as well as paths and +loads plugin. + +=cut + sub initialize { my $self = shift; @@ -57,60 +82,51 @@ sub initialize $self->{'plugin'} = $self->_loadPlugin(); return if !$self->{'plugin'}; + + $self->{'chrooted-plugin-repo-path'} + = "$openslxConfig{'base-path'}/plugin-repo/$self->{'plugin-name'}"; + $self->{'plugin-repo-path'} + = "$self->{'vendor-os-path'}/$self->{'chrooted-plugin-repo-path'}"; + $self->{'chrooted-plugin-temp-path'} + = "/tmp/slx-plugin/$self->{'plugin-name'}"; + $self->{'plugin-temp-path'} + = "$self->{'vendor-os-path'}/$self->{'chrooted-plugin-temp-path'}"; + $self->{'chrooted-openslx-base-path'} = '/mnt/openslx'; } return 1; } +=back + +=head2 Driver Interface + +The following methods are invoked by the slxos-plugin script in order to +install/remove a plugin into/from a vendor-OS: + +=over + +=item installPlugin() + +Creates an ossetup-engine for the current vendor-OS and asks that to invoke +the plugin's installer method while chrooted into that vendor-OS. + +=cut + sub installPlugin { my $self = shift; if ($self->{'vendor-os-name'} ne '<<<default>>>') { - # create ossetup-engine for given vendor-OS: - my $osSetupEngine = OpenSLX::OSSetup::Engine->new; - $osSetupEngine->initialize($self->{'vendor-os-name'}, 'plugin'); - $self->{'os-setup-engine'} = $osSetupEngine; - - # bind mount openslx basepath to /mnt/openslx of vendor-OS: - my $basePath = $openslxConfig{'base-path'}; - my $openslxPathInChroot = "$self->{'vendor-os-path'}/mnt/openslx"; - mkpath( [ $openslxPathInChroot ] ); - if (slxsystem("mount -o bind $basePath $openslxPathInChroot")) { - croak( - _tr( - "unable to bind mount '%s' to '%s'! (%s)", - $basePath, $openslxPathInChroot, $! - ) - ); - } - - # now let plugin install itself into vendor-OS - my $chrootedPluginRepoPath - = "$openslxConfig{'base-path'}/plugin-repo/$self->{'plugin-name'}"; - my $pluginRepoPath - = "$self->{'vendor-os-path'}/$chrootedPluginRepoPath"; - my $chrootedPluginTempPath - = "/tmp/slx-plugin/$self->{'plugin-name'}"; - my $pluginTempPath - = "$self->{'vendor-os-path'}/$chrootedPluginTempPath"; - foreach my $path ($pluginRepoPath, $pluginTempPath) { - if (slxsystem("mkdir -p $path")) { - croak(_tr("unable to create path '%s'! (%s)", $path, $!)); - } - } - $self->{'os-setup-engine'}->callChrootedFunctionForVendorOS( + $self->_callChrootedFunctionForPlugin( sub { $self->{plugin}->installationPhase( - $chrootedPluginRepoPath, $chrootedPluginTempPath, - '/mnt/openslx', + $self->{'chrooted-plugin-repo-path'}, + $self->{'chrooted-plugin-temp-path'}, + $self->{'chrooted-openslx-base-path'}, ); } ); - - if (slxsystem("umount $openslxPathInChroot")) { - croak(_tr("unable to umount '%s'! (%s)", $openslxPathInChroot, $!)); - } } $self->_addInstalledPluginToDB(); @@ -118,41 +134,24 @@ sub installPlugin return 1; } -sub getPlugin -{ - my $self = shift; +=item removePlugin() + +Creates an ossetup-engine for the current vendor-OS and asks that to invoke +the plugin's removal method while chrooted into that vendor-OS. + +=cut - return $self->{plugin}; -} - sub removePlugin { my $self = shift; if ($self->{'vendor-os-name'} ne '<<<default>>>') { - # create ossetup-engine for given vendor-OS: - my $osSetupEngine = OpenSLX::OSSetup::Engine->new; - $osSetupEngine->initialize($self->{'vendor-os-name'}, 'plugin'); - $self->{'os-setup-engine'} = $osSetupEngine; - - my $chrootedPluginRepoPath - = "$openslxConfig{'base-path'}/plugin-repo/$self->{'plugin-name'}"; - my $pluginRepoPath - = "$self->{'vendor-os-path'}/$chrootedPluginRepoPath"; - my $chrootedPluginTempPath - = "/tmp/slx-plugin/$self->{'plugin-name'}"; - my $pluginTempPath - = "$self->{'vendor-os-path'}/$chrootedPluginTempPath"; - foreach my $path ($pluginRepoPath, $pluginTempPath) { - if (slxsystem("mkdir -p $path")) { - croak(_tr("unable to create path '%s'! (%s)", $path, $!)); - } - } - - $self->{'os-setup-engine'}->callChrootedFunctionForVendorOS( + $self->_callChrootedFunctionForPlugin( sub { $self->{plugin}->removalPhase( - $chrootedPluginRepoPath, $chrootedPluginTempPath + $self->{'chrooted-plugin-repo-path'}, + $self->{'chrooted-plugin-temp-path'}, + $self->{'chrooted-openslx-base-path'}, ); } ); @@ -163,6 +162,13 @@ sub removePlugin return 1; } +=item getInstalledPlugins() + +Returns the list of names of the plugins that are installed into the current +vendor-OS. + +=cut + sub getInstalledPlugins { my $self = shift; @@ -183,6 +189,179 @@ sub getInstalledPlugins return @installedPlugins; } +=back + +=head2 Support Interface + +This is the plugin support interface for OS-plugins, which represents the +connection between a plugin's implementation and the rest of the OpenSLX system. + +Plugin implementations are meant to use this interface in order to find +out details about the current vendor-OS or download files or install packages. + +=over + +=item vendorOSName() + +Returns the name of the current vendor-OS. + +=cut + +sub vendorOSName +{ + my $self = shift; + + return $self->{'vendor-os-name'}; +} + +=item distroName() + +Returns the name of the distro that the current vendor-OS is based on. + +Each distro name always consists of the distro type, a dash and the +distro version, like 'suse-10.2' or 'ubuntu-7.04'. + +=cut + +sub distroName +{ + my $self = shift; + + return $self->{'ossetup-engine'}->distroName(); +} + +=item downloadFile($fileURL, $targetPath, $wgetOptions) + +Invokes busybox's wget to download a file from the given URL. + +=over + +=item I<$fileURL> + +The URL of the file to download. + +=item I<$targetPath> [optional] + +The directory where the file should be downloaded into. The default is the +current plugin's temp directory. + +=item I<$wgetOptions> [optional] + +Any other options you'd like to pass to wget. + +=item I<Return Value> + +If the downloaded was successful this method returns C<1>, otherwise it dies. + +=back + +=cut + +sub downloadFile +{ + my $self = shift; + my $fileURL = shift || return; + my $targetPath = shift || $self->{'chrooted-plugin-temp-path'}; + my $wgetOptions = shift || ''; + + my $busybox = $self->{'ossetup-engine'}->busyboxBinary(); + + if (slxsystem("$busybox wget -P $targetPath $wgetOptions $fileURL")) { + die _tr('unable to download file "%s"! (%s)', $fileURL, $!); + } + + return 1; +} + +=item getInstalledPackages() + +Returns the list of names of the packages that are already installed in the +vendor-OS. Useful if a plugin wants to find out whether or not it has to +install additional packages. + +=cut + +sub getInstalledPackages +{ + my $self = shift; + + my $metaPackager = $self->{'ossetup-engine'}->metaPackager(); + return if !$metaPackager; + + return $metaPackager->getInstalledPackages(); +} + +=item installPackages($packages) + +Installs the given packages into the vendor-OS. + +N.B: Since this method uses the meta-packager of the vendor-OS, package +dependencies will be determined and solved automatically. + +=over + +=item I<$packages> + +Contains a list of package names (separated by spaces) that shall be installed. + +=item I<Return Value> + +If the packages have been installed successfully this method return 1, +otherwise it dies. + +=back + +=cut + +sub installPackages +{ + my $self = shift; + my $packages = shift; + + return if !$packages; + + my $metaPackager = $self->{'ossetup-engine'}->metaPackager(); + return if !$metaPackager; + + return $metaPackager->installSelection($packages); +} + +=item removePackages($packages) + +Removes the given packages from the vendor-OS. + +=over + +=item I<$packages> [ARRAY-ref] + +Contains a list of package names (separated by spaces) that shall be removed. + +=item I<Return Value> + +If the packages have been removed successfully this method return 1, +otherwise it dies. + +=back + +=cut + +sub removePackages +{ + my $self = shift; + my $packages = shift; + + return if !$packages; + + my $metaPackager = $self->{'ossetup-engine'}->metaPackager(); + return if !$metaPackager; + + return $metaPackager->removeSelection($packages); +} + +=back + +=cut + sub _loadPlugin { my $self = shift; @@ -198,6 +377,41 @@ sub _loadPlugin return $plugin; } +sub _callChrootedFunctionForPlugin +{ + my $self = shift; + my $function = shift; + + # create ossetup-engine for given vendor-OS: + my $osSetupEngine = OpenSLX::OSSetup::Engine->new; + $osSetupEngine->initialize($self->{'vendor-os-name'}, 'plugin'); + $self->{'os-setup-engine'} = $osSetupEngine; + + # bind-mount openslx basepath to /mnt/openslx of vendor-OS: + my $basePath = $openslxConfig{'base-path'}; + my $openslxPathInChroot = "$self->{'vendor-os-path'}/mnt/openslx"; + mkpath( [ $openslxPathInChroot ] ); + if (slxsystem("mount -o bind $basePath $openslxPathInChroot")) { + croak( + _tr( + "unable to bind mount '%s' to '%s'! (%s)", + $basePath, $openslxPathInChroot, $! + ) + ); + } + + # now let plugin install itself into vendor-OS + $self->{'os-setup-engine'}->callChrootedFunctionForVendorOS($function); + + if (slxsystem("umount $openslxPathInChroot")) { + croak(_tr("unable to umount '%s'! (%s)", $openslxPathInChroot, $!)); + } + + delete $self->{'os-setup-engine'}; + + return; +} + sub _addInstalledPluginToDB { my $self = shift; |