2
# Copyright 2010 Red Hat, Inc.
3
# Cole Robinson <crobinso@redhat.com>
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.
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.
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,
20
import CapabilitiesParser
22
class Seclabel(object):
24
Class for generating <seclabel> XML
27
SECLABEL_TYPE_DYNAMIC = "dynamic"
28
SECLABEL_TYPE_STATIC = "static"
29
SECLABEL_TYPES = [SECLABEL_TYPE_DYNAMIC, SECLABEL_TYPE_STATIC]
31
def __init__(self, conn):
33
self._caps = CapabilitiesParser.parse(conn.getCapabilities())
35
self._type = self.SECLABEL_TYPE_DYNAMIC
38
self._imagelabel = None
40
model = self._caps.host.secmodel.model
42
raise ValueError("Hypervisor does not have any security driver"
48
def set_type(self, val):
49
if val not in self.SECLABEL_TYPES:
50
raise ValueError("Unknown security type '%s'" % val)
52
type = property(get_type, set_type)
56
def set_model(self, val):
58
model = property(get_model, set_model)
62
def set_label(self, val):
64
label = property(get_label, set_label)
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)
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")
76
if (self.type == self.SECLABEL_TYPE_STATIC and not self.label):
77
raise RuntimeError("A label must be specified for static "
80
xml = " <seclabel type='%s' model='%s'>\n" % (self.type, self.model)
83
xml += " <label>%s</label>\n" % self.label
85
xml += " <imagelabel>%s</imagelabel>\n" % self.imagelabel