__init__.py 3.12 KB
Newer Older
Łukasz Nowak's avatar
Łukasz Nowak committed
1 2
##############################################################################
#
3
# Copyright (c) 2011 Vifib SARL and Contributors. All Rights Reserved.
Łukasz Nowak's avatar
Łukasz Nowak committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
##############################################################################
27
from slapos.recipe.librecipe import GenericBaseRecipe
Łukasz Nowak's avatar
Łukasz Nowak committed
28 29
import os
import sys
30

31 32 33 34 35
class Recipe(GenericBaseRecipe):
  """
  kvm instance configuration.
  """
  def install(self):
36 37 38 39 40 41 42 43
    # Sanitize drive type parameter
    self.options.setdefault('disk-type', 'virtio')
    if not self.options.get('disk-type') in ['ide', 'scsi', 'sd',
        'mtd', 'floppy', 'pflash', 'virtio']:
      print 'Warning: "disk-type" parameter is not in allowed values. Using ' \
          '"virtio" value.'
      self.options['disk-type'] = 'virtio'

44
    self.options['python-path'] = sys.executable
45

46 47
    path_list = []

48
    if self.isTrueValue(self.options.get('use-nat')):
49 50
      # XXX This could be done using Jinja.
      for port in self.options['nat-rules'].split():
51
        tunnel_port = int(port) + 10000
52
        tunnel_path = self.createExecutable(
53
            '%s-%s' % (self.options['6tunnel-wrapper-path'], tunnel_port),
54 55 56 57
            self.substituteTemplate(
                self.getTemplateFilename('6to4.in'),
                {
                    'ipv6': self.options['ipv6'],
58
                    'ipv6_port': tunnel_port,
59
                    'ipv4': self.options['ipv4'],
60
                    'ipv4_port': tunnel_port,
61 62 63 64 65 66
                    'shell_path': self.options['shell-path'],
                    '6tunnel_path': self.options['6tunnel-path'],
                },
            ),
        )
        path_list.append(tunnel_path)
67

68 69 70
    runner_path = self.createExecutable(
        self.options['runner-path'],
        self.substituteTemplate(self.getTemplateFilename('kvm_run.in'),
71
                                self.options))
72 73
    path_list.append(runner_path)

74 75 76
    controller_path = self.createExecutable(
      self.options['controller-path'],
      self.substituteTemplate(self.getTemplateFilename('kvm_controller_run.in'),
77
                              self.options))
78 79


80
    return path_list