try {
String vmName = cmd.getVmName();
if(cmd.getVMType() == VirtualMachine.Type.User) {
s_logger.error("Vm in Running state cannot be added to new network.Nic cannot be plugged to VM in running state");
return new PlugNicAnswer(cmd, false, "Vm in Running state cannot be added to new network.Nic cannot be plugged to VM in running state");
}
NicTO nic = cmd.getNic();
URI broadcastUri = nic.getBroadcastUri();
if (BroadcastDomainType.getSchemeValue(broadcastUri) != BroadcastDomainType.Vlan) {
throw new InternalErrorException("Unable to assign a public IP to a VIF on network " + nic.getBroadcastUri());
}
int vlanId = Integer.parseInt(BroadcastDomainType.getValue(broadcastUri));
int publicNicInfo = -1;
publicNicInfo = getVmFreeNicIndex(vmName);
if (publicNicInfo > 0) {
modifyNicVlan(vmName, vlanId, publicNicInfo, true, cmd.getNic().getName());
return new PlugNicAnswer(cmd, true, "success");
}
String msg = " Plug Nic failed for the vm as it has reached max limit of NICs to be added";
s_logger.warn(msg);
return new PlugNicAnswer(cmd, false, msg);
} catch (Exception e) {
s_logger.error("Unexpected exception: ", e);
return new PlugNicAnswer(cmd, false, "Unable to execute PlugNicCommand due to " + e.toString());
}
}