diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java index 65a97a8de31..a0540637e95 100755 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/discoverer/XcpServerDiscoverer.java @@ -315,6 +315,7 @@ public class XcpServerDiscoverer extends DiscovererBase implements Discoverer, L params.put("wait", Integer.toString(_wait)); details.put("wait", Integer.toString(_wait)); params.put("migratewait", _configDao.getValue(Config.MigrateWait.toString())); + params.put(Config.XenMaxNics.toString().toLowerCase(), _configDao.getValue(Config.XenMaxNics.toString())); params.put(Config.InstanceName.toString().toLowerCase(), _instance); details.put(Config.InstanceName.toString().toLowerCase(), _instance); try { diff --git a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java index 22f4ba9cb80..e2e2d6696a9 100644 --- a/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java +++ b/plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java @@ -331,6 +331,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe protected boolean _isOvs = false; protected List _tmpDom0Vif = new ArrayList(); protected XenServerStorageResource storageResource; + protected int _maxNics = 7; public enum SRType { NFS, LVM, ISCSI, ISO, LVMOISCSI, LVMOHBA, EXT, FILE; @@ -3842,22 +3843,6 @@ 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; @@ -3990,21 +3975,25 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe protected String getLowestAvailableVIFDeviceNum(Connection conn, VM vm) { try { - Set availableDeviceNums = vm.getAllowedVIFDevices(conn); - Iterator deviceNumsIterator = availableDeviceNums.iterator(); - List sortedDeviceNums = new ArrayList(); - - while (deviceNumsIterator.hasNext()) { - try { - sortedDeviceNums.add(Integer.valueOf(deviceNumsIterator.next())); + List usedDeviceNums = new ArrayList(); + Set vifs = vm.getVIFs(conn); + Iterator vifIter = vifs.iterator(); + while(vifIter.hasNext()){ + VIF vif = vifIter.next(); + try{ + usedDeviceNums.add(Integer.valueOf(vif.getDevice(conn))); } catch (NumberFormatException e) { - s_logger.debug("Obtained an invalid value for an available VIF device number for VM: " + vm.getNameLabel(conn)); + s_logger.debug("Obtained an invalid value for an allocated VIF device number for VM: " + vm.getNameLabel(conn)); return null; } } - Collections.sort(sortedDeviceNums); - return String.valueOf(sortedDeviceNums.get(0)); + for(Integer i=0; i< _maxNics; i++){ + if(!usedDeviceNums.contains(i)){ + s_logger.debug("Lowest available Vif device number: "+i+" for VM: " + vm.getNameLabel(conn)); + return i.toString(); + } + } } catch (XmlRpcException e) { String msg = "Caught XmlRpcException: " + e.getMessage(); s_logger.warn(msg, e); @@ -5655,6 +5644,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe value = (String) params.get("migratewait"); _migratewait = NumbersUtil.parseInt(value, 3600); + _maxNics = NumbersUtil.parseInt((String) params.get("xen.nics.max"), 7); + if (_pod == null) { throw new ConfigurationException("Unable to get the pod"); } @@ -7765,7 +7756,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe s_logger.warn(msg); return new PlugNicAnswer(cmd, false, msg); } - String deviceId = getUnusedVIFNum(conn, vm); + String deviceId = getLowestAvailableVIFDeviceNum(conn, vm); nic.setDeviceId(Integer.parseInt(deviceId)); vif = createVif(conn, vmName, vm, nic); vif.plug(conn); diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java index abc6a09e4ef..4a0306a1986 100755 --- a/server/src/com/cloud/configuration/Config.java +++ b/server/src/com/cloud/configuration/Config.java @@ -247,7 +247,7 @@ public enum Config { XenBondStorageNic("Advanced", ManagementServer.class, String.class, "xen.bond.storage.nics", null, "Attempt to bond the two networks if found", null), XenHeartBeatInterval("Advanced", ManagementServer.class, Integer.class, "xen.heartbeat.interval", "60", "heartbeat to use when implementing XenServer Self Fencing", null), XenGuestNetwork("Hidden", ManagementServer.class, String.class, "xen.guest.network.device", null, "Specify for guest network name label", null), - + XenMaxNics("Advanced", AgentManager.class, Integer.class, "xen.nics.max", "7", "Maximum allowed nics for Vms created on Xen", null), // VMware VmwarePrivateNetworkVSwitch("Hidden", ManagementServer.class, String.class, "vmware.private.vswitch", null, "Specify the vSwitch on host for private network", null), VmwarePublicNetworkVSwitch("Hidden", ManagementServer.class, String.class, "vmware.public.vswitch", null, "Specify the vSwitch on host for public network", null), @@ -360,7 +360,7 @@ public enum Config { VpcMaxNetworks("Advanced", ManagementServer.class, Integer.class, "vpc.max.networks", "3", "Maximum number of networks per vpc", null), DetailBatchQuerySize("Advanced", ManagementServer.class, Integer.class, "detail.batch.query.size", "2000", "Default entity detail batch query size for listing", null), ConcurrentSnapshotsThresholdPerHost("Advanced", ManagementServer.class, Long.class, "concurrent.snapshots.threshold.perhost", - null, "Limits number of snapshots that can be handled by the host concurrently; default is NULL - unlimited", null), + null, "Limits number of snapshots that can be handled by the host concurrently; default is NULL - unlimited", null), NetworkIPv6SearchRetryMax("Network", ManagementServer.class, Integer.class, "network.ipv6.search.retry.max", "10000", "The maximum number of retrying times to search for an available IPv6 address in the table", null), ExternalBaremetalSystemUrl("Advanced", ManagementServer.class, String.class, "external.baremetal.system.url", null, "url of external baremetal system that CloudStack will talk to", null), diff --git a/server/src/com/cloud/resource/DiscovererBase.java b/server/src/com/cloud/resource/DiscovererBase.java index 940608c4419..b7c5b6f58de 100644 --- a/server/src/com/cloud/resource/DiscovererBase.java +++ b/server/src/com/cloud/resource/DiscovererBase.java @@ -128,6 +128,7 @@ public abstract class DiscovererBase extends AdapterBase implements Discoverer { params.put("secondary.storage.vm", "false"); params.put("max.template.iso.size", _configDao.getValue(Config.MaxTemplateAndIsoSize.toString())); params.put("migratewait", _configDao.getValue(Config.MigrateWait.toString())); + params.put(Config.XenMaxNics.toString().toLowerCase(), _configDao.getValue(Config.XenMaxNics.toString())); return params; } diff --git a/setup/db/db/schema-410to420.sql b/setup/db/db/schema-410to420.sql index 8bd9bfd353e..65add75294b 100644 --- a/setup/db/db/schema-410to420.sql +++ b/setup/db/db/schema-410to420.sql @@ -23,3 +23,4 @@ ALTER TABLE `cloud`.`hypervisor_capabilities` ADD COLUMN `max_hosts_per_cluster` UPDATE `cloud`.`hypervisor_capabilities` SET `max_hosts_per_cluster`=32 WHERE `hypervisor_type`='VMware'; INSERT IGNORE INTO `cloud`.`hypervisor_capabilities`(hypervisor_type, hypervisor_version, max_guests_limit, security_group_enabled, max_hosts_per_cluster) VALUES ('VMware', '5.1', 128, 0, 32); DELETE FROM `cloud`.`configuration` where name='vmware.percluster.host.max'; +INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'AgentManager', 'xen.nics.max', '7', 'Maximum allowed nics for Vms created on Xen'); \ No newline at end of file