00001 from GUIcreatePorts import *
00002 from objectclasses import *
00003
00004
00005 DEVICE_NAME = 0
00006 PORT_NR = 1
00007 PORT_TYPE = 2
00008 PORT_WAY = 3
00009 PORT_SPEED = 4
00010 PXI = 5
00011 ADM_STATUS = 6
00012 PHY = 7
00013 MAC_ADRESS = 8
00014 IP_ADRESS = 9
00015 SUBNET = 10
00016 IP_NAME = 11
00017 BIA = 12
00018 PORTID = 13
00019 MODIFIED = 14
00020 MODIFIED_PARAMS = 15
00021 OLD_IP = 16
00022 SAVE_STATUS = 17
00023
00024 class createPortsWindow(GUIcreatePort):
00025 def __init__(self, main, devicetypeobj, devicename, portlist, parent = None):
00026 GUIcreatePort.__init__(self,parent,"Create Ports",0,0)
00027 self.connect(self.addportbutton,SIGNAL("released()"),self.OnAddPort)
00028 self.connect(self.removebutton,SIGNAL("released()"),self.OnDeleteRow)
00029 self.connect(self.okbutton,SIGNAL("released()"),self.accept)
00030 self.connect(self.cancelbutton,SIGNAL("released()"),self.reject)
00031
00032 self.main = main
00033 self.table.hideColumn(SAVE_STATUS)
00034 self.maxPortsIn = devicetypeobj.GetPortsIn()
00035 self.maxPortsOut = devicetypeobj.GetPortsOut()
00036
00037 self.devicename.setText(devicename)
00038 self.devicename.setEnabled(False)
00039 self.portid.setText('-1')
00040 self.portid.setEnabled(False)
00041 self.phy.insertItem('')
00042 self.phy.insertItem('SX')
00043 self.phy.insertItem('T')
00044 self.phy.insertItem('SL')
00045
00046 self.portlist = portlist
00047 self.deletedports = []
00048 self.NewFreePorts = [[],[]]
00049
00050 self.table.setReadOnly(True)
00051 for i in range(len(self.portlist)):
00052 port = self.portlist[i]
00053 self.insertInTable(i,port)
00054
00055
00056
00057
00058
00059 def OnAddPort(self):
00060
00061
00062
00063
00064 if self.portwayOUT.isChecked(): portway = 2
00065 elif self.portwayIN.isChecked(): portway = 1
00066 else:
00067 self.main.ShowError("You should choose a port way",ERR_ERROR,True)
00068 return
00069
00070 if (self.portnumber.value() > self.maxPortsIn-1 and portway==1) or (self.portnumber.value() > self.maxPortsOut-1 and portway==2):
00071 self.main.ShowError("Invalid port number : \nport number should not exceed %d for Inputs and %d for Outputs. \n Port's number begins at zero."%(self.maxPortsIn-1,self.maxPortsOut-1),ERR_ERROR,True)
00072 return
00073
00074 tmp_port = Port('',str(self.portnumber.value()),str(self.porttype.text()), portway, str(self.devicename.text()) )
00075 tmp_port.SetBia(str(self.bia.text()))
00076 tmp_port.SetMAC(str(self.macadress.text()))
00077 tmp_port.SetPortSpeed(self.portspeed.value())
00078 tmp_port.SetPhy(str(self.phy.currentText()))
00079 tmp_port.SetPXIBooting(int(self.pxibooting.isChecked()))
00080 tmp_port.SetIP(str(self.ipadress.text()))
00081 tmp_port.SetAdmStatus(int(self.admstatus.isChecked()))
00082 tmp_port.SetIPName(str(self.ipname.text()))
00083 tmp_port.SetSubnet(str(self.subnetadress.text()))
00084
00085 if self.find(tmp_port)>0:
00086 self.main.ShowError("Port already exist ",ERR_ERROR,True)
00087 return
00088
00089 tmp_port.SetSaveStatus(CREATE)
00090 self.insertInTable(0,tmp_port)
00091 self.portlist.insert(0,tmp_port)
00092 if portway==1:
00093 self.NewFreePorts[0].insert(0,tmp_port)
00094 else:
00095 self.NewFreePorts[1].insert(0,tmp_port)
00096
00097 def GetNewFreePorts(self):
00098 return self.NewFreePorts
00099
00100 def GetPorts(self):
00101 return self.portlist
00102
00103 def GetDeletedPorts(self):
00104 return self.deletedports
00105
00106 def OnDeleteRow(self):
00107
00108 toDeleteIndex = self.table.currentRow()
00109 self.table.selectRow(toDeleteIndex)
00110 ans = QMessageBox.question(self,"Remove?","Are you sur you want to remove this port ?","Yes","No","",0,1)
00111 if ans == 1:
00112 return
00113
00114 portToDelete = (int(str(self.table.text(toDeleteIndex,PORT_NR))), int(str(self.table.text(toDeleteIndex,PORT_WAY))))
00115 index = self.find(portToDelete)
00116 if index < 0:
00117 print "ERROR : port not found"
00118 return
00119 if int(str(self.table.text(index,SAVE_STATUS))) == CREATE:
00120 self.portlist.remove(self.portlist[index])
00121 else:
00122
00123 self.deletedports.append(self.portlist[index])
00124 self.portlist.remove(self.portlist[index])
00125
00126 self.table.removeRow(toDeleteIndex)
00127
00128
00129
00130
00131
00132 def find(self,port):
00133 if self.portlist == []:
00134 return -1
00135 if isinstance(port,Port):
00136 port = (int(port.GetPortNbr()), port.GetPortWay())
00137 match = ( (int(self.portlist[0].GetPortNbr()), self.portlist[0].GetPortWay()) == port )
00138 i = 0
00139 while ( not match and i<len(self.portlist)-1 ):
00140 i += 1
00141 match = ( (int(self.portlist[i].GetPortNbr()), self.portlist[i].GetPortWay()) == port )
00142 if match:
00143 return i
00144 else:
00145 return -1
00146
00147 def insertInTable(self,row,port):
00148 self.table.insertRows(row)
00149 self.table.setText( row, DEVICE_NAME,port.GetDevice());
00150 self.table.setText( row, PORT_NR,port.GetPortNbr());
00151 self.table.setText( row, PORT_TYPE,port.GetPortType());
00152 self.table.setText( row, PORT_WAY, str(port.GetPortWay()) );
00153 self.table.setText( row, PORT_SPEED,str(port.GetPortSpeed()));
00154 self.table.setText( row, PXI, str(port.GetPXIBooting()) );
00155 self.table.setText( row, ADM_STATUS, str(port.GetAdmStatus()) );
00156 self.table.setText( row, PHY,port.GetPhy());
00157 self.table.setText( row, MAC_ADRESS,port.GetMAC());
00158 self.table.setText( row, IP_ADRESS,port.GetIP());
00159 self.table.setText( row, SUBNET,port.GetSubnet());
00160 self.table.setText( row, IP_NAME,port.GetIPName().replace('\n',' '));
00161 self.table.setText( row, BIA,port.GetBia());
00162 self.table.setText( row, PORTID, str(port.GetPortID()) );
00163 print port.GetSaveStatus()
00164 self.table.setText( row, SAVE_STATUS, str(port.GetSaveStatus()) );
00165
00166
00167
00168