1 # Copyright (c) 2011 Nicira Networks.
2 # Copyright (c) 2010 Citrix Systems, Inc.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 from OVEStandard import *
17 from OVELogger import *
25 return [str_recursive(_) for _ in x]
28 for k,v in x.iteritems():
29 out[str_recursive(k)] = str_recursive(v)
34 class OVEConfig(QtCore.QObject):
37 QtCore.QObject.__init__(self)
39 self.logTraffic = True
40 self.truncateUuids = True
45 if cls.instance is None:
46 cls.instance = OVEConfig()
47 cls.instance.loadConfig()
50 def hostFromUuid(self, uuid):
51 for host in self.hosts:
52 if host['uuid'] == uuid:
54 OVELog("+++ Couldn't find host '"+str(uuid)+"' in "+str([x['uuid'] for x in self.hosts]))
58 settings = QtCore.QSettings()
59 settings.setValue('config/hosts', QVariant(ovs.json.to_string((self.hosts))))
60 settings.setValue('config/logTraffic', QVariant(self.logTraffic))
61 settings.setValue('config/truncateUuids', QVariant(self.truncateUuids))
62 settings.setValue('config/ssgList', QVariant(ovs.json.to_string(self.ssgList)))
67 settings = QtCore.QSettings()
68 jsonText = unicode(settings.value('config/hosts', QVariant('[]')).toString())
69 self.hosts = str_recursive(ovs.json.from_string(str(jsonText)))
70 self.logTraffic = settings.value('config/logTraffic', QVariant(False)).toBool()
71 self.truncateUuids = settings.value('config/truncateUuids', QVariant(False)).toBool()
72 jsonText = unicode(settings.value('config/ssgList', QVariant('[]')).toString())
73 self.ssgList = ovs.json.from_string(str(jsonText))
74 if len(self.ssgList) == 0:
87 r'!ff:ff:ff:ff:ff:ff',
90 r'255\.255\.255\.255',
91 r'!255\.255\.255\.255',
100 def emitUpdated(self):
101 self.emit(QtCore.SIGNAL("configUpdated()"))