summaryrefslogtreecommitdiffstats
path: root/os-plugins/plugins/vmware/OpenSLX/Distro/Suse.pm
blob: 7e6840ccb16ac53434a28a1296f962f750c1581b (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Copyright (c) 2008 - 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/
# -----------------------------------------------------------------------------
# vmware/OpenSLX/Distro/Suse.pm
#    - provides SUSE-specific overrides of the Distro API for the vmware plugin.
# -----------------------------------------------------------------------------
package vmware::OpenSLX::Distro::Suse;

use strict;
use warnings;

use base qw(vmware::OpenSLX::Distro::Base);

use OpenSLX::Basics;
use OpenSLX::Utils;

################################################################################
### interface methods
################################################################################

sub fillRunlevelScript
{
    my $self     = shift;
    my $location = shift;
    my $kind     = shift;

    my $script = unshiftHereDoc(<<"    End-of-Here");
        #!/bin/sh
        # SuSE compatible start/stop script, generated via stage1 'vmware' plugin
        # installation
        #
        # inspiration taken from vmware start script:
        #   Copyright 1998-2007 VMware, Inc.  All rights reserved.
        #
        # This script manages the services needed to run VMware software
        
        # Basic support for the Linux Standard Base Specification 1.3
        ### BEGIN INIT INFO
        # Provides: VMware
        # Required-Start: \$syslog
        # Required-Stop:
        # Default-Start: 2 3 5
        # Default-Stop: 0 6
        # Short-Description: Manages the services needed to run VMware software
        # Description: Manages the services needed to run VMware software
        ### END INIT INFO

        # helper functions
        load_modules() {
    End-of-Here

    # Load modules
    if ($kind eq 'local' || $kind eq 'local25') {
        $script .= unshiftHereDoc(<<"        End-of-Here");
                  # to be filled in via the stage1 configuration script
                  insmod /lib/modules/\$(uname -r)/misc/vmmon.ko || return 1
                  insmod /lib/modules/\$(uname -r)/misc/vmnet.ko || return 1
                  insmod /lib/modules/\$(uname -r)/misc/vmblock.ko 2>/dev/null || return 0
        End-of-Here
    } elsif ($kind eq 'vmpl1.0') {
        $script .= unshiftHereDoc(<<"        End-of-Here");
                  vmware_kind_path=/opt/openslx/plugin-repo/vmware/\${vmware_kind}/
                  module_src_path=\${vmware_kind_path}/vmroot/modules
                  insmod \${module_src_path}/vmmon.ko
                  insmod \${module_src_path}/vmnet.ko
        End-of-Here
    } elsif ($kind eq "vmpl2.0") {
        $script .= unshiftHereDoc(<<"        End-of-Here");
                  vmware_kind_path=/opt/openslx/plugin-repo/vmware/\${vmware_kind}/
                  module_src_path=\${vmware_kind_path}/vmroot/modules
                  insmod \${module_src_path}/vmmon.ko
                  insmod \${module_src_path}/vmnet.ko
                  insmod \${module_src_path}/vmblock.ko
        End-of-Here
    } elsif ($kind eq 'vmpl2.5') {
        $script .= unshiftHereDoc(<<"        End-of-Here");
                  vmware_kind_path=/opt/openslx/plugin-repo/vmware/\${vmware_kind}/
                  module_src_path=\${vmware_kind_path}/vmroot/modules
                  insmod \${module_src_path}/vmmon.ko
                  insmod \${module_src_path}/vmnet.ko
                  insmod \${module_src_path}/vmblock.ko
        End-of-Here
    }

    # unload modules
    $script .= unshiftHereDoc(<<"    End-of-Here");
        }

        unload_modules() {
          # to be filled with the proper list within via the stage1
          # configuration script
          rmmod vmmon vmblock vmnet vmmon 2>/dev/null
        }
    End-of-Here

    # setup vmnet0 and vmnet8
    # depends on specific stage3 setting. A complete rewrite would be
    # needed (generation of proper runlevel scripts depending on distro
    # and VMware version, see tickets #211, 290)
    $script .= unshiftHereDoc(<<"    End-of-Here");
        # the bridged interface
        setup_vmnet0() {
          if [ -n "\$vmnet0" ] ; then
            # the path might be directly point to the plugin dir
    End-of-Here
    if ($kind eq 'vmpl2.5'||$kind eq 'local25') {
        $script .= "    $location/vmnet-bridge -d /var/run/vmnet-bridge-0.pid -n 0\n";
    } else {
        $script .= "    $location/vmnet-bridge -d /var/run/vmnet-bridge-0.pid /dev/vmnet0 eth0\n";
    }
    $script .= unshiftHereDoc(<<"        End-of-Here");
          fi
        }
        # we definately prefer the hostonly interface for NATed operation too
        # distinction is made via enabled forwarding
        setup_vmnet1() {
          if [ -n "\$vmnet1" ] ; then
            # the path might be directly point to the plugin dir
            $location/vmnet-netifup -d /var/run/vmnet-netifup-vmnet1.pid \\
              /dev/vmnet1 vmnet1
            dhcpif="\$dhcpif vmnet1"
            ip addr add \$vmnet1 dev vmnet1
            ip link set vmnet1 up
            if [ -n "\$vmnet1nat" ] ; then
              # needs refinement interface name for eth0 is known in stage3 already
              # available from \$nwif
              echo "1" > /proc/sys/net/ipv4/conf/vmnet1/forwarding 2>/dev/null
              echo "1" > /proc/sys/net/ipv4/conf/eth0/forwarding 2>/dev/null
              #iptables -A -s vmnet1 -d eth0
            fi
            $location/vmnet-dhcpd -cf /etc/vmware/dhcpd-vmnet1.conf \\
              -lf /var/run/vmware/dhcpd-vmnet1.leases \\
              -pf /var/run/vmnet-dhcpd-vmnet1.pid vmnet1 2>/dev/null # or logfile
          fi
        }
        # incomplete ...
        setup_vmnet8() {
          if [ -n "\$vmnet8" ] ; then
            # we don't need the following test. It's handled by
            # XX_vmware.sh
            #test -c /dev/vmnet8 || mknod c 119 8 /dev/vmnet8
            $location/vmnet-netifup -d /var/run/vmnet-netifup-vmnet8.pid \\
              /dev/vmnet8 vmnet8
            ip addr add \$vmnet8 dev vmnet8
            ip link set vmnet8 up
            # /etc/vmware/vmnet-natd-8.mac simply contains a mac like 00:50:56:F1:30:50
            $location/vmnet-natd -d /var/run/vmnet-natd-8.pid \\
              -m /etc/vmware/vmnet-natd-8.mac -c /etc/vmware/nat.conf 2>/dev/null # or logfile
            $location/vmnet-dhcpd -cf /etc/vmware/dhcpd-vmnet8.conf \\
              -lf /var/run/vmware/dhcpd-vmnet8.leases \\
              -pf /var/run/vmnet-dhcpd-vmnet8.pid vmnet8 2>/dev/null # or logfile
          fi
        }
        # load the helper stuff
        . /etc/rc.status
        # reset the script status
        rc_reset
    
        case \$1 in
          start)
            echo -n "Starting vmware background services ..."
            # load the configuration file
            . /etc/vmware/slxvmconfig
            # hack to access the first serial/parallel port
            chmod a+rw /dev/ttyS0
            chmod a+rw /dev/parport0
            load_modules
            setup_vmnet0
            setup_vmnet1
            setup_vmnet8
            rc_status -v
          ;;
          stop)
            # message output should match the given vendor-os
            echo -n "Stopping vmware background services ..."
            killall vmnet-netifup vmnet-natd vmnet-bridge vmware vmplayer \\
              vmware-tray vmnet-dhcpd 2>/dev/null
            # wait for shutting down of interfaces. vmnet needs kinda
            # long
            sleep 1
            unload_modules
            # workaround, because we can kill and unload more as we have
            # started
            rc_reset
            rc_status -v
          ;;
          # we don't need a status yet... at least as long as it is
          # unclear in which path the corresponding binary (see original
          # /etc/init.d/vmware) is in our case
          #status)
          #  echo -n "Say something useful here ..."
          #;;
          restart)
            "\$0" stop
            "\$0" start
          ;;
          *)
            echo "Usage: `basename "\$0"` {start|stop|restart}"
            exit 1
         ;;
        esac
        exit 0
        End-of-Here
    return $script;
}

1;