Skip to content

Commit 600f140

Browse files
author
Mice Xia
committed
fix CLOUDSTACK-2277 Add approriate message for the user informing about the absence of vm-tools when adding nics to vm on vmware
1 parent 6ef615e commit 600f140

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@
237237
import com.vmware.vim25.ComputeResourceSummary;
238238
import com.vmware.vim25.DatastoreSummary;
239239
import com.vmware.vim25.DynamicProperty;
240+
import com.vmware.vim25.GuestInfo;
240241
import com.vmware.vim25.HostCapability;
241242
import com.vmware.vim25.HostFirewallInfo;
242243
import com.vmware.vim25.HostFirewallRuleset;
@@ -1326,6 +1327,12 @@ private PlugNicAnswer execute(PlugNicCommand cmd) {
13261327
throw new Exception(msg);
13271328
}
13281329

1330+
if(!isVMWareToolsInstalled(vmMo)){
1331+
String errMsg = "vmware tools is not installed or not running, cannot add nic to vm " + vmName;
1332+
s_logger.debug(errMsg);
1333+
return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + errMsg);
1334+
}
1335+
13291336
// TODO need a way to specify the control of NIC device type
13301337
VirtualEthernetCardType nicDeviceType = VirtualEthernetCardType.E1000;
13311338

@@ -1400,6 +1407,12 @@ private UnPlugNicAnswer execute(UnPlugNicCommand cmd) {
14001407
throw new Exception(msg);
14011408
}
14021409

1410+
if(!isVMWareToolsInstalled(vmMo)){
1411+
String errMsg = "vmware tools not installed or not running, cannot remove nic from vm " + vmName;
1412+
s_logger.debug(errMsg);
1413+
return new UnPlugNicAnswer(cmd, false, "Unable to execute unPlugNicCommand due to " + errMsg);
1414+
}
1415+
14031416
VirtualDevice nic = findVirtualNicDevice(vmMo, cmd.getNic().getMac());
14041417
if ( nic == null ) {
14051418
return new UnPlugNicAnswer(cmd, true, "success");
@@ -5237,4 +5250,9 @@ public void setRunLevel(int level) {
52375250
// TODO Auto-generated method stub
52385251

52395252
}
5253+
5254+
private boolean isVMWareToolsInstalled(VirtualMachineMO vmMo) throws Exception{
5255+
GuestInfo guestInfo = vmMo.getVmGuestInfo();
5256+
return (guestInfo != null && guestInfo.getGuestState() != null && guestInfo.getGuestState().equalsIgnoreCase("running"));
5257+
}
52405258
}

‎server/src/com/cloud/vm/UserVmManagerImpl.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4248,7 +4248,7 @@ public boolean plugNic(Network network, NicTO nic, VirtualMachineTO vm,
42484248
_agentMgr.send(dest.getHost().getId(),cmds);
42494249
PlugNicAnswer plugNicAnswer = cmds.getAnswer(PlugNicAnswer.class);
42504250
if (!(plugNicAnswer != null && plugNicAnswer.getResult())) {
4251-
s_logger.warn("Unable to plug nic for " + vmVO);
4251+
s_logger.warn("Unable to plug nic for " + vmVO + " due to: " + " due to: " + plugNicAnswer.getDetails());
42524252
return false;
42534253
}
42544254
} catch (OperationTimedoutException e) {
@@ -4276,7 +4276,7 @@ public boolean unplugNic(Network network, NicTO nic, VirtualMachineTO vm,
42764276
_agentMgr.send(dest.getHost().getId(),cmds);
42774277
UnPlugNicAnswer unplugNicAnswer = cmds.getAnswer(UnPlugNicAnswer.class);
42784278
if (!(unplugNicAnswer != null && unplugNicAnswer.getResult())) {
4279-
s_logger.warn("Unable to unplug nic for " + vmVO);
4279+
s_logger.warn("Unable to unplug nic for " + vmVO + " due to: " + unplugNicAnswer.getDetails());
42804280
return false;
42814281
}
42824282
} catch (OperationTimedoutException e) {

0 commit comments

Comments
 (0)