Migration: Fix migration to use "migrate to connection" instead of "migrate to uri"
authorMichal Novotny <minovotn@redhat.com>
Thu, 9 Aug 2012 14:09:49 +0000 (16:09 +0200)
committerMichal Novotny <minovotn@redhat.com>
Thu, 9 Aug 2012 14:10:52 +0000 (16:10 +0200)
Signed-off-by: Michal Novotny <minovotn@redhat.com>

classes/libvirt.php
index.php
pages/domain-list.php

index d5cbfb7..057941f 100644 (file)
                                return false;
 
                        $name = $this->domain_get_name($dom);
-                       $tmp = libvirt_domain_migrate($dom, $conn, $live ? VIR_MIGRATE_LIVE : 0, $name, $bandwidth);
+                       if (!is_resource($conn)) {
+                               $uri = $conn['connection_uri'];
+                               $login = $conn['connection_credentials'][VIR_CRED_AUTHNAME];
+                               $pwd = $conn['connection_credentials'][VIR_CRED_PASSPHRASE];
+
+                               if ($login && $pwd)
+                                       $dconn = libvirt_connect($uri, false, array(VIR_CRED_AUTHNAME => $login, VIR_CRED_PASSPHRASE => $password));
+                               else
+                                       $dconn = libvirt_connect($uri, false);
+
+                               if ($dconn && $dom && $name)
+                                       $tmp = libvirt_domain_migrate($dom, $dconn, $live ? VIR_MIGRATE_LIVE : 0, $name, $bandwidth);
+                               else
+                                       $tmp = false;
+
+                               unset($dconn);
+                       }
+                       else
+                               $tmp = libvirt_domain_migrate($dom, $conn, $live ? VIR_MIGRATE_LIVE : 0, $name, $bandwidth);
+
                        return ($tmp) ? $tmp : $this->_set_last_error();
                }
 
                                $test = libvirt_connect($uri, false, $credentials);
                        }
                        else
-                               $test = libvirt_connect($uri);
+                               $test = @libvirt_connect($uri);
                        $ok = is_resource($test);
                        unset($test);
 
index aaae028..b0431fc 100644 (file)
--- a/index.php
+++ b/index.php
@@ -28,6 +28,7 @@
                $tmp = $db->list_connections(true);
                $rid = (int)$_GET['attach'];
 
+               $new_uri = false;
                for ($i = 0; $i < sizeof($tmp); $i++) {
                        if ($tmp[$i]['id'] == $rid) {
                                $id = $tmp[$i]['id'];
index cedd0a9..1bf29b7 100644 (file)
@@ -76,7 +76,7 @@
        foreach ($conns as $conn) {
                if ($conn['connection_uri'] != $uri)
                        $uris[] = array(
-                                       'uri' => $conn['connection_uri'],
+                                       'id' => $conn['id'],
                                        'name' => $conn['connection_name']
                                        );
        }
        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>";
-               }
+               foreach ($uris as $cn)
+                       echo "<option value=\"${cn['id']}\">{$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))
+       $arr = false;
+
+       for ($i = 0; $i < sizeof($conns); $i++) {
+               if ($conns[$i]['id'] == $_POST['dest-uri']) {
+                       $arr = $conns[$i];
+                       break;
+               }
+       }
+
+        if ($arr && (!$lv->migrate($name, $arr)))
                echo '<b>'.$lang->get('error_page_title').'</b>: '.$lv->get_last_error();
     }
   }