Add ovsdbmonitor GUI tool by Andy Southgate, contributed by Citrix.
[sliver-openvswitch.git] / ovsdb / ovsdbmonitor / OVEHostWindow.py
1 # Copyright (c) 2010 Citrix Systems, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from OVEStandard import *
16 from OVELogger import *
17 from Ui_HostWindow import *
18
19 class OVEHostWindow(QtGui.QDialog):
20     DEFAULT_CONNECT_TARGET = 'unix:/var/run/openvswitch/db.sock'
21     def __init__(self, parent, currentValues = None):
22         QtGui.QDialog.__init__(self, parent)
23         self.ui = Ui_HostWindow()
24         self.ui.setupUi(self)
25         self.resize(-1, -1)
26         self.connect(self.ui.buttonBox, QtCore.SIGNAL("clicked(QAbstractButton *)"), self.xon_actionButton_Box_clicked)
27         if currentValues is not None:
28             self.ui.hostAddressEdit.setText(currentValues['address'])
29             self.ui.hostPasswordEdit.setText(currentValues['password'])
30             self.ui.hostConnectTarget.setText(currentValues.get('connectTarget', self.DEFAULT_CONNECT_TARGET))
31             self.uuid = currentValues.get('uuid', str(uuid.uuid4()))
32         else:
33             self.ui.hostConnectTarget.setText(self.DEFAULT_CONNECT_TARGET)
34             self.uuid = str(uuid.uuid4())
35             self.accepted = None
36     
37     def xon_actionButton_Box_clicked(self, button):
38         role = self.ui.buttonBox.buttonRole(button)
39         if role == QtGui.QDialogButtonBox.AcceptRole:
40             self.accepted = True
41             self.close()
42         elif role == QtGui.QDialogButtonBox.RejectRole:
43             self.accepted = False
44             self.close()
45
46     def record(self):
47         return {
48             'accepted' : self.accepted,
49             'uuid' : self.uuid,
50             'address' : str(self.ui.hostAddressEdit.text()),
51             'password' : str(self.ui.hostPasswordEdit.text()),
52             'connectTarget' : str(self.ui.hostConnectTarget.text())
53             }
54