KVM SR: Remove brain overhead of having a dict created from another dict.
[slapos.git] / slapos / recipe / kvm / __init__.py
1 ##############################################################################
2 #
3 # Copyright (c) 2011 Vifib SARL and Contributors. All Rights Reserved.
4 #
5 # WARNING: This program as such is intended to be used by professional
6 # programmers who take the whole responsibility of assessing all potential
7 # consequences resulting from its eventual inadequacies and bugs
8 # End users who are looking for a ready-to-use solution with commercial
9 # guarantees and support are strongly adviced to contract a Free Software
10 # Service Company
11 #
12 # This program is Free Software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License
14 # as published by the Free Software Foundation; either version 3
15 # of the License, or (at your option) any later version.
16 #
17 # This program is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write to the Free Software
24 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #
26 ##############################################################################
27 from slapos.recipe.librecipe import GenericBaseRecipe
28 import os
29 import sys
30
31 class Recipe(GenericBaseRecipe):
32 """
33 kvm instance configuration.
34 """
35 def install(self):
36 # Sanitize drive type parameter
37 self.options.setdefault('disk-type', 'virtio')
38 if not self.options.get('disk-type') in ['ide', 'scsi', 'sd',
39 'mtd', 'floppy', 'pflash', 'virtio']:
40 print 'Warning: "disk-type" parameter is not in allowed values. Using ' \
41 '"virtio" value.'
42 self.options['disk-type'] = 'virtio'
43
44 self.options['python-path'] = sys.executable
45
46 path_list = []
47
48 if not self.isTrueValue(self.options.get('use-tap')):
49 # XXX This could be done using Jinja.
50 for port in self.options['nat-rules'].split():
51 ipv6_port = int(port) + 10000
52 tunnel_path = self.createExecutable(
53 '%s-%sto%s' % (self.options['6tunnel-wrapper-path'], port, ipv6_port),
54 self.substituteTemplate(
55 self.getTemplateFilename('6to4.in'),
56 {
57 'ipv6': self.options['ipv6'],
58 'ipv6_port': ipv6_port,
59 'ipv4': self.options['ipv4'],
60 'ipv4_port': port,
61 'shell_path': self.options['shell-path'],
62 '6tunnel_path': self.options['6tunnel-path'],
63 },
64 ),
65 )
66 path_list.append(tunnel_path)
67
68 runner_path = self.createExecutable(
69 self.options['runner-path'],
70 self.substituteTemplate(self.getTemplateFilename('kvm_run.in'),
71 self.options))
72 path_list.append(runner_path)
73
74 controller_path = self.createExecutable(
75 self.options['controller-path'],
76 self.substituteTemplate(self.getTemplateFilename('kvm_controller_run.in'),
77 self.options))
78
79
80 return path_list