Code

Renamed opsi class.
[gosa.git] / gosa-plugins / opsi / admin / opsi / class_opsi.inc
index f878fcbaae741b0d62361524d96eae75b4e44644..a60ce9085464a6a735a91787dbcceec0a2f2e345 100644 (file)
@@ -57,6 +57,11 @@ class opsi extends gosaSupportDaemon
     $this->target = "00:01:6c:9d:b9:fa";
   }
 
+  
+  public function enabled()
+  {
+    return(TRUE);
+  }
 
   /******************
     Opsi handling 
@@ -65,7 +70,6 @@ class opsi extends gosaSupportDaemon
   function get_hosts_for_system_management()
   {
     $res = $this->list_clients();
-
     $data = array();
     foreach($res as $entry){
       if(!isset($entry['MAC'][0]['VALUE'])) $entry['MAC'][0]['VALUE'] = "";
@@ -91,11 +95,90 @@ class opsi extends gosaSupportDaemon
   }
 
 
+  /*! \brief  Trigger an event like wake or install for a specific hostId. 
+   */
+  public function send_action($type,$hostId,$mac)
+  {
+    switch($type){
+      case 'install'  :  $this->job_opsi_install_client($hostId,$mac); break;
+      default         :  trigger_error('Unknown type '.$type.'.');
+    }
+  }
+
+
   /******************
     SI Communication functions
    ******************/
 
 
+
+  /*! \brief           Returns a list of all opsi clients.
+    @param
+    @return            
+   */
+  public function list_clients( $hostId = "")
+  {
+    $data   = array();
+    $res    = $this->send_data("gosa_opsi_list_clients",$this->target,$data,TRUE);
+    $items  = array();
+    if(isset($res['XML'][0]['ITEM'])){
+      $items = $res['XML'][0]['ITEM'];
+    }
+    return($items);
+  }
+
+
+  /*! \brief           Adds a new opsi client.
+    @param
+    @return            
+   */
+  public function add_client($hostId,$macaddress,$notes,$description)
+  {
+    $data = array("hostId" => $hostId,"macaddress" => $macaddress);
+
+    if(empty($hostId)){
+      trigger_error("No valid host id given, check parameter 1.");
+      return;
+    }
+  
+    /* Add optional attributes */ 
+    foreach(array("notes","description") as $attr) {
+      if(!empty($$attr)){
+        $data[$attr] = $$attr;
+      }
+    }
+
+    /* Query SI server */
+    $res    = $this->send_data("gosa_opsi_add_client",$this->target,$data,TRUE);
+  }
+
+
+  /*! \brief           Modify an opsi client.
+    @param
+    @return            
+   */
+  public function modify_client($hostId,$mac,$notes,$description)
+  {
+    $data = array("hostId" => $hostId,"mac" => $mac);
+
+    if(empty($hostId)){
+      trigger_error("No valid host id given, check parameter 1.");
+      return;
+    }
+  
+    /* Add optional attributes */ 
+    foreach(array("notes","description") as $attr) {
+      if(!empty($$attr)){
+        $data[$attr] = $$attr;
+      }
+    }
+
+    /* Query SI server */
+    $res = $this->send_data("gosa_opsi_modify_client",$this->target,$data,TRUE);
+  }
+
+
+
   /*! \brief           Returns a list of netboot products.
     @param
     @return            
@@ -279,7 +362,10 @@ class opsi extends gosaSupportDaemon
 
     /* Query SI server */
     $res    = $this->send_data("gosa_opsi_get_client_hardware",$this->target,$data,TRUE);
-    print_a($res);
+    if(isset($res['XML'][0]['ITEM'])){
+      return($res['XML'][0]['ITEM']);
+    }
+    return(array());
   }
 
 
@@ -287,119 +373,66 @@ class opsi extends gosaSupportDaemon
     @param
     @return            
    */
-  public function get_client_software()
+  public function get_client_software($hostId)
   {
-    /*  <xml> 
-        <header>gosa_opsi_get_client_software</header> 
-        <source>GOSA</source> 
-        <target>GOSA</target> 
-        <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
-        </xml> i
-     */
-  }
-
-
+    $data = array("hostId" => $hostId);
 
+    /* Check parameter */ 
+    if(empty($hostId)){
+      trigger_error("No valid host id given, check parameter 1.");
+      return;
+    }
 
-  /*! \brief           Returns a list of all opsi clients.
-    @param
-    @return            
-   */
-  public function list_clients( $hostId = "")
-  {
-    $data   = array();
-    $res    = $this->send_data("gosa_opsi_list_clients",$this->target,$data,TRUE);
-    $items  = array();
+    /* Query SI server */
+    $res    = $this->send_data("gosa_opsi_get_client_software",$this->target,$data,TRUE);
     if(isset($res['XML'][0]['ITEM'])){
-      $items = $res['XML'][0]['ITEM'];
+      return($res['XML'][0]['ITEM']);
     }
-    return($items);
-  }
-
-
-  /*! \brief           Deletes the given opsi client.
-    @param
-    @return            
-   */
-  public function del_client()
-  {
-    /*  <xml> 
-        <header>gosa_opsi_del_client</header> 
-        <source>GOSA</source> 
-        <target>00:01:6c:9d:b9:fa</target> 
-        <hostId>limux-cl-2.intranet.gonicus.de</hostId>
-        </xml>
-     */
+    return(array());
   }
 
 
-  /*! \brief           Triggers install/reinstall of an opsi client.
-    @param
-    @return            
-   */
-  public function job_opsi_install_client()
-  {
-    /*  <xml> 
-        <header>job_opsi_install_client</header> 
-        <source>GOSA</source> 
-        <target>00:01:6c:9d:b9:fa</target> 
-        <hostId>limux-cl-2.intranet.gonicus.de</hostId> 
-        <macaddress>00:11:25:4b:8c:e5</macaddress> 
-        </xml>
-     */
-  }
-
 
-  /*! \brief           Adds a new opsi client.
+  /*! \brief           Deletes the given opsi client.
     @param
     @return            
    */
-  public function add_client($hostId,$macaddress,$notes,$description)
+  public function del_client($hostId)
   {
-    $data = array("hostId" => $hostId,"macaddress" => $macaddress);
+    $data = array("hostId" => $hostId);
 
+    /* Check parameter */ 
     if(empty($hostId)){
       trigger_error("No valid host id given, check parameter 1.");
       return;
     }
-  
-    /* Add optional attributes */ 
-    foreach(array("notes","description") as $attr) {
-      if(!empty($$attr)){
-        $data[$attr] = $$attr;
-      }
-    }
 
     /* Query SI server */
-    $res    = $this->send_data("gosa_opsi_add_client",$this->target,$data,TRUE);
+    $res    = $this->send_data("gosa_opsi_del_client",$this->target,$data,TRUE);
+    if(isset($res['XML'][0]['ITEM'])){
+      return($res['XML'][0]['ITEM']);
+    }
+    return(array());
   }
 
 
-  /*! \brief           Modify an opsi client.
+  /*! \brief           Triggers install/reinstall of an opsi client.
     @param
     @return            
    */
-  public function modify_client($hostId,$mac,$notes,$description)
+  public function job_opsi_install_client($hostId,$mac)
   {
-    $data = array("hostId" => $hostId,"mac" => $mac);
+    $data = array("hostId" => $hostId,"macaddress"=>$mac);
 
+    /* Check parameter */ 
     if(empty($hostId)){
       trigger_error("No valid host id given, check parameter 1.");
       return;
     }
-  
-    /* Add optional attributes */ 
-    foreach(array("notes","description") as $attr) {
-      if(!empty($$attr)){
-        $data[$attr] = $$attr;
-      }
-    }
 
     /* Query SI server */
-    $res    = $this->send_data("gosa_opsi_modify_client",$this->target,$data,TRUE);
+    $this->send_data("job_opsi_install_client",$this->target,$data,TRUE);
   }
-
-
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>