@@ -50,9 +50,7 @@ public final class LibvirtGetRemoteVmsCommandWrapper extends CommandWrapper<GetR
5050
5151 @ Override
5252 public Answer execute (final GetRemoteVmsCommand command , final LibvirtComputingResource libvirtComputingResource ) {
53- String result = null ;
54- String hypervisorURI = "qemu+tcp://" + command .getRemoteIp () +
55- "/system" ;
53+ String hypervisorURI = "qemu+tcp://" + command .getRemoteIp () + "/system" ;
5654 HashMap <String , UnmanagedInstanceTO > unmanagedInstances = new HashMap <>();
5755 try {
5856 Connect conn = LibvirtConnection .getConnection (hypervisorURI );
@@ -61,26 +59,27 @@ public Answer execute(final GetRemoteVmsCommand command, final LibvirtComputingR
6159 final Domain domain = libvirtComputingResource .getDomain (conn , name );
6260
6361 final DomainInfo .DomainState ps = domain .getInfo ().state ;
64-
6562 final VirtualMachine .PowerState state = libvirtComputingResource .convertToPowerState (ps );
66-
67- s_logger .debug ("VM " + domain .getName () + ": powerstate = " + ps + "; vm state=" + state .toString ());
63+ s_logger .debug ("VM " + domain .getName () + " - powerstate: " + ps + ", state: " + state .toString ());
6864
6965 if (state == VirtualMachine .PowerState .PowerOff ) {
7066 try {
7167 UnmanagedInstanceTO instance = getUnmanagedInstance (libvirtComputingResource , domain , conn );
7268 unmanagedInstances .put (instance .getName (), instance );
7369 } catch (Exception e ) {
74- s_logger .error ("Error while fetching instance details" , e );
70+ s_logger .error ("Couldn't fetch VM " + domain . getName () + " details, due to: " + e . getMessage () , e );
7571 }
7672 }
7773 domain .free ();
7874 }
79- s_logger .debug ("Found Vms: " + unmanagedInstances .size ());
80- return new GetRemoteVmsAnswer (command , "" , unmanagedInstances );
75+ s_logger .debug ("Found " + unmanagedInstances .size () + " stopped VMs on host " + command . getRemoteIp ());
76+ return new GetRemoteVmsAnswer (command , "" , unmanagedInstances );
8177 } catch (final LibvirtException e ) {
82- s_logger .error ("Error while listing stopped Vms on remote host: " + e .getMessage ());
83- return new Answer (command , false , result );
78+ s_logger .error ("Failed to list stopped VMs on remote host " + command .getRemoteIp () + ", due to: " + e .getMessage (), e );
79+ if (e .getMessage ().toLowerCase ().contains ("connection refused" )) {
80+ return new Answer (command , false , "Unable to connect to remote host " + command .getRemoteIp () + ", please check the libvirtd tcp connectivity and retry" );
81+ }
82+ return new Answer (command , false , "Unable to list stopped VMs on remote host " + command .getRemoteIp () + ", due to: " + e .getMessage ());
8483 }
8584 }
8685
@@ -106,8 +105,8 @@ private UnmanagedInstanceTO getUnmanagedInstance(LibvirtComputingResource libvir
106105
107106 return instance ;
108107 } catch (Exception e ) {
109- s_logger .debug ("Unable to retrieve unmanaged instance info. " , e );
110- throw new CloudRuntimeException ("Unable to retrieve unmanaged instance info. " + e .getMessage ());
108+ s_logger .debug ("Unable to retrieve unmanaged instance info, due to: " + e . getMessage () , e );
109+ throw new CloudRuntimeException ("Unable to retrieve unmanaged instance info, due to: " + e .getMessage ());
111110 }
112111 }
113112
@@ -119,7 +118,6 @@ private UnmanagedInstanceTO.PowerState getPowerState(VirtualMachine.PowerState v
119118 return UnmanagedInstanceTO .PowerState .PowerOff ;
120119 default :
121120 return UnmanagedInstanceTO .PowerState .PowerUnknown ;
122-
123121 }
124122 }
125123
@@ -166,7 +164,6 @@ private List<UnmanagedInstanceTO.Disk> getUnmanagedInstanceDisks(List<LibvirtVMD
166164 disk .setLabel (diskDef .getDiskLabel ());
167165 disk .setController (diskDef .getBusType ().toString ());
168166
169-
170167 Pair <String , String > sourceHostPath = getSourceHostPath (libvirtComputingResource , diskDef .getSourcePath ());
171168 if (sourceHostPath != null ) {
172169 disk .setDatastoreHost (sourceHostPath .first ());
0 commit comments