[PC-BSD Commits] r18305 - pcbsd/current/src-qt4/warden-gui

svn at pcbsd.org svn at pcbsd.org
Tue Aug 7 10:59:19 PDT 2012


Author: kris
Date: 2012-08-07 17:59:19 +0000 (Tue, 07 Aug 2012)
New Revision: 18305

Modified:
   pcbsd/current/src-qt4/warden-gui/dialogwarden.cpp
   pcbsd/current/src-qt4/warden-gui/dialogwarden.h
   pcbsd/current/src-qt4/warden-gui/dialogwarden.ui
Log:

Add new GUI elements to ZFS snapshots, which allow user to enable automated
snapshot creation via cron. 



Modified: pcbsd/current/src-qt4/warden-gui/dialogwarden.cpp
===================================================================
--- pcbsd/current/src-qt4/warden-gui/dialogwarden.cpp	2012-08-07 17:27:42 UTC (rev 18304)
+++ pcbsd/current/src-qt4/warden-gui/dialogwarden.cpp	2012-08-07 17:59:19 UTC (rev 18305)
@@ -97,6 +97,12 @@
    connect( pushRemoveSnap, SIGNAL(clicked()), this, SLOT(slotRemoveSnap() ) );
    //connect( sliderSnaps, SIGNAL(sliderMoved(int)), this, SLOT(slotSnapSliderChanged(int) ) );
    connect( sliderSnaps, SIGNAL(valueChanged(int)), this, SLOT(slotSnapSliderChanged(int) ) );
+
+   // Snapshot cron support
+   connect( comboSnapFrequency, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCronSnapshotChanged() ) );
+   connect( spinSnapDays, SIGNAL(valueChanged(int)), this, SLOT(slotCronSnapshotChanged() ) );
+   connect( groupSnapSchedule, SIGNAL(clicked(bool)), this, SLOT(slotCronSnapshotChanged() ) );
+
    QTimer::singleShot(100, this, SLOT(slotCheckNic()) );
 
    // Disable the start button until status's come back
@@ -1154,6 +1160,7 @@
         QTimer::singleShot(50, this, SLOT(slotLoadSnapshots()) );
      } else {
 	groupSnaps->setEnabled(false); 
+	groupSnapSchedule->setEnabled(false); 
 	labelSnap->setText(tr("For snapshot support you must be using ZFS"));
      }
 
@@ -1168,9 +1175,43 @@
    if ( ! listJails->currentItem() )
       return;
 
+   bool ok, ok2;
+
    groupSnaps->setEnabled(false); 
+   groupSnapSchedule->setEnabled(false); 
    labelSnap->setText(tr("Loading snapshots..."));
+   disconnect(spinSnapDays, SIGNAL(valueChanged(int)), 0, 0);
+   disconnect(comboSnapFrequency, SIGNAL(currentIndexChanged(int)), 0, 0);
+   // Load the snapshot schedule
+   QFile file(JailDir + "/." + listJails->currentItem()->text(0) + ".meta/cron" );
+   if ( file.exists() && file.open( QIODevice::ReadOnly ) ) {
+      QTextStream streamfreq( &file );
+      if ( streamfreq.readLine().simplified() == "hourly" )
+         comboSnapFrequency->setCurrentIndex(1);
+      else
+         comboSnapFrequency->setCurrentIndex(0);
+      file.close();
 
+     // Now see how many are set to keep
+     QFile file2(JailDir + "/." + listJails->currentItem()->text(0) + ".meta/cron-keep" );
+     if ( file2.exists() && file2.open( QIODevice::ReadOnly ) ) {
+        QTextStream streamkeep( &file2 );
+	int keep = streamkeep.readLine().toInt(&ok);
+        if ( ok )
+            spinSnapDays->setValue(keep);
+     }
+     groupSnapSchedule->setChecked(true); 
+   } else {
+     comboSnapFrequency->setCurrentIndex(0);
+     spinSnapDays->setValue(10);
+     groupSnapSchedule->setChecked(false); 
+   }
+
+   groupSnapSchedule->setEnabled(true); 
+   connect( comboSnapFrequency, SIGNAL(currentIndexChanged(int)), this, SLOT(slotCronSnapshotChanged() ) );
+   connect( spinSnapDays, SIGNAL(valueChanged(int)), this, SLOT(slotCronSnapshotChanged() ) );
+   // Done loading snapshot schedule
+
    QString IP = listJails->currentItem()->text(0);
 
    // Grab the ZFS snapshot list
@@ -1189,7 +1230,6 @@
 
    snapshotList.clear();
    QString tmp;
-   bool ok, ok2;
 
    qDebug() << "Getting ZFS snapshots for " + IP;
 
@@ -1303,7 +1343,7 @@
    QDate date = QDate::fromString(time.section("-", 0, 0), "yyyyMMdd");
    QTime timestr = QTime::fromString(time.section("-", 1, 1), "hhmmss");
    
-   return QString(date.toString("ddd MMMM d',' yyyy") + " @ " + timestr.toString("h:m:s ap"));
+   return QString(date.toString("ddd MMMM d',' yyyy") + " @ " + timestr.toString("h:mm:ss ap"));
 }
 
 void dialogWarden::slotCurrentJailChanged()
@@ -1641,3 +1681,27 @@
     // Unhide the close button
     dialogOutput->setCloseHide(FALSE);
 }
+
+void dialogWarden::slotCronSnapshotChanged()
+{
+   QString IP = listJails->currentItem()->text(0);
+
+   if ( groupSnapSchedule->isChecked() ) {
+     qDebug() << "Enabling cron snapshots";
+     QProcess m;
+     m.start(QString("warden"), QStringList() << "zfscronsnap" << IP << "start" << comboSnapFrequency->currentText() << QString::number(spinSnapDays->value()) );
+     while(m.state() == QProcess::Starting || m.state() == QProcess::Running) {
+        m.waitForFinished(200);
+        QCoreApplication::processEvents();
+     }
+   } else {
+     qDebug() << "Disabling cron snapshots";
+     QProcess m;
+     m.start(QString("warden"), QStringList() << "zfscronsnap" << IP << "stop" );
+     while(m.state() == QProcess::Starting || m.state() == QProcess::Running) {
+        m.waitForFinished(200);
+        QCoreApplication::processEvents();
+     }
+   }
+
+}

Modified: pcbsd/current/src-qt4/warden-gui/dialogwarden.h
===================================================================
--- pcbsd/current/src-qt4/warden-gui/dialogwarden.h	2012-08-07 17:27:42 UTC (rev 18304)
+++ pcbsd/current/src-qt4/warden-gui/dialogwarden.h	2012-08-07 17:59:19 UTC (rev 18305)
@@ -83,6 +83,7 @@
     void slotLoadClones();
     void slotAddClone();
     void slotRemoveClone();
+    void slotCronSnapshotChanged();
 
 private:
     void refreshJailDetailsView();

Modified: pcbsd/current/src-qt4/warden-gui/dialogwarden.ui
===================================================================
(Binary files differ)



More information about the Commits mailing list