VPC : when plug VIF , get unused VIF number

This commit is contained in:
anthony 2012-06-19 12:30:07 -07:00
parent 17b9952b86
commit 205fd844e5
1 changed files with 18 additions and 1 deletions

View File

@ -774,7 +774,6 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
if (s_logger.isDebugEnabled()) {
s_logger.debug("Creating VIF for " + vmName + " on nic " + nic);
}
VIF.Record vifr = new VIF.Record();
vifr.VM = vm;
vifr.device = Integer.toString(nic.getDeviceId());
@ -3583,6 +3582,22 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
throw new CloudRuntimeException("Could not find an available slot in VM with name to attach a new disk.");
}
protected String getUnusedVIFNum(Connection conn, VM vm) {
String vmName = "";
try {
vmName = vm.getNameLabel(conn);
Set<String> allowedVIFDevices = vm.getAllowedVIFDevices(conn);
if (allowedVIFDevices.size() > 0) {
return allowedVIFDevices.iterator().next();
}
} catch (Exception e) {
String msg = "getUnusedVIFNum failed due to " + e.toString();
s_logger.warn(msg, e);
}
throw new CloudRuntimeException("Could not find available VIF slot in VM with name: " + vmName + " to plug a VIF");
}
protected String callHostPlugin(Connection conn, String plugin, String cmd, String... params) {
Map<String, String> args = new HashMap<String, String>();
String msg;
@ -7109,6 +7124,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
VM vm = vms.iterator().next();
NicTO nic = cmd.getNic();
String deviceId = getUnusedVIFNum(conn, vm);
nic.setDeviceId(Integer.parseInt(deviceId));
VIF vif = createVif(conn, vmName, vm, nic);
vif.plug(conn);
return new PlugNicAnswer(cmd, true, "success");