add delete slice button
authorsmbaker <smbaker@fc8clean.lan>
Tue, 4 Oct 2011 20:38:04 +0000 (13:38 -0700)
committersmbaker <smbaker@fc8clean.lan>
Tue, 4 Oct 2011 20:38:04 +0000 (13:38 -0700)
sface/screens/configscreen.py
sface/sficreate.py
sface/sfiprocess.py

index 3c716ce..5adefa2 100644 (file)
@@ -8,7 +8,7 @@ from sface.screens.sfascreen import SfaScreen
 from sfa.util.version import version_core
 from sface.version import version_dict
 
-from sface.sficreate import CreateWindow
+from sface.sficreate import CreateWindow, RemoveWindow
 
 static_labels = {
     'slice' :  [ 
@@ -93,6 +93,7 @@ class ConfigWidget(QWidget):
         hlayout.addSpacing(10)
 
         hlayout.addStretch()
+        bottom_button ('deleteSlice', 'Delete Slice', Qt.AlignRight),
         bottom_button ('createSlice', 'Create New Slice', Qt.AlignRight),
         bottom_button ('apply','Apply Only',Qt.AlignRight),
         bottom_button ('save','Apply && Save',Qt.AlignRight)
@@ -111,6 +112,10 @@ class ConfigWidget(QWidget):
             self.slice.setText(dlg.getHrn())
             self.save()
 
+    def deleteSlice(self):
+        dlg = RemoveWindow(hrn = config.getSlice(), parent=self)
+        dlg.exec_()
+
     def apply(self):
         for field in config.fields():
             widget=getattr(self,field)
index 70dd900..adfba55 100644 (file)
@@ -145,3 +145,69 @@ class CreateWindow(QDialog):
         self.userView.hideUnusableColumns()
         self.userView.resizeColumnToContents(0)
 
+class RemoveWindow(QDialog):
+    def __init__(self, hrn, parent=None):
+        super(RemoveWindow, self).__init__(parent)
+        self.setWindowTitle("Remove Slice")
+
+        hrnLabel = QLabel("Slice HRN:")
+        self.hrnEdit = QLineEdit()
+        self.status = QLabel("")
+        self.status.setMaximumWidth(640)
+
+        if hrn:
+            self.hrnEdit.setText(hrn)
+
+        self.buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
+        self.buttonBox.button(QDialogButtonBox.Ok).setDefault(True)
+
+        layout = QVBoxLayout()
+        layout.addWidget(hrnLabel)
+        layout.addWidget(self.hrnEdit)
+        layout.addWidget(self.status)
+        layout.addWidget(self.buttonBox)
+        self.setLayout(layout)
+
+        self.userModel = UserModel(parent=self)
+
+        self.connect(self.buttonBox, SIGNAL("accepted()"), self, SLOT("accept()"))
+        self.connect(self.buttonBox, SIGNAL("rejected()"), self, SLOT("reject()"))
+
+    def accept(self):
+        hrn = self.hrnEdit.text()
+
+        box = QMessageBox(parent=self)
+        box.setText("Confirm deletion of slice %s ?" % hrn)
+        box.setStandardButtons(QMessageBox.Yes | QMessageBox.No)
+        ret = box.exec_()
+        if (ret != QMessageBox.Yes):
+            return
+
+        self.setStatus("Removing Slice...")
+
+        self.removeProcess = SfiProcess(self)
+        self.connect(self.removeProcess, SIGNAL('finished()'), self.removeFinished)
+
+        self.buttonBox.setEnabled(False)
+
+        self.removeProcess.removeRecord(hrn)
+
+    def setStatus(self, x):
+        self.status.setText(x)
+
+    def removeFinished(self):
+        faultString = self.removeProcess.getFaultString()
+        if not faultString:
+            self.setStatus("<font color='green'>Slice removed.</font>")
+            self.sliceWasCreated = True
+            self.buttonBox.setEnabled(True)
+            self.buttonBox.clear()
+            self.buttonBox.addButton(QDialogButtonBox.Close)
+        else:
+            self.setStatus("<font color='red'>Slice removal failed: %s</font>" % (faultString))
+            self.buttonBox.setEnabled(True)
+
+        self.disconnect(self.removeProcess, SIGNAL('finished()'), self.removeFinished)
+        self.removeProcess = None
+
+
index cfa1109..872fa5a 100644 (file)
@@ -200,6 +200,12 @@ class SfiProcess(QObject):
         self.__init_command(args)
         self.start()
 
+    def removeRecord(self, hrn):
+        args = ["-u", config.getUser(), "-a", config.getAuthority(),
+                "-r", config.getRegistry(), "-s", config.getSlicemgr(), "remove", hrn]
+        self.__init_command(args)
+        self.start()
+
     def renewSlivers(self, expiration, slice=None):
         if not slice:
             slice = config.getSlice()