}
}
try {
Set<VM> vms = VM.getByNameLabel(conn, domrName);
if ( vms == null || vms.isEmpty() ) {
return new SetupGuestNetworkAnswer(cmd, 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 SetupGuestNetworkAnswer(cmd, false, "Can not find vif with mac " + mac + " for VM " + domrName);
}
String args = "vpc_guestnw.sh " + domrIP + (cmd.isAdd()?" -C":" -D");
String dev = "eth" + domrVif.getDevice(conn);
args += " -d " + dev;
args += " -i " + domrGIP;
args += " -g " + gw;
args += " -m " + cidr;
args += " -n " + NetUtils.getSubNet(domrGIP, nic.getNetmask());
if ( dns != null && !dns.isEmpty() ) {
args += " -s " + dns;
}
if ( domainName != null && !domainName.isEmpty() ) {
args += " -e " + domainName;
}
String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
if (result == null || result.isEmpty()) {
return new SetupGuestNetworkAnswer(cmd, false, "creating guest network failed due to " + ((result == null)? "null":result));
}
return new SetupGuestNetworkAnswer(cmd, true, "success");
} catch (Exception e) {
String msg = "Creating guest network failed due to " + e.toString();
s_logger.warn(msg, e);
return new SetupGuestNetworkAnswer(cmd, false, msg);
}
}