vNode.setNodeAction(Constants.NODE_ACTION_CLONING_FAILED);
vNode.setErrMessage(CommonUtil.getCurrentTimestamp() + " "
+ vNode.getNodeAction());
return false;
}
VcVirtualMachine vm = VcCache.getIgnoreMissing(vmId);
if (vm == null) {
logger.info("vm " + vmId + " is created, and then removed afterwards.");
vNode.setNodeAction(Constants.NODE_ACTION_CLONING_FAILED);
vNode.setErrMessage(CommonUtil.getCurrentTimestamp() + " "
+ vNode.getNodeAction());
return false;
}
boolean success = true;
for (String portGroup : vNode.getNics().keySet()) {
String ipv4Address =
VcVmUtil.getIpAddressOfPortGroup(vm, portGroup, false);
// currently only care ipv4 address
vNode.updateNicOfPortGroup(portGroup, ipv4Address, null, null);
}
if (vNode.ipsReadyV4()) {
vNode.setSuccess(true);
vNode.setGuestHostName(VcVmUtil.getGuestHostName(vm, false));
vNode.setTargetHost(vm.getHost().getName());
vNode.setVmMobId(vm.getId());
if (vm.isPoweredOn()) {
vNode.setNodeStatus(NodeStatus.VM_READY);
vNode.setNodeAction(null);
} else {
vNode.setNodeStatus(NodeStatus.POWERED_OFF);
vNode.setNodeAction(Constants.NODE_ACTION_CREATION_FAILED);
vNode.setErrMessage(CommonUtil.getCurrentTimestamp() + " "
+ vNode.getNodeAction());
}
} else {
vNode.setSuccess(false);
// in static ip case, vNode contains the allocated address,
// here reset the value in case the ip is unavailable from vc
vNode.resetIpsV4();
if (vm != null) {
vNode.setVmMobId(vm.getId());
if (vm.isPoweredOn()) {
vNode.setNodeStatus(NodeStatus.POWERED_ON);
vNode.setNodeAction(Constants.NODE_ACTION_GET_IP_FAILED);
vNode.setErrMessage(CommonUtil.getCurrentTimestamp() + " "
+ vNode.getNodeAction());
} else {
vNode.setNodeStatus(NodeStatus.POWERED_OFF);
vNode.setNodeAction(Constants.NODE_ACTION_CREATION_FAILED);
vNode.setErrMessage(CommonUtil.getCurrentTimestamp() + " "
+ vNode.getNodeAction());
}
}
success = false;
logger.error("Failed to get ip address of VM " + vNode.getVmName());
}
if (success) {
String haFlag = vNode.getNodeGroup().getHaFlag();
if (haFlag != null
&& Constants.HA_FLAG_FT.equals(haFlag.toLowerCase())
&& !verifyFTState(vm)) {
// FT is enabled and ft status is incorrect
logger.error("Failed to power on FT secondary VM for node "
+ vm.getName() + ", " + "FT state " + vm.getFTState()
+ " is unexpected.");
vNode.setNodeAction(Constants.NODE_ACTION_WRONG_FT_STATUS);
vNode.setErrMessage(CommonUtil.getCurrentTimestamp() + " "
+ vNode.getNodeAction());
return false;