summaryrefslogtreecommitdiffstats
path: root/os-plugins/OpenSLX/OSPlugin/Engine.pm
blob: 5785022997d3796fd92f03aa38a81cf4b8bc04dc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# Copyright (c) 2007 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
# Engine.pm
#	- provides driver engine for the OSPlugin API.
# -----------------------------------------------------------------------------
package OpenSLX::OSPlugin::Engine;

use strict;
use warnings;

our $VERSION = 1.01;    # API-version . implementation-version

use File::Basename;

use OpenSLX::Basics;
use OpenSLX::OSSetup::Engine;
use OpenSLX::Utils;

################################################################################
### interface methods
################################################################################
sub new
{
	my $class = shift;

	my $self = {};

	return bless $self, $class;
}

sub getAvailablePlugins
{	# Class-method!
	my $class = shift;

	return 
		map { basename($_); }
		sort 
		glob("$openslxConfig{'base-path'}/lib/plugins/*");
}

sub initialize
{
	my $self         = shift;
	my $pluginName   = shift;
	my $vendorOSName = shift;

	$self->{'plugin-name'}     = $pluginName;
	$self->{'vendor-os-name'}  = $vendorOSName;

	$self->{'vendor-os-path'} 
		= "$openslxConfig{'private-path'}/stage1/$vendorOSName";
	vlog(1, "vendor-OS path is '$self->{'vendor-os-path'}'");

	$self->{'plugin-path'} 
		= "$openslxConfig{'base-path'}/lib/plugins/$pluginName";
	vlog(1, "plugin path is '$self->{'plugin-path'}'");
	
	$self->{'plugin'} = $self->_loadPlugin();
}

sub installPlugin
{
	my $self = 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;
	$self->{'distro-name'}     = $osSetupEngine->{'distro-name'};

	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->{plugin}->preInstallationPhase($pluginRepoPath, $pluginTempPath);
	
	$self->{'os-setup-engine'}->callChrootedFunctionForVendorOS(
		sub {
			$self->{plugin}->installationPhase(
				$chrootedPluginRepoPath, $chrootedPluginTempPath
			);
		}
	);
	
	$self->{plugin}->postInstallationPhase($pluginRepoPath, $pluginTempPath);
}

sub getPlugin
{
	my $self = shift;

	return $self->{plugin};
}
	
sub removePlugin
{
}

sub _loadPlugin
{
	my $self = shift;
	
	my $pluginModule = "OpenSLX::OSPlugin::$self->{'plugin-name'}";
	my $plugin = instantiateClass(
		$pluginModule, { pathToClass => $self->{'plugin-path'} }
	);
	$plugin->initialize($self);
	return $plugin;
}