Changeset b22b3a5


Ignore:
Timestamp:
Oct 23, 2013 10:09:58 AM (6 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1
Children:
dfb8c89
Parents:
b62e8c4
Message:

Add the ability to scan the network for hosts with SSH availability (port 22) to the Configuration UI. If it works, I will add the same thing to the LPWizard.

Location:
src-qt4/life-preserver/lp-gui
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/life-preserver/lp-gui/LPConfig.cpp

    r6a2483b rb22b3a5  
    1313  connect(ui->tool_apply,SIGNAL(clicked()), this,SLOT(slotApplyChanges()) ); 
    1414  connect(ui->tool_cancel,SIGNAL(clicked()), this, SLOT(slotCancelConfig()) ); 
     15  connect(ui->push_scanNetwork, SIGNAL(clicked()), this, SLOT(autoDetectReplicationTargets()) ); 
    1516} 
    1617 
     
    170171  ui->time_local_daily->setVisible( (index == 0) ); 
    171172} 
     173 
     174void LPConfig::autoDetectReplicationTargets(){ 
     175  QStringList targs = LPGUtils::scanNetworkSSH(); // <name>:::<address>:::<port> 
     176  if(targs.isEmpty()){ 
     177    QMessageBox::warning(this,tr("No Network Targets"), tr("We could not find any systems on the local network with SSH availability (port 22)") ); 
     178    return; 
     179  } 
     180  //Ask the user to select a target 
     181  QStringList targets; 
     182  for(int i=0; i<targs.length(); i++){ 
     183    targets << targs[i].section(":::",0,0); 
     184  } 
     185  bool ok; 
     186  QString target = QInputDialog::getItem(this, tr("Select Replication Target"), tr("Hostname:"), targets, 0, false, &ok); 
     187  if(!ok || target.isEmpty() ){ return; } //cancelled 
     188  //Now look for that target in the list of info 
     189  for(int i=0; i<targs.length(); i++){ 
     190    if(targs[i].startsWith(target+":::")){ 
     191      ui->lineHostName->setText(targs[i].section(":::",1,1)); 
     192      ui->spinPort->setValue( targs[i].section(":::",2,2).toInt() ); 
     193      break; 
     194    } 
     195  } 
     196} 
  • src-qt4/life-preserver/lp-gui/LPConfig.h

    r6a2483b rb22b3a5  
    55#include <QString> 
    66#include <QDebug> 
     7#include <QMessageBox> 
     8#include <QInputDialog> 
    79 
    810#include "LPBackend.h" 
     11#include "LPGUtils.h" 
    912 
    1013namespace Ui{ 
     
    3538        void slotCancelConfig(); 
    3639        void on_combo_local_schedule_currentIndexChanged(int); 
     40        void autoDetectReplicationTargets(); 
    3741}; 
    3842 
  • src-qt4/life-preserver/lp-gui/LPConfig.ui

    r6a2483b rb22b3a5  
    77    <x>0</x> 
    88    <y>0</y> 
    9     <width>374</width> 
    10     <height>327</height> 
     9    <width>372</width> 
     10    <height>353</height> 
    1111   </rect> 
    1212  </property> 
     
    4242    <widget class="QTabWidget" name="tabWidget"> 
    4343     <property name="currentIndex"> 
    44       <number>0</number> 
     44      <number>1</number> 
    4545     </property> 
    4646     <widget class="QWidget" name="tab_local"> 
     
    176176         </property> 
    177177         <layout class="QVBoxLayout" name="verticalLayout_3"> 
     178          <item> 
     179           <layout class="QHBoxLayout" name="horizontalLayout_9"> 
     180            <item> 
     181             <spacer name="horizontalSpacer_5"> 
     182              <property name="orientation"> 
     183               <enum>Qt::Horizontal</enum> 
     184              </property> 
     185              <property name="sizeHint" stdset="0"> 
     186               <size> 
     187                <width>40</width> 
     188                <height>20</height> 
     189               </size> 
     190              </property> 
     191             </spacer> 
     192            </item> 
     193            <item> 
     194             <widget class="QPushButton" name="push_scanNetwork"> 
     195              <property name="text"> 
     196               <string>Scan Network</string> 
     197              </property> 
     198              <property name="icon"> 
     199               <iconset resource="lPreserve.qrc"> 
     200                <normaloff>:/images/network-wired.png</normaloff>:/images/network-wired.png</iconset> 
     201              </property> 
     202             </widget> 
     203            </item> 
     204            <item> 
     205             <spacer name="horizontalSpacer_4"> 
     206              <property name="orientation"> 
     207               <enum>Qt::Horizontal</enum> 
     208              </property> 
     209              <property name="sizeHint" stdset="0"> 
     210               <size> 
     211                <width>40</width> 
     212                <height>20</height> 
     213               </size> 
     214              </property> 
     215             </spacer> 
     216            </item> 
     217           </layout> 
     218          </item> 
    178219          <item> 
    179220           <layout class="QHBoxLayout" name="horizontalLayout_8"> 
  • src-qt4/life-preserver/lp-gui/LPGUtils.cpp

    r6a2483b rb22b3a5  
    253253  return devs; 
    254254} 
     255 
     256QStringList LPGUtils::scanNetworkSSH(){ 
     257  //Output format: <name>:::<address>::::<port> 
     258  QStringList out; 
     259  QStringList netout = LPBackend::getCmdOutput("avahi-browse -art"); 
     260  for(int i=0; i<netout.length(); i++){ 
     261    if(netout[i].startsWith("=") && netout[i].contains("local")){ 
     262      QString name, address, port; 
     263      for(int j=0; j<3; j++){ //need the next 3 lines 
     264        i++; //Move to the next line 
     265        QString var = netout[i].section("=",0,0).replace("\t"," ").simplified(); 
     266        QString val = netout[i].section("[",1,1).section("]",0,0).simplified(); 
     267        if(var == "hostname"){ name = val.section(".local",0,0).simplified(); } 
     268        else if(var == "address"){ address = val; } 
     269        else if(var == "port"){ port = val; } 
     270      } 
     271      //Check that it is an SSH connection that is open (port 22) 
     272      if(port == "22"){  
     273         out << name+":::"+address+":::"+port; 
     274      } 
     275    } 
     276  } 
     277  return out; 
     278} 
  • src-qt4/life-preserver/lp-gui/LPGUtils.h

    r6a2483b rb22b3a5  
    2424        //Function to scan the system for available harddisks/devices 
    2525        static QStringList listAvailableHardDisks(); 
     26        //Function to scan the network for available replication targets (SSH open) 
     27        static QStringList scanNetworkSSH(); 
    2628}; 
    2729 
Note: See TracChangeset for help on using the changeset viewer.