Skip to content

Commit f5056d4

Browse files
anthonyxuAlena Prokharchyk
authored andcommitted
VPC : implement SetupGuestNetworkCommand
1 parent 8c1700a commit f5056d4

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

api/src/com/cloud/agent/api/SetupGuestNetworkCommand.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public class SetupGuestNetworkCommand extends NetworkElementCommand{
2828
boolean add = true;
2929
NicTO nic;
3030

31+
public NicTO getNic() {
32+
return nic;
33+
}
34+
3135
@Override
3236
public boolean executeInSequence() {
3337
return true;

core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7030,8 +7030,47 @@ private PlugNicAnswer execute(PlugNicCommand cmd) {
70307030
* @return
70317031
*/
70327032
private SetupGuestNetworkAnswer execute(SetupGuestNetworkCommand cmd) {
7033-
// TODO Auto-generated method stub
7034-
return null;
7033+
Connection conn = getConnection();
7034+
NicTO nic = cmd.getNic();
7035+
String domrIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_IP);
7036+
String domrGIP = cmd.getAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP);
7037+
String domrName = cmd.getAccessDetail(NetworkElementCommand.ROUTER_NAME);
7038+
try {
7039+
Set<VM> vms = VM.getByNameLabel(conn, domrName);
7040+
if ( vms == null || vms.isEmpty() ) {
7041+
return new SetupGuestNetworkAnswer(cmd, false, "Can not find VM " + domrName);
7042+
}
7043+
VM vm = vms.iterator().next();
7044+
String mac = nic.getMac();
7045+
VIF domrVif = null;
7046+
for ( VIF vif : vm.getVIFs(conn)) {
7047+
String lmac = vif.getMAC(conn);
7048+
if ( lmac.equals(mac) ) {
7049+
domrVif = vif;
7050+
break;
7051+
}
7052+
}
7053+
if ( domrVif == null ) {
7054+
return new SetupGuestNetworkAnswer(cmd, false, "Can not find vif with mac " + mac + " for VM " + domrName);
7055+
}
7056+
7057+
String args = "guestnw.sh " + domrIP + " -C";
7058+
String dev = "eth" + domrVif.getDevice(conn);
7059+
args += " -d " + dev;
7060+
args += " -i " + domrGIP;
7061+
args += " -g " + nic.getGateway();
7062+
args += " -m " + Long.toString(NetUtils.getCidrSize(nic.getNetmask()));
7063+
args += " -s " + nic.getDns1();
7064+
String result = callHostPlugin(conn, "vmops", "routerProxy", "args", args);
7065+
if (result == null || result.isEmpty()) {
7066+
return new SetupGuestNetworkAnswer(cmd, false, "creating guest network failed due to " + ((result == null)? "null":result));
7067+
}
7068+
return new SetupGuestNetworkAnswer(cmd, true, "success");
7069+
} catch (Exception e) {
7070+
String msg = " UnPlug Nic failed due to " + e.toString();
7071+
s_logger.warn(msg, e);
7072+
return new SetupGuestNetworkAnswer(cmd, false, msg);
7073+
}
70357074
}
70367075

70377076

wscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# the following two variables are used by the target "waf dist"
55
# if you change 'em here, you need to change it also in cloud.spec, add a %changelog entry there, and add an entry in debian/changelog
66

7-
VERSION = '3.0.3.2012-06-06T00:22:14Z'
7+
VERSION = '3.0.3.2012-06-06T01:46:43Z'
88
APPNAME = 'cloud'
99

1010
import shutil,os

0 commit comments

Comments
 (0)