From 205fd844e5a4e05e80342433e0ffbba3cc442470 Mon Sep 17 00:00:00 2001 From: anthony Date: Tue, 19 Jun 2012 12:30:07 -0700 Subject: [PATCH] VPC : when plug VIF , get unused VIF number --- .../xen/resource/CitrixResourceBase.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 3e3f35b287e..d0723f0b503 100644 --- a/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/core/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -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 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 args = new HashMap(); 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");