~ubuntu-branches/ubuntu/quantal/virtinst/quantal-proposed

« back to all changes in this revision

Viewing changes to virtinst/Seclabel.py

  • Committer: Bazaar Package Importer
  • Author(s): Jean-Louis Dupond
  • Date: 2010-05-05 03:32:42 UTC
  • mfrom: (1.3.13 sid)
  • Revision ID: james.westby@ubuntu.com-20100505033242-um6f6pjcc89i07m0
Tags: 0.500.3-1ubuntu1
* Merge from debian unstable. (LP: #590068)  Remaining changes:
  - debian/patches/9001_Ubuntu.patch:
     + Added lucid and maverick to OS list and enable virtio for it.
  - debian/patches/0003-Fix-patch-to-keyboard-configuration.patch: disable
    as the keyboard config in Ubuntu is still in /etc/default/console-setup
    and this was causing virt-manager to always default to a en-us
    keyboard. (LP: #524318)
  - debian/control: added acl package to depends. (LP: #533048)
  - Demote virt-viewer to Suggests, as it's in universe.
  - Recommends libvirt-bin (LP: #215084)
* debian/patches/9002-add-ca-keymap.patch: dropped, its now in upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright 2010  Red Hat, Inc.
 
3
# Cole Robinson <crobinso@redhat.com>
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free  Software Foundation; either version 2 of the License, or
 
8
# (at your option)  any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
18
# MA 02110-1301 USA.
 
19
 
 
20
import CapabilitiesParser
 
21
 
 
22
class Seclabel(object):
 
23
    """
 
24
    Class for generating <seclabel> XML
 
25
    """
 
26
 
 
27
    SECLABEL_TYPE_DYNAMIC = "dynamic"
 
28
    SECLABEL_TYPE_STATIC = "static"
 
29
    SECLABEL_TYPES = [SECLABEL_TYPE_DYNAMIC, SECLABEL_TYPE_STATIC]
 
30
 
 
31
    def __init__(self, conn):
 
32
        self.conn = conn
 
33
        self._caps = CapabilitiesParser.parse(conn.getCapabilities())
 
34
 
 
35
        self._type = self.SECLABEL_TYPE_DYNAMIC
 
36
        self._model = None
 
37
        self._label = None
 
38
        self._imagelabel = None
 
39
 
 
40
        model = self._caps.host.secmodel.model
 
41
        if not model:
 
42
            raise ValueError("Hypervisor does not have any security driver"
 
43
                             "enabled")
 
44
        self.model = model
 
45
 
 
46
    def get_type(self):
 
47
        return self._type
 
48
    def set_type(self, val):
 
49
        if val not in self.SECLABEL_TYPES:
 
50
            raise ValueError("Unknown security type '%s'" % val)
 
51
        self._type = val
 
52
    type = property(get_type, set_type)
 
53
 
 
54
    def get_model(self):
 
55
        return self._model
 
56
    def set_model(self, val):
 
57
        self._model = val
 
58
    model = property(get_model, set_model)
 
59
 
 
60
    def get_label(self):
 
61
        return self._label
 
62
    def set_label(self, val):
 
63
        self._label = val
 
64
    label = property(get_label, set_label)
 
65
 
 
66
    def get_imagelabel(self):
 
67
        return self._imagelabel
 
68
    def set_imagelabel(self, val):
 
69
        self._imagelabel = val
 
70
    imagelabel = property(get_imagelabel, set_imagelabel)
 
71
 
 
72
    def get_xml_config(self):
 
73
        if not self.type or not self.model:
 
74
            raise RuntimeError("Security type and model must be specified")
 
75
 
 
76
        if (self.type == self.SECLABEL_TYPE_STATIC and not self.label):
 
77
            raise RuntimeError("A label must be specified for static "
 
78
                               "security type.")
 
79
 
 
80
        xml = "  <seclabel type='%s' model='%s'>\n" % (self.type, self.model)
 
81
 
 
82
        if self.label:
 
83
            xml += "    <label>%s</label>\n" % self.label
 
84
        if self.imagelabel:
 
85
            xml += "    <imagelabel>%s</imagelabel>\n" % self.imagelabel
 
86
 
 
87
        xml += "  </seclabel>"
 
88
 
 
89
        return xml