File: _conn.py

package info (click to toggle)
openipmi 2.0.37-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,100 kB
  • sloc: ansic: 140,279; python: 8,801; sh: 5,723; perl: 5,394; makefile: 490
file content (228 lines) | stat: -rw-r--r-- 6,649 bytes parent folder | download | duplicates (3)
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
# _conn.py
#
# openipmi GUI handling for connections
#
# Author: MontaVista Software, Inc.
#         Corey Minyard <minyard@mvista.com>
#         source@mvista.com
#
# Copyright 2006 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 OpenIPMI
from openipmigui import gui_popup
from openipmigui import gui_SoL

class Port:
    def __init__(self, domain, c, pnum):
        self.c = c
        self.pnum = pnum
        self.ui = c.ui
        self.name = c.d.name + "(" + str(c.cnum) + "." + str(pnum) + ")"

        c.ports[pnum] = self

        self.ui.add_port(c, self)

        # Wait to get activation information
        self.up = False
        self.ui.incr_item_warning(self.treeroot)

        pi = domain.get_port_info(c.cnum, pnum);
        if (pi != None):
            self.ui.set_item_text(self.treeroot, pi)
            pass

        v = [ 0 ]
        rv = domain.is_connection_port_up(c.cnum, pnum, v)
        if (rv == 0):
            self.SetUp(domain, v[0])
        return

    def remove(self):
        self.c = None
        self.ui = None
        return

    def __str__(self):
        return self.name

    def SetUp(self, domain, up):
        pi = domain.get_port_info(self.c.cnum, self.pnum);
        if (pi != None):
            self.ui.set_item_text(self.treeroot, pi)
            pass

        if (up):
            if (not self.up):
                self.ui.decr_item_warning(self.treeroot)
                pass
            pass
        else:
            if (self.up):
                self.ui.incr_item_warning(self.treeroot)
                pass
            pass
        self.up = up
        return

    def IsUp(self):
        return self.up

    pass

class Connection:
    def __init__(self, domain, d, cnum):
        self.d = d
        self.cnum = cnum
        self.ui = d.ui
        self.name = d.name + "(" + str(cnum) + ")"
        self.ports = { }
        self.domain_id = domain.get_id()

        d.connections[cnum] = self

        v = [ 0 ]
        rv = domain.is_connection_active(cnum, v)
        if (rv == 0):
            if (v[0] != 0):
                self.active_str = "active"
                pass
            else:
                self.active_str = "inactive"
                pass
            pass
        else:
            self.active_str = "inactive(" + str(rv) + ")"
            pass

        self.ui.add_connection(d, self)
        self.ui.set_item_text(self.treeroot,
                              (domain.get_connection_type(cnum)
                               + " (" + self.active_str + ")"))

        v = [ 0 ]
        rv = domain.num_connection_ports(cnum, v)
        if (rv == 0):
            num_ports = v[0]
            for i in range(0, num_ports):
                Port(domain, self, i)
                pass
            pass
        self.conup = False
        self.ui.incr_item_severe(self.treeroot)
        return

    def remove(self):
        self.ui = None
        for p in self.ports.values():
            p.remove()
            pass
        self.ports = None
        return
    
    def __str__(self):
        return self.name

    def DoUpdate(self):
        self.op = "checkactive"
        self.domain_id.to_domain(self)
        return
    
    def SetPortUp(self, domain, port, err):
        if (port not in self.ports):
            Port(domain, self, port)
            pass
        if (err == OpenIPMI.enoent):
            self.ui.remove_port(self.ports[port])
            del self.ports[port];
            return
        
        self.ports[port].SetUp(domain, err == 0)
        conup = False
        for p in self.ports.values():
            conup = p.IsUp() or conup
            pass
        if (conup):
            if (not self.conup):
                self.ui.decr_item_severe(self.treeroot)
                pass
            pass
        else:
            if (self.conup):
                self.ui.incr_item_severe(self.treeroot)
                pass
            pass
        self.conup = conup
        return

    def IsPortUp(self, port):
        return self.ports[port].IsUp(port)

    def IsUp(self):
        return self.conup
    
    def HandleMenu(self, event):
        gui_popup.popup(self.ui, event,
                        [ [ "Activate", self.Activate ],
                          [ "Open SOL", self.OpenSOL ] ])
        return

    def Activate(self, event):
        self.op = "activate"
        self.domain_id.to_domain(self)
        return

    def OpenSOL(self, event):
        gui_SoL.SoL(self.ui, self.domain_id, self.cnum)
        return
    
    def domain_cb(self, domain):
        if (self.op == "activate"):
            domain.activate_connection(self.cnum)
        elif (self.op == "checkactive"):
            v = [ 0 ]
            rv = domain.is_connection_active(self.cnum, v)
            if (rv == 0):
                if (v[0] != 0):
                    new_active_str = "active"
                    pass
                else:
                    new_active_str = "inactive"
                    pass
                pass
            else:
                new_active_str = "inactive("+ str(rv) + ")"
                pass

            if (new_active_str != self.active_str):
                self.active_str = new_active_str
                self.ui.set_item_text(self.treeroot,
                                      (domain.get_connection_type(self.cnum)
                                       + " (" + self.active_str + ")"))
                pass
            pass
        return

    pass