From 98862ce811bdc9443e3eeb8a147153c0ee8d5903 Mon Sep 17 00:00:00 2001
From: hahn <axel.hahn@iml.unibe.ch>
Date: Tue, 3 Aug 2021 11:15:36 +0200
Subject: [PATCH] update rollout plugins; use select (awx)

---
 .../deployment/plugins/rollout/awx/info.json  |   6 +-
 .../plugins/rollout/awx/lang_de.json          |   2 +-
 .../plugins/rollout/awx/lang_en.json          |   2 +-
 .../plugins/rollout/awx/rollout_awx.php       |  29 ++---
 .../rollout/default/rollout_default.php       |  14 ++-
 .../plugins/rollout/ssh/rollout_ssh.php       | 103 ++----------------
 6 files changed, 37 insertions(+), 119 deletions(-)

diff --git a/public_html/deployment/plugins/rollout/awx/info.json b/public_html/deployment/plugins/rollout/awx/info.json
index 611f37b8..c1c0ec9d 100644
--- a/public_html/deployment/plugins/rollout/awx/info.json
+++ b/public_html/deployment/plugins/rollout/awx/info.json
@@ -23,7 +23,7 @@
             },
             "jobtemplate": {
                 "type": "select",
-                "default": "36",
+                "default": "",
                 "callback": "getAwxJobTemplates",
                 "ttl": 120,
                 "per_scope": false
@@ -46,9 +46,9 @@
         "phase": {
             "inventory": {
                 "type": "select",
-                "default": "example: 5",
+                "default": "",
                 "callback": "getAwxInventories",
-                "ttl": 10,
+                "ttl": 120,
                 "per_scope": false
             }     
         }
diff --git a/public_html/deployment/plugins/rollout/awx/lang_de.json b/public_html/deployment/plugins/rollout/awx/lang_de.json
index 427a3f6f..ffa4d4ef 100644
--- a/public_html/deployment/plugins/rollout/awx/lang_de.json
+++ b/public_html/deployment/plugins/rollout/awx/lang_de.json
@@ -18,7 +18,7 @@
     "extravars-label": "Extravars",
     "extravars-hint": "Extravars als JSON Syntax.",
 
-    "inventory-label": "Inventory ID",
+    "inventory-label": "Inventory",
     "inventory-hint": "AWX inventory zum Setzen der Phase und der zu installierenden Hosts",
 
     "endoffile": ""
diff --git a/public_html/deployment/plugins/rollout/awx/lang_en.json b/public_html/deployment/plugins/rollout/awx/lang_en.json
index 43b46920..e662c504 100644
--- a/public_html/deployment/plugins/rollout/awx/lang_en.json
+++ b/public_html/deployment/plugins/rollout/awx/lang_en.json
@@ -18,7 +18,7 @@
     "extravars-label": "Extravars",
     "extravars-hint": "Extravars in JSON syntax",
 
-    "inventory-label": "Inventory ID",
+    "inventory-label": "Inventory",
     "inventory-hint": "AWX inventory to define phase and set of hosts",
 
     "endoffile": ""
diff --git a/public_html/deployment/plugins/rollout/awx/rollout_awx.php b/public_html/deployment/plugins/rollout/awx/rollout_awx.php
index 5c3e4ffa..7ec6f2dc 100644
--- a/public_html/deployment/plugins/rollout/awx/rollout_awx.php
+++ b/public_html/deployment/plugins/rollout/awx/rollout_awx.php
@@ -6,7 +6,7 @@
  * 
  * Run an Https POST request to AWX
  *
- * @author axel
+ * @author <axel.hahn@iml.unibe.ch>
  */
 class rollout_awx extends rollout_base {
 
@@ -74,8 +74,8 @@ class rollout_awx extends rollout_base {
    
   
     /**
-     * get AWX Job Templates and return them as array for select box
-     * [id] => array('value' => [ID], 'label' => [PLAYBOOK] [ID])
+     * get AWX inventories and return them as array for select box
+     * [id] => array('value' => [ID], 'label' => [NAME] [ID])
      * @return array
      */
     static public function getAwxInventories(){
@@ -98,12 +98,7 @@ class rollout_awx extends rollout_base {
                 'label'=>$aItem['name'].' (id: '.$aItem['id'].')'
             ];
         }
-        /*
-        echo '<pre>RETURN: '; 
-        print_r($aReturn);
-        die(__METHOD__);
-        */
-        
+
         return  $aReturn;
     }
     /**
@@ -113,7 +108,7 @@ class rollout_awx extends rollout_base {
      */
     static public function getAwxJobTemplates(){
         $aResponse=$this->_httpRequest(array(
-                'url'=>'/job_templates/?order_by=playbook',
+                'url'=>'/job_templates/?order_by=name',
                 'method'=>'GET',
             )
         );
@@ -128,15 +123,9 @@ class rollout_awx extends rollout_base {
         foreach ($aData['results'] as $aItem){
             $aReturn[$aItem['id']]= [
                 'value'=>$aItem['id'], 
-                'label'=>$aItem['playbook'].' (id: '.$aItem['id'].')'
+                'label'=>$aItem['name'].' (id: '.$aItem['id'].'; '.$aItem['playbook'].')'
             ];
         }
-        /*
-        echo '<pre>RETURN: '; 
-        print_r($aReturn);
-        die(__METHOD__);
-        */
-        
         return  $aReturn;
     }
     
@@ -148,6 +137,12 @@ class rollout_awx extends rollout_base {
         return true;
     }
 
+    /**
+     * get array with commands to execute to deploy a package
+     * 
+     * @param string  $sPhase  phase
+     * @return array
+     */
     public function getDeployCommands($sPhase){
         $aReturn=array();
         $aConfig=$this->getConfig($sPhase);
diff --git a/public_html/deployment/plugins/rollout/default/rollout_default.php b/public_html/deployment/plugins/rollout/default/rollout_default.php
index a8999a44..a98ca37a 100644
--- a/public_html/deployment/plugins/rollout/default/rollout_default.php
+++ b/public_html/deployment/plugins/rollout/default/rollout_default.php
@@ -5,7 +5,7 @@
  * 
  * no action
  *
- * @author axel
+ * @author <axel.hahn@iml.unibe.ch>
  */
 class rollout_default extends rollout_base {
 
@@ -25,10 +25,22 @@ class rollout_default extends rollout_base {
         return true;
     }
 
+    /**
+     * override general form renderer: show a single message that no
+     * configuration items exist
+     * 
+     * @return string
+     */
     public function renderFormdata4Project() {
         return $this->_t('no-cfg');
     }
 
+    /**
+     * override general form renderer: show a single message that no
+     * configuration items exist
+     * 
+     * @return string
+     */
     public function renderFormdata4Phase($sPhase) {
         return $this->_t('no-cfg');
     }    
diff --git a/public_html/deployment/plugins/rollout/ssh/rollout_ssh.php b/public_html/deployment/plugins/rollout/ssh/rollout_ssh.php
index 822d0375..f896fe92 100644
--- a/public_html/deployment/plugins/rollout/ssh/rollout_ssh.php
+++ b/public_html/deployment/plugins/rollout/ssh/rollout_ssh.php
@@ -6,7 +6,7 @@
  * 
  * Run a SSH command on remote targets
  *
- * @author axel
+ * @author <axel.hahn@iml.unibe.ch>
  */
 class rollout_ssh extends rollout_base {
 
@@ -26,6 +26,12 @@ class rollout_ssh extends rollout_base {
         return true;
     }
 
+    /**
+     * get array with commands to execute to deploy a package
+     * 
+     * @param string  $sPhase  phase
+     * @return array
+     */
     public function getDeployCommands($sPhase){
         $aReturn=array();
         $aConfig=$this->getConfig($sPhase);
@@ -45,99 +51,4 @@ class rollout_ssh extends rollout_base {
         return $aReturn;
     }
     
-    /**
-     * form fields for project settings
-     * @return type
-     */
-    public function __DISABLED__renderFormdata4Project() {
-        /*
-          $sReturn='';
-          $i=0;
-
-          $sNamePrefix='plugins[rollout]['.$this->getId().']';
-          $aValues=$this->getConfig();
-
-          $aFormdata=array(
-          array('type' => 'markup','value' => '<br>'.$this->_t('section-required').':'),
-          array(
-          'type' => 'text',
-          'name' => $sNamePrefix.'[user]',
-          'label' => $this->_t('user'),
-          'value' => $aValues['user'],
-          // 'required' => 'required',
-          'validate' => 'isastring',
-          'size' => 25,
-          'placeholder' => $this->_aCfgGlobal['user'],
-          ),
-          array(
-          'type' => 'text',
-          'name' => $sNamePrefix.'[command]',
-          'label' => $this->_t('command'),
-          'value' => $aValues['command'],
-          // 'required' => 'required',
-          'validate' => 'isastring',
-          // 'size' => 100,
-          'placeholder' => $this->_aCfgGlobal['command'],
-          ),
-          array('type' => 'markup','value' => '<br><br>'.$this->_t('section-optional').':'),
-          array(
-          'type' => 'text',
-          'name' => $sNamePrefix.'[privatekey]',
-          'label' => $this->_t('privatekey'),
-          'value' => $aValues['privatekey'],
-          // 'required' => 'required',
-          'validate' => 'isastring',
-          // 'size' => 100,
-          'placeholder' => $this->_aCfgGlobal['privatekey'],
-          ),
-          array('type' => 'markup','value' => '<br><br>'.$this->_t('section-commands').':'),
-          array(
-          'type' => 'text',
-          'name' => $sNamePrefix.'[addkeycommand]',
-          'label' => $this->_t('addkeycommand'),
-          'value' => $aValues['addkeycommand'],
-          // 'required' => 'required',
-          'validate' => 'isastring',
-          // 'size' => 100,
-          'placeholder' => $this->_aCfgGlobal['addkeycommand'],
-          ),
-          array(
-          'type' => 'text',
-          'name' => $sNamePrefix.'[testcommand]',
-          'label' => $this->_t('testcommand'),
-          'value' => $aValues['testcommand'],
-          // 'required' => 'required',
-          'validate' => 'isastring',
-          // 'size' => 100,
-          'placeholder' => $this->_aCfgGlobal['testcommand'],
-          ),
-          );
-         * 
-         */
-
-        return 'WIP: project based setup for plugin [' . $this->getId() . ']<br>'
-                . $this->_renderForm4Vars('global', false)
-                // . $this->_renderForm($aFormdata, 'project')
-                // .$sReturn
-                . '<pre>DEBUG: GLOBAL settings - $this->_aCfgGlobal = ' . print_r($this->_aCfgGlobal, 1) . '</pre>'
-                . '<pre>DEBUG: PROJECT settings - $this->getConfig() = ' . print_r($this->getConfig(), 1) . '</pre>'
-        // .'<pre>DEBUG: $this->_aCfgProject ... plugin = '.print_r($this->_aCfgProject, 1).'</pre>'
-        ;
-    }
-
-    /**
-     * form fields for project settings
-     * @return type
-     */
-    public function __DISABLED__renderFormdata4Phase($sMyPhase) {
-        return 'WIP: pase based setup for plugin [' . $this->getId() . '] in phase '.$sMyPhase.'<br>'
-            . $this->_renderForm4Vars('global', $sMyPhase)
-            // . $this->_renderForm($aFormdata, 'project')
-            // .$sReturn
-            . '<pre>DEBUG: GLOBAL settings - $this->_aCfgGlobal = ' . print_r($this->_aCfgGlobal, 1) . '</pre>'
-            . '<pre>DEBUG: PROJECT settings - $this->getConfig() = ' . print_r($this->getConfig(), 1) . '</pre>'
-            . '<pre>DEBUG: PHASE settings - $this->getConfig("'.$sMyPhase.'") = ' . print_r($this->getConfig($sMyPhase), 1) . '</pre>'
-            ;
-    }
-
 }
-- 
GitLab