NicTO nic = cmd.getNic();
String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
try {
Set<VM> vms = VM.getByNameLabel(conn, domrName);
if (vms == null || vms.isEmpty()) {
return new ExecutionResult(false, "Can not find VM " + domrName);
}
VM vm = vms.iterator().next();
String mac = nic.getMac();
VIF domrVif = null;
for (VIF vif : vm.getVIFs(conn)) {
String lmac = vif.getMAC(conn);
if (lmac.equals(mac)) {
domrVif = vif;
break;
}
}
if (domrVif == null) {
return new ExecutionResult(false, "Can not find vif with mac " + mac + " for VM " + domrName);
}
nic.setDeviceId(Integer.valueOf(domrVif.getDevice(conn)));
} catch (Exception e) {
String msg = "Creating guest network failed due to " + e.toString();
s_logger.warn(msg, e);
return new ExecutionResult(false, msg);
}
return new ExecutionResult(true, null);
}