File: gui_domainDialog.py

package info (click to toggle)
openipmi 2.0.7-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 10,200 kB
  • ctags: 14,662
  • sloc: ansic: 126,919; sh: 9,454; python: 6,885; perl: 5,838; makefile: 507
file content (345 lines) | stat: -rw-r--r-- 11,199 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# _domainDialog.py
#
# Prompts for creating a domain in the openipmi GUI
#
# Author: MontaVista Software, Inc.
#         Corey Minyard <minyard@mvista.com>
#         source@mvista.com
#
# Copyright 2005 MontaVista Software Inc.
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU Lesser General Public License
#  as published by the Free Software Foundation; either version 2 of
#  the License, or (at your option) any later version.
#
#
#  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
#  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
#  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
#  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
#  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
#  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
#  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with this program; if not, write to the Free
#  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
import Tix
import OpenIPMI
import _domain
import gui_errstr

authtypes = [ 'default', 'none', 'md2', 'md5', 'straight', 'rmcp+' ]
privileges = [ 'default', 'callback', 'user', 'operator', 'admin', 'oem' ]
auth_algs = [ 'default', 'rakp_none', 'rakp_hmac_sha1', 'rakp_hmac_md5' ]
integ_algs = [ 'default', 'none', 'hmac_sha1', 'hmac_md5', 'md5' ]
conf_algs = [ 'default', 'none', 'aes_cbc_128', 'xrc4_128', 'xrc4_40' ]

class EnumHolder:
    def __init__(self):
        self.value = ""
        return

    def get(self):
        return self.value

    def set(self, val):
        self.value = val

    def SelectType(self, newbutton, selected):
        if (selected == "0"):
            return
        self.value = newbutton
        return
    
    pass

class ConnTypeInfo(Tix.Frame):
    def __init__(self, contype, parent):
        Tix.Frame.__init__(self, parent)
        self.contype = contype
        self.fields = [ ]

        args = OpenIPMI.alloc_empty_args(str(contype))
        self.args = args

        self.errstr = gui_errstr.ErrStr(self)
        self.errstr.pack(side=Tix.TOP, fill=Tix.X, expand=1)

        i = 0
        rv = 0
        frame = None
        while (rv == 0):
            name = [ "" ]
            vtype = [ "" ]
            vrange = [ "" ]
            vhelp = [ "" ]
            value = [ "" ]
            rv = args.get_val(i, name, vtype, vhelp, value, vrange)
            if (rv == 0):
                if (vhelp[0][0] == '*'):
                    optional = False
                    vhelp[0] = vhelp[0][1:]
                else:
                    optional = True
                    pass
                if (vhelp[0][0] == '!'):
                    password = True
                    vhelp[0] = vhelp[0][1:]
                else:
                    password = False
                    pass
                
                if (vtype[0] == "bool"):
                    if (frame == None):
                        didframe = True
                        frame = Tix.Frame(self)
                        frame.pack(side=Tix.TOP)
                        newframe = frame
                        pass
                    else:
                        newframe = None
                        pass
                    fw = Tix.BooleanVar()
                    w = Tix.Checkbutton(frame, text=name[0], variable=fw)
                    w.pack(side=Tix.LEFT, padx=10)
                    if ((value[0] != None) and (value[0] == "true")):
                        fw.set(True)
                        pass
                    pass
                elif (vtype[0] == "enum"):
                    do_box = False
                    fw = EnumHolder()
                    if (value[0] != None):
                        fw.set(value[0])
                        pass
                    else:
                        fw.set(vrange[0])
                        pass
                    w = Tix.Select(self, label=name[0], allowzero=0, radio=1,
                                   command=fw.SelectType)
                    for v in vrange:
                        w.add(v, text=v)
                        pass
                    newframe = None
                    w.invoke(fw.get())
                    w.pack()
                    pass
                elif (vtype[0] == "str"):
                    if (frame == None):
                        didframe = True
                        frame = Tix.Frame(self)
                        frame.pack(side=Tix.TOP)
                        newframe = frame
                        pass
                    else:
                        newframe = None
                        pass

                    if (value[0] == None):
                        value[0] = ""
                        pass
                    if (password):
                        options="entry.show '*' entry.width 20"
                    else:
                        options="entry.width 20"
                        pass
                    w = Tix.LabelEntry(frame, label=name[0], options=options)
                    w.pack(side=Tix.LEFT, padx=10)
                    fw = w.entry
                    pass
                else:
                    continue
                frame = newframe
                self.fields.append( (i, name[0], vtype[0], fw) )
                pass
            i += 1
            pass
        return

    def SetupArgs(self):
        self.errstr.SetError("")
        args = self.args
        for f in self.fields:
            idx = f[0]
            vtype = f[2]
            fw = f[3]
            if (vtype == "bool"):
                if (fw.get()):
                    val = "true"
                else:
                    val = "false"
                    pass
                pass
            elif (vtype == "enum"):
                val = str(fw.get())
                pass
            elif (vtype == "str"):
                val = str(fw.get())
                if (val == ""):
                    val = None
                    pass
                pass
            else:
                continue
            rv = args.set_val(idx, None, val);
            if (rv != 0):
                self.errstr.SetError("Error setting field " + f[1] + ": "
                                     + OpenIPMI.get_error_string(rv))
                raise Exception()
            pass
        return args

    def Cleanup(self):
        self.args = None
        return

    pass

class ConnInfo(Tix.ScrolledWindow):
    def __init__(self, parent, mainhandler, enable=True):
        self.contypes = { }
        OpenIPMI.parse_args_iter_help(self)
        if (len(self.contypes) == 0):
            return
        
        Tix.ScrolledWindow.__init__(self, parent, height=300, width=600)
        self.parent = parent
        self.enable = enable;

        if (not enable):
            self.enablevar = Tix.BooleanVar()
            self.enable_box = Tix.Checkbutton(self.window, text="Enable",
                                              variable=self.enablevar)
            self.enable_box.pack(side=Tix.TOP)
            pass

        self.contype = Tix.Select(self.window, label="Connection Type",
                                  radio=1, allowzero=0,
                                  command=self.selectType)
        for key in self.contypes.keys():
            self.contype.add(key, text=key)
            pass
        self.contype.pack(side=Tix.TOP)

        self.coninfos = [ ]

        show = True
        panel = Tix.Frame(self.window)
        panel.pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
        for ct in self.contypes.keys():
            cti = ConnTypeInfo(ct, panel)
            if (show):
                cti.pack()
                self.currcon = cti
                show = False
                pass
            self.coninfos.append(cti)
            pass

        self.contype.invoke(self.contypes.keys()[0])
        return

    def parse_args_iter_help_cb(self, name, help):
        self.contypes[name] = help
        return

    def selectType(self, newbutton, selected):
        if (selected == "0"):
            return
        self.currcon.pack_forget()
        for cti in self.coninfos:
            if (newbutton == cti.contype):
                self.currcon = cti;
                cti.pack()
                pass
            pass
        return

    def FillinConn(self):
        if (not self.enable):
            if (not self.enablevar.get()):
                return None
            pass
        return self.currcon.SetupArgs()

    def Cleanup(self):
        for cti in self.coninfos:
            cti.Cleanup()
            pass
        self.currcon = None
        return

    pass

class OpenDomainDialog(Tix.Toplevel):
    def __init__(self, mainhandler):
        Tix.Toplevel.__init__(self)
        self.title("Domain Creation Dialog")
        
        self.mainhandler = mainhandler

        self.name = Tix.LabelEntry(self, label="Domain name")
        self.name.pack(side=Tix.TOP, fill=Tix.X, expand=1)

        bbox = Tix.ButtonBox(self)
        bbox.add("cancel", text="Cancel", command=lambda w=self: w.cancel())
        bbox.add("ok", text="Ok", command=lambda w=self: w.ok())
        bbox.pack(side=Tix.BOTTOM, fill=Tix.X, expand=1)

        self.status = gui_errstr.ErrStr(self)
        self.status.pack(side=Tix.BOTTOM, fill=Tix.X, expand=1)

        self.conn = [ ConnInfo(self, mainhandler),
                      ConnInfo(self, mainhandler, False) ]
        self.conn[0].pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
        self.conn[1].pack(side=Tix.TOP, fill=Tix.BOTH, expand=1)
        self.name.entry.focus()

        self.bind("<Destroy>", self.OnDestroy)

        return

    def OnDestroy(self, event):
        # This doesn't get cleaned up properly by Python til after
        # exit, but we need to make sure the args get freed now, or
        # it won't be freed until after the OS handler is destroyed.
        for c in self.conn:
            c.Cleanup()
            pass
        return
    
    def cancel(self):
        self.destroy()
        return

    def ok(self):
        self.status.SetError("")
        name = str(self.name.entry.get())
        if (name == ""):
            self.status.SetError("No name specified")
            return
        try:
            args = [ self.conn[0].FillinConn() ]
            arg = self.conn[1].FillinConn()
            if (arg != None):
                args.append(arg);
                pass
            pass
        except:
            self.status.SetError("Error handling connection arguments")
            return
        domain_id = OpenIPMI.open_domain3(name, [], args, None, None)
        if (domain_id == None):
            self.status.SetError("Error opening domain")
            return

        self.destroy()
        return

    pass