New functionality: Migrate domain and connection list on left
authorMichal Novotny <minovotn@redhat.com>
Mon, 6 Aug 2012 16:15:23 +0000 (18:15 +0200)
committerMichal Novotny <minovotn@redhat.com>
Mon, 6 Aug 2012 16:17:45 +0000 (18:17 +0200)
This patch is adding the functionality to migrate domain and
it's also adding the support for viewing connections in the
left pane after login. The migration is possible only to
open connection and list of open connections is now well
viewable.

Signed-off-by: Michal Novotny <minovotn@redhat.com>

classes/language.php
classes/libvirt.php
graphics/closed.png [new file with mode: 0644]
graphics/migrate.png [new file with mode: 0644]
graphics/open.png [new file with mode: 0644]
index.php
lang/cs.php
lang/en.php
main-menu.php
manager.css
pages/domain-list.php

index b87d9ec..6815b31 100644 (file)
                                        'system_information' => 'System information',
                                        'date-format' => 'Y-m-d H:i:s',
                                        'run' => 'Run',
+                                       'no-destination-present' => 'No destination present or connected',
+                                       'choose-destination' => 'Choose migration destination',
+                                       'dom_migrate' => 'Migrate domain',
                                        );
 
                        $this->trans = $trans;
index e8fce08..e0a3d6f 100644 (file)
                        return ($tmp) ? $tmp : $this->_set_last_error();
                }
 
+               function migrate_to_uri($domain, $uri, $live = false, $bandwidth = 100) {
+                       $dom = $this->get_domain_object($domain);
+                       if (!$dom)
+                               return false;
+
+                       $name = $this->domain_get_name($dom);
+                       $tmp = libvirt_domain_migrate_to_uri($dom, $uri, $live ? VIR_MIGRATE_LIVE : 0, $name, $bandwidth);
+                       return ($tmp) ? $tmp : $this->_set_last_error();
+               }
+
+               function migrate($domain, $conn, $live = false, $bandwidth = 100) {
+                       $dom = $this->get_domain_object($domain);
+                       if (!$dom)
+                               return false;
+
+                       $name = $this->domain_get_name($dom);
+                       $tmp = libvirt_domain_migrate($dom, $conn, $live ? VIR_MIGRATE_LIVE : 0, $name, $bandwidth);
+                       return ($tmp) ? $tmp : $this->_set_last_error();
+               }
+
                function generate_connection_uri($hv, $remote, $remote_method, $remote_username, $remote_hostname, $session=false) {
                        if ($hv == 'qemu') {
                                if ($session)
diff --git a/graphics/closed.png b/graphics/closed.png
new file mode 100644 (file)
index 0000000..645f200
Binary files /dev/null and b/graphics/closed.png differ
diff --git a/graphics/migrate.png b/graphics/migrate.png
new file mode 100644 (file)
index 0000000..5cf3a60
Binary files /dev/null and b/graphics/migrate.png differ
diff --git a/graphics/open.png b/graphics/open.png
new file mode 100644 (file)
index 0000000..1a87a2e
Binary files /dev/null and b/graphics/open.png differ
index b2eae86..aaae028 100644 (file)
--- a/index.php
+++ b/index.php
@@ -6,9 +6,6 @@
        if ($lg == '')
                $lg = false;
 
-       if ($lg && LOGDIR)
-               $lg = LOGDIR.'/'.$lg;
-
        $errmsg = false;
        if (!CONNECT_WITH_NULL_STRING && $uri == 'null')
                $uri = false;
                        $lg,
                        $lang_str
                );
-
        else
                $lv = new Libvirt($uri, null, null, $lg, $lang_str);
 
+       $conns = array();
+       if (array_key_exists('connections', $_SESSION))
+               $conns = $_SESSION['connections'];
+
+       if (array_key_exists('attach', $_GET) && ($_GET['attach'])) {
+               $tmp = $db->list_connections(true);
+               $rid = (int)$_GET['attach'];
+
+               for ($i = 0; $i < sizeof($tmp); $i++) {
+                       if ($tmp[$i]['id'] == $rid) {
+                               $id = $tmp[$i]['id'];
+                               $hv = $tmp[$i]['hypervisor'];
+                               $nm = $tmp[$i]['name'];
+                               $rh = $tmp[$i]['remote'];
+                               $rm = $tmp[$i]['method'];
+                               $rp = $tmp[$i]['require_pwd'];
+                               $un = $tmp[$i]['user'];
+                               $pwd= $tmp[$i]['password'];
+                               $hn = $tmp[$i]['host'];
+                               $lg = $tmp[$i]['logfile'];
+                       }
+               }
+
+               if ($hv) {
+                       if ($lv->test_connection_uri($hv, $rh, $rm, $un, $pwd, $hn)) {
+                               $new_uri = $lv->generate_connection_uri($hv, $rh, $rm, $un, $hn);
+                               $new_conn = array();
+                               $new_conn['connection_uri'] = $new_uri;
+                               $new_conn['connection_name'] = $nm;
+                               $new_conn['connection_logging'] = $lg;
+                               $new_conn['id'] = $id;
+                               if (isset($un) && isset($pwd))
+                                       $new_conn['connection_credentials'] = array(
+                                               VIR_CRED_AUTHNAME => $un,
+                                               VIR_CRED_PASSPHRASE => $pwd
+                                       );
+                       }
+               }
+
+               $skip = false;
+               foreach ($conns as $item) {
+                       if ($item['connection_uri'] == $new_uri)
+                               $skip = true;
+               }
+
+               if (!$skip) {
+                       $conns[] = $new_conn;
+                       $_SESSION['connections'] = $conns;
+               }
+
+               $_GET['connect'] = $rid;
+       }
+
+       if (array_key_exists('detach', $_GET) && ($_GET['detach'])) {
+               $tmp = $db->list_connections(true);
+               $rid = (int)$_GET['detach'];
+
+               for ($i = 0; $i < sizeof($tmp); $i++) {
+                       if ($tmp[$i]['id'] == $rid) {
+                               $id = $tmp[$i]['id'];
+
+                               for ($j = 0; $j < sizeof($conns); $j++) {
+                                       if ($conns[$j]['id'] == $id)
+                                               unset($conns[$j]);
+                               }
+                       }
+               }
+
+               $_SESSION['connections'] = $conns;
+       }
+
+       if ($lg && LOGDIR)
+               $lg = LOGDIR.'/'.$lg;
+
        /* Get new MAC address in plain text - called by Ajax from pages/new-vm.php */
        if (array_key_exists('get_mac', $_GET)) {
                die( $lv->generate_random_mac_addr() );
index ce05b48..aba14bd 100644 (file)
                                        'system_information' => 'Systémové informace',
                                        'date-format' => 'd.m.Y H:i:s',
                                        'run' => 'Spuštění',
+                                       'no-destination-present' => 'Žádný cíl není dostupný či na něj nejste připojeni',
+                                       'choose-destination' => 'Zvolte cíl migrace',
+                                       'dom_migrate' => 'Migrovat doménu',
                                        );
 ?>
index 931f92c..096e513 100644 (file)
                                        'system_information' => 'System information',
                                        'date-format' => 'Y-m-d H:i:s',
                                        'run' => 'Run',
+                                       'no-destination-present' => 'No destination present or connected',
+                                       'choose-destination' => 'Choose migration destination',
+                                       'dom_migrate' => 'Migrate domain',
                                        );
 ?>
index b1ba770..dd31b7e 100644 (file)
@@ -1,3 +1,32 @@
+  <!-- LIST OF CONNECTIONS -->
+  <div id="conn-list">
+    <p><?php echo $lang->get('conns') ?></p>
+    <?php
+       $tmp = $db->list_connections(true);
+
+       $conn_ids = array();
+       foreach ($conns as $conn) {
+               $conn_ids[] = $conn['id'];
+       }
+
+       if (sizeof($tmp) > 0) {
+               foreach ($tmp as $item) {
+                       $lmid = $item['id'];
+                       $lmname = $item['name'];
+
+                       if (in_array($lmid, $conn_ids))
+                               echo "<img src='graphics/open.png' /><a href=\"?attach=$lmid\">$lmname</a> <a href=\"?detach=$lmid\">[x]</a><br />";
+                       else
+                               echo "<img src='graphics/closed.png' /><a href=\"?attach=$lmid\">$lmname</a><br />";
+               }
+       }
+       else
+               echo '-';
+    ?>
+  </div>
+
+  <div id="conn-detail">
+
   <!-- MENU -->
   <div id="main-menu">
     <a href="?"><?php echo $lang->get('main_menu') ?></a>
index 4d2506a..edc9869 100644 (file)
@@ -139,3 +139,31 @@ table tr td {
 #content .item .nl {
        clear: both;
 }
+
+#conn-list {
+       width: 145px;
+       float: left;
+       background-color: lightgray;
+}
+
+#conn-list a {
+       font-size: 1em;
+       padding: 10px;
+       color: blue;
+       text-decoration: none;
+       font-weight: bold;
+       font-style: italic;
+}
+
+#conn-list p {
+       font-size: 1em;
+       font-weight: bold;
+       font-style: italic;
+       padding: 0;
+       margin: 10px 0 10px 0;
+       text-align: center;
+}
+
+#conn-detail {
+       margin-left: 150px;
+}
index 5b00c4f..cedd0a9 100644 (file)
             </tr></form></table>';
   }
 
+  if ($action == 'domain-migrate') {
+    $name = $_GET['dom'];
+
+    if (!array_key_exists('dest-uri', $_POST)) {
+       $uris = array();
+
+       foreach ($conns as $conn) {
+               if ($conn['connection_uri'] != $uri)
+                       $uris[] = array(
+                                       'uri' => $conn['connection_uri'],
+                                       'name' => $conn['connection_name']
+                                       );
+       }
+
+       if (sizeof($uris) == 0)
+               echo $lang->get('no-destination-present');
+       else {
+               echo "<form method='POST'>".$lang->get('choose-destination')." ($name): <br /><select name='dest-uri' style='width: 150px'>";
+
+               foreach ($uris as $cn) {
+                       $str = base64_encode($cn['uri']);
+
+                       echo "<option value=\"$str\">{$cn['name']}</option>";
+               }
+
+               echo "</select><br /><input type='submit' value='".$lang->get('dom_migrate')."'>";
+       }
+    }
+    else {
+       $uri = base64_decode($_POST['dest-uri']);
+        if (!$lv->migrate_to_uri($name, $uri))
+               echo '<b>'.$lang->get('error_page_title').'</b>: '.$lv->get_last_error();
+    }
+  }
+
   if ($action == 'domain-edit') {
     $name = $_GET['dom'];
 
                                        $actions  = '<a href="?page='.$page.'&amp;action=domain-stop&amp;dom='.$name.'"><img src="graphics/stop.png" title="'.$lang->get('dom_stop').'" /></a> ';
                                        $actions .= '<a href="?page='.$page.'&amp;action=domain-destroy&amp;dom='.$name.'"><img src="graphics/destroy.png" title="'.$lang->get('dom_destroy').'" /></a> ';
                                        $actions .= '<a href="?page='.$page.'&amp;action=domain-dump&amp;dom='.$name.'"><img src="graphics/dump.png" title="'.$lang->get('dom_dumpxml').'" /></a> ';
+                                       $actions .= '<a href="?page='.$page.'&amp;action=domain-migrate&amp;dom='.$name.'"><img src="graphics/migrate.png" title="'.$lang->get('dom_migrate').'" /></a> ';
 
                                        if ($lv->supports('screenshot'))
                                                $actions .= '<a href="?name='.$name.'&amp;page=screenshot"><img src="graphics/screenshot.png" title="'.$lang->get('dom_screenshot').'" /></a>';