mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CS-9919 - Support for Nexus Swiches (Cisco Vswitches)
Description: Code changes to manage Cisco Nexus 1000v in CloudStack. VmwareResource has been modified to leverage Nexus vSwitch. Providing following global configuration parameters, vmware.use.nexus.vswitch - This would decide whether Nexus vSwitch in the VMware cluster environment would be used/managed by CloudStack for it's network infrastructure needs. vmware.guest.network.vswitch.type - This setting would enable CloudStack to use Nexus vSwitch in the VMware cluster environment for guest traffic. vmware.private.network.vswitch.type - This setting would enable CloudStack to use Nexus vSwitch in the VMware cluster environment for private traffic. vmware.public.network.vswitch.type - This setting would enable CloudStack to use Nexus vSwitch in the VMware cluster environment for private traffic. Functional Specification - http://wiki.cloudstack.org/display/RelOps/Cisco+Nexus+1000v+Support+in+CloudStack+-+Functional+Specification Documentation / README for usage instructions - http://wiki.cloudstack.org/display/RelOps/Configuration+instructions+for+CloudStack+Deployment+with+Nexus+vSwitch Conflicts: core/src/com/cloud/hypervisor/vmware/manager/VmwareManager.java core/src/com/cloud/hypervisor/vmware/resource/VmwareResource.java server/src/com/cloud/hypervisor/vmware/VmwareServerDiscoverer.java vmware-base/src/com/cloud/hypervisor/vmware/mo/HostMO.java vmware-base/src/com/cloud/hypervisor/vmware/mo/HypervisorHostHelper.java vmware-base/src/com/cloud/hypervisor/vmware/util/VmwareContext.java
This commit is contained in:
parent
0e293b7b5b
commit
205f4a2192
@ -60,4 +60,6 @@ public interface VmwareManager {
|
|||||||
|
|
||||||
boolean beginExclusiveOperation(int timeOutSeconds);
|
boolean beginExclusiveOperation(int timeOutSeconds);
|
||||||
void endExclusiveOperation();
|
void endExclusiveOperation();
|
||||||
|
|
||||||
|
Map<String, String> getNexusVSMCredentials(String hostGuid);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -161,6 +161,7 @@ import com.cloud.hypervisor.vmware.mo.HypervisorHostHelper;
|
|||||||
import com.cloud.hypervisor.vmware.mo.NetworkDetails;
|
import com.cloud.hypervisor.vmware.mo.NetworkDetails;
|
||||||
import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
|
import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
|
||||||
import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
|
import com.cloud.hypervisor.vmware.mo.VirtualMachineMO;
|
||||||
|
import com.cloud.hypervisor.vmware.mo.VirtualSwitchType;
|
||||||
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
|
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHost;
|
||||||
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary;
|
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostNetworkSummary;
|
||||||
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostResourceSummary;
|
import com.cloud.hypervisor.vmware.mo.VmwareHypervisorHostResourceSummary;
|
||||||
@ -258,6 +259,10 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
protected String _privateNetworkVSwitchName;
|
protected String _privateNetworkVSwitchName;
|
||||||
protected String _publicNetworkVSwitchName;
|
protected String _publicNetworkVSwitchName;
|
||||||
protected String _guestNetworkVSwitchName;
|
protected String _guestNetworkVSwitchName;
|
||||||
|
protected VirtualSwitchType _privateNetworkVSwitchType = VirtualSwitchType.StandardVirtualSwitch;
|
||||||
|
protected VirtualSwitchType _publicNetworkVSwitchType = VirtualSwitchType.StandardVirtualSwitch;
|
||||||
|
protected VirtualSwitchType _guestNetworkVSwitchType = VirtualSwitchType.StandardVirtualSwitch;
|
||||||
|
protected boolean _nexusVSwitch = false;
|
||||||
|
|
||||||
protected float _cpuOverprovisioningFactor = 1;
|
protected float _cpuOverprovisioningFactor = 1;
|
||||||
protected boolean _reserveCpu = false;
|
protected boolean _reserveCpu = false;
|
||||||
@ -806,8 +811,16 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
|
|
||||||
private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final String vifMacAddress) throws Exception {
|
private void plugPublicNic(VirtualMachineMO vmMo, final String vlanId, final String vifMacAddress) throws Exception {
|
||||||
// TODO : probably need to set traffic shaping
|
// TODO : probably need to set traffic shaping
|
||||||
Pair<ManagedObjectReference, String> networkInfo = HypervisorHostHelper.prepareNetwork(this._publicNetworkVSwitchName, "cloud.public",
|
Pair<ManagedObjectReference, String> networkInfo = null;
|
||||||
|
|
||||||
|
if(!_nexusVSwitch) {
|
||||||
|
networkInfo = HypervisorHostHelper.prepareNetwork(this._publicNetworkVSwitchName, "cloud.public",
|
||||||
vmMo.getRunningHost(), vlanId, null, null, this._ops_timeout, true);
|
vmMo.getRunningHost(), vlanId, null, null, this._ops_timeout, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
networkInfo = HypervisorHostHelper.prepareNetwork(this._publicNetworkVSwitchName, "cloud.public",
|
||||||
|
vmMo.getRunningHost(), vlanId, null, null, this._ops_timeout);
|
||||||
|
}
|
||||||
|
|
||||||
int nicIndex = allocPublicNicIndex(vmMo);
|
int nicIndex = allocPublicNicIndex(vmMo);
|
||||||
|
|
||||||
@ -1674,12 +1687,22 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
|
|
||||||
Pair<String, String> switchName = getTargetSwitch(nicTo);
|
Pair<String, String> switchName = getTargetSwitch(nicTo);
|
||||||
String namePrefix = getNetworkNamePrefix(nicTo);
|
String namePrefix = getNetworkNamePrefix(nicTo);
|
||||||
|
Pair<ManagedObjectReference, String> networkInfo = null;
|
||||||
|
|
||||||
s_logger.info("Prepare network on vSwitch: " + switchName.first() + " with name prefix: " + namePrefix);
|
s_logger.info("Prepare network on vSwitch: " + switchName + " with name prefix: " + namePrefix);
|
||||||
return HypervisorHostHelper.prepareNetwork(switchName.first(), namePrefix, hostMo, getVlanInfo(nicTo, switchName.second()),
|
|
||||||
|
if(!_nexusVSwitch) {
|
||||||
|
networkInfo = HypervisorHostHelper.prepareNetwork(switchName.first(), namePrefix, hostMo, getVlanInfo(nicTo, switchName.second()),
|
||||||
nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _ops_timeout,
|
nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _ops_timeout,
|
||||||
!namePrefix.startsWith("cloud.private"));
|
!namePrefix.startsWith("cloud.private"));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
networkInfo = HypervisorHostHelper.prepareNetwork(switchName.first(), namePrefix, hostMo, getVlanInfo(nicTo, switchName.second()),
|
||||||
|
nicTo.getNetworkRateMbps(), nicTo.getNetworkRateMulticastMbps(), _ops_timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
return networkInfo;
|
||||||
|
}
|
||||||
|
|
||||||
// return Pair<switch name, vlan tagging>
|
// return Pair<switch name, vlan tagging>
|
||||||
private Pair<String, String> getTargetSwitch(NicTO nicTo) throws Exception {
|
private Pair<String, String> getTargetSwitch(NicTO nicTo) throws Exception {
|
||||||
@ -4036,6 +4059,34 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
else
|
else
|
||||||
_rootDiskController = DiskControllerType.ide;
|
_rootDiskController = DiskControllerType.ide;
|
||||||
|
|
||||||
|
value = params.get("vmware.use.nexus.vswitch").toString();
|
||||||
|
if(value != null && value.equalsIgnoreCase("true"))
|
||||||
|
_nexusVSwitch = true;
|
||||||
|
|
||||||
|
value = (String)params.get("private.network.vswitch.type");
|
||||||
|
if(value != null && value.equalsIgnoreCase("standard"))
|
||||||
|
_privateNetworkVSwitchType = VirtualSwitchType.StandardVirtualSwitch;
|
||||||
|
else if(value != null && value.equalsIgnoreCase("nexus"))
|
||||||
|
_privateNetworkVSwitchType = VirtualSwitchType.NexusDistributedVirtualSwitch;
|
||||||
|
else
|
||||||
|
_privateNetworkVSwitchType = VirtualSwitchType.VMwareDistributedVirtualSwitch;
|
||||||
|
|
||||||
|
value = (String)params.get("public.network.vswitch.type");
|
||||||
|
if(value != null && value.equalsIgnoreCase("standard"))
|
||||||
|
_publicNetworkVSwitchType = VirtualSwitchType.StandardVirtualSwitch;
|
||||||
|
else if(value != null && value.equalsIgnoreCase("nexus"))
|
||||||
|
_publicNetworkVSwitchType = VirtualSwitchType.NexusDistributedVirtualSwitch;
|
||||||
|
else
|
||||||
|
_publicNetworkVSwitchType = VirtualSwitchType.VMwareDistributedVirtualSwitch;
|
||||||
|
|
||||||
|
value = (String)params.get("guest.network.vswitch.type");
|
||||||
|
if(value != null && value.equalsIgnoreCase("standard"))
|
||||||
|
_guestNetworkVSwitchType = VirtualSwitchType.StandardVirtualSwitch;
|
||||||
|
else if(value != null && value.equalsIgnoreCase("nexus"))
|
||||||
|
_guestNetworkVSwitchType = VirtualSwitchType.NexusDistributedVirtualSwitch;
|
||||||
|
else
|
||||||
|
_guestNetworkVSwitchType = VirtualSwitchType.VMwareDistributedVirtualSwitch;
|
||||||
|
|
||||||
s_logger.info("VmwareResource network configuration info. private vSwitch: " + _privateNetworkVSwitchName + ", public vSwitch: " + _publicNetworkVSwitchName + ", guest network: "
|
s_logger.info("VmwareResource network configuration info. private vSwitch: " + _privateNetworkVSwitchName + ", public vSwitch: " + _publicNetworkVSwitchName + ", guest network: "
|
||||||
+ _guestNetworkVSwitchName);
|
+ _guestNetworkVSwitchName);
|
||||||
|
|
||||||
@ -4100,8 +4151,19 @@ public class VmwareResource implements StoragePoolResource, ServerResource, Vmwa
|
|||||||
s_logger.error("Unable to connect to vSphere server: " + _vCenterAddress, e);
|
s_logger.error("Unable to connect to vSphere server: " + _vCenterAddress, e);
|
||||||
throw new CloudRuntimeException("Unable to connect to vSphere server: " + _vCenterAddress);
|
throw new CloudRuntimeException("Unable to connect to vSphere server: " + _vCenterAddress);
|
||||||
}
|
}
|
||||||
|
if(_nexusVSwitch)
|
||||||
|
{
|
||||||
|
VmwareManager mgr = _serviceContext.getStockObject(VmwareManager.CONTEXT_STOCK_NAME);
|
||||||
|
Map<String, String> nexusVSwitchCredentials = mgr.getNexusVSMCredentials(_guid);
|
||||||
|
if(nexusVSwitchCredentials != null)
|
||||||
|
{
|
||||||
|
_serviceContext.registerStockObject("vsmcredentials", nexusVSwitchCredentials);
|
||||||
|
//_serviceContext.registerStockObject("vsmip", nexusVSwitchCredentials.get("vsmip"));
|
||||||
|
//_serviceContext.registerStockObject("vsmusername", nexusVSwitchCredentials.get("vsmusername"));
|
||||||
|
//_serviceContext.registerStockObject("vsmpassword", nexusVSwitchCredentials.get("vsmpassword"));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return _serviceContext;
|
return _serviceContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -242,6 +242,10 @@ public enum Config {
|
|||||||
VmwarePrivateNetworkVSwitch("Hidden", ManagementServer.class, String.class, "vmware.private.vswitch", null, "Specify the vSwitch on host for private network", null),
|
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),
|
VmwarePublicNetworkVSwitch("Hidden", ManagementServer.class, String.class, "vmware.public.vswitch", null, "Specify the vSwitch on host for public network", null),
|
||||||
VmwareGuestNetworkVSwitch("Hidden", ManagementServer.class, String.class, "vmware.guest.vswitch", null, "Specify the vSwitch on host for guest network", null),
|
VmwareGuestNetworkVSwitch("Hidden", ManagementServer.class, String.class, "vmware.guest.vswitch", null, "Specify the vSwitch on host for guest network", null),
|
||||||
|
VmwareUseNexusVSwitch("Network", ManagementServer.class, Boolean.class, "vmware.use.nexus.vswitch", "false", "Enable/Disable Cisco Nexus 1000v vSwitch in VMware environment", null),
|
||||||
|
VmwarePrivateNetworkVSwitchType("Advanced", ManagementServer.class, String.class, "vmware.private.network.vswitch.type", null, "Specify type of (standard/nexus) virtual switch designated for private traffic", null),
|
||||||
|
VmwarePublicNetworkVSwitchType("Advanced", ManagementServer.class, String.class, "vmware.public.network.vswitch.type", null, "Specify type of (standard/nexus) virtual switch designated for public traffic", null),
|
||||||
|
VmwareGuestNetworkVSwitchType("Advanced", ManagementServer.class, String.class, "vmware.guest.network.vswitch.type", null, "Specify type of (standard/nexus) virtual switch designated for guest traffic", null),
|
||||||
VmwareServiceConsole("Advanced", ManagementServer.class, String.class, "vmware.service.console", "Service Console", "Specify the service console network name(for ESX hosts)", null),
|
VmwareServiceConsole("Advanced", ManagementServer.class, String.class, "vmware.service.console", "Service Console", "Specify the service console network name(for ESX hosts)", null),
|
||||||
VmwareManagementPortGroup("Advanced", ManagementServer.class, String.class, "vmware.management.portgroup", "Management Network", "Specify the management network name(for ESXi hosts)", null),
|
VmwareManagementPortGroup("Advanced", ManagementServer.class, String.class, "vmware.management.portgroup", "Management Network", "Specify the management network name(for ESXi hosts)", null),
|
||||||
VmwareAdditionalVncPortRangeStart("Advanced", ManagementServer.class, Integer.class, "vmware.additional.vnc.portrange.start", "50000", "Start port number of additional VNC port range", null),
|
VmwareAdditionalVncPortRangeStart("Advanced", ManagementServer.class, Integer.class, "vmware.additional.vnc.portrange.start", "50000", "Start port number of additional VNC port range", null),
|
||||||
|
|||||||
@ -46,7 +46,9 @@ import com.cloud.configuration.Config;
|
|||||||
import com.cloud.configuration.dao.ConfigurationDao;
|
import com.cloud.configuration.dao.ConfigurationDao;
|
||||||
import com.cloud.dc.ClusterDetailsDao;
|
import com.cloud.dc.ClusterDetailsDao;
|
||||||
import com.cloud.dc.ClusterVO;
|
import com.cloud.dc.ClusterVO;
|
||||||
|
import com.cloud.dc.ClusterVSMMapVO;
|
||||||
import com.cloud.dc.dao.ClusterDao;
|
import com.cloud.dc.dao.ClusterDao;
|
||||||
|
import com.cloud.dc.dao.ClusterVSMMapDao;
|
||||||
import com.cloud.exception.DiscoveredWithErrorException;
|
import com.cloud.exception.DiscoveredWithErrorException;
|
||||||
import com.cloud.host.HostVO;
|
import com.cloud.host.HostVO;
|
||||||
import com.cloud.host.Status;
|
import com.cloud.host.Status;
|
||||||
@ -66,6 +68,8 @@ import com.cloud.hypervisor.vmware.mo.VirtualEthernetCardType;
|
|||||||
import com.cloud.hypervisor.vmware.mo.VmwareHostType;
|
import com.cloud.hypervisor.vmware.mo.VmwareHostType;
|
||||||
import com.cloud.hypervisor.vmware.resource.SshHelper;
|
import com.cloud.hypervisor.vmware.resource.SshHelper;
|
||||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||||
|
import com.cloud.network.CiscoNexusVSMDeviceVO;
|
||||||
|
import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
|
||||||
import com.cloud.network.router.VirtualNetworkApplianceManager;
|
import com.cloud.network.router.VirtualNetworkApplianceManager;
|
||||||
import com.cloud.org.Cluster.ClusterType;
|
import com.cloud.org.Cluster.ClusterType;
|
||||||
import com.cloud.secstorage.CommandExecLogDao;
|
import com.cloud.secstorage.CommandExecLogDao;
|
||||||
@ -114,6 +118,8 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
@Inject CheckPointManager _checkPointMgr;
|
@Inject CheckPointManager _checkPointMgr;
|
||||||
@Inject VirtualNetworkApplianceManager _routerMgr;
|
@Inject VirtualNetworkApplianceManager _routerMgr;
|
||||||
@Inject SecondaryStorageVmManager _ssvmMgr;
|
@Inject SecondaryStorageVmManager _ssvmMgr;
|
||||||
|
@Inject CiscoNexusVSMDeviceDao _nexusDao;
|
||||||
|
@Inject ClusterVSMMapDao _vsmMapDao;
|
||||||
|
|
||||||
ConfigurationServer _configServer;
|
ConfigurationServer _configServer;
|
||||||
|
|
||||||
@ -123,6 +129,10 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
String _privateNetworkVSwitchName;
|
String _privateNetworkVSwitchName;
|
||||||
String _publicNetworkVSwitchName;
|
String _publicNetworkVSwitchName;
|
||||||
String _guestNetworkVSwitchName;
|
String _guestNetworkVSwitchName;
|
||||||
|
String _privateNetworkVSwitchType;
|
||||||
|
String _publicNetworkVSwitchType;
|
||||||
|
String _guestNetworkVSwitchType;
|
||||||
|
Boolean _nexusVSwitchActive;
|
||||||
String _serviceConsoleName;
|
String _serviceConsoleName;
|
||||||
String _managemetPortGroupName;
|
String _managemetPortGroupName;
|
||||||
String _defaultSystemVmNicAdapterType = VirtualEthernetCardType.E1000.toString();
|
String _defaultSystemVmNicAdapterType = VirtualEthernetCardType.E1000.toString();
|
||||||
@ -208,20 +218,50 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value = configDao.getValue(Config.VmwareUseNexusVSwitch.key());
|
||||||
|
if(value == null) {
|
||||||
|
_nexusVSwitchActive = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_nexusVSwitchActive = Boolean.parseBoolean(value);
|
||||||
|
}
|
||||||
|
|
||||||
_privateNetworkVSwitchName = configDao.getValue(Config.VmwarePrivateNetworkVSwitch.key());
|
_privateNetworkVSwitchName = configDao.getValue(Config.VmwarePrivateNetworkVSwitch.key());
|
||||||
|
_privateNetworkVSwitchType = configDao.getValue(Config.VmwarePrivateNetworkVSwitchType.key());
|
||||||
if(_privateNetworkVSwitchName == null) {
|
if(_privateNetworkVSwitchName == null) {
|
||||||
|
if(_privateNetworkVSwitchType == null || _privateNetworkVSwitchType.equalsIgnoreCase("standard")) {
|
||||||
_privateNetworkVSwitchName = "vSwitch0";
|
_privateNetworkVSwitchName = "vSwitch0";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_privateNetworkVSwitchName = "privateEthernetPortProfile";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_publicNetworkVSwitchName = configDao.getValue(Config.VmwarePublicNetworkVSwitch.key());
|
_publicNetworkVSwitchName = configDao.getValue(Config.VmwarePublicNetworkVSwitch.key());
|
||||||
|
_publicNetworkVSwitchType = configDao.getValue(Config.VmwarePublicNetworkVSwitchType.key());
|
||||||
if(_publicNetworkVSwitchName == null) {
|
if(_publicNetworkVSwitchName == null) {
|
||||||
|
if(_publicNetworkVSwitchType == null || _publicNetworkVSwitchType.equalsIgnoreCase("standard")) {
|
||||||
_publicNetworkVSwitchName = "vSwitch0";
|
_publicNetworkVSwitchName = "vSwitch0";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_publicNetworkVSwitchName = "publicEthernetPortProfile";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_guestNetworkVSwitchName = configDao.getValue(Config.VmwareGuestNetworkVSwitch.key());
|
_guestNetworkVSwitchName = configDao.getValue(Config.VmwareGuestNetworkVSwitch.key());
|
||||||
|
_guestNetworkVSwitchType = configDao.getValue(Config.VmwareGuestNetworkVSwitchType.key());
|
||||||
if(_guestNetworkVSwitchName == null) {
|
if(_guestNetworkVSwitchName == null) {
|
||||||
|
if(_guestNetworkVSwitchType == null || _guestNetworkVSwitchType.equalsIgnoreCase("standard")) {
|
||||||
_guestNetworkVSwitchName = "vSwitch0";
|
_guestNetworkVSwitchName = "vSwitch0";
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_guestNetworkVSwitchName = "guestEthernetPortProfile";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_serviceConsoleName = configDao.getValue(Config.VmwareServiceConsole.key());
|
_serviceConsoleName = configDao.getValue(Config.VmwareServiceConsole.key());
|
||||||
if(_serviceConsoleName == null) {
|
if(_serviceConsoleName == null) {
|
||||||
@ -353,7 +393,12 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
vlanId = String.valueOf(spec.getVlanId());
|
vlanId = String.valueOf(spec.getVlanId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!_nexusVSwitchActive) {
|
||||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000);
|
||||||
|
}
|
||||||
returnedHostList.add(hosts[0]);
|
returnedHostList.add(hosts[0]);
|
||||||
return returnedHostList;
|
return returnedHostList;
|
||||||
} else if(mor.getType().equals("ClusterComputeResource")) {
|
} else if(mor.getType().equals("ClusterComputeResource")) {
|
||||||
@ -386,7 +431,12 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
}
|
}
|
||||||
|
|
||||||
// prepare at least one network on the vswitch to enable OVF importing
|
// prepare at least one network on the vswitch to enable OVF importing
|
||||||
|
if(!_nexusVSwitchActive) {
|
||||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000);
|
||||||
|
}
|
||||||
returnedHostList.add(morHost);
|
returnedHostList.add(morHost);
|
||||||
}
|
}
|
||||||
return returnedHostList;
|
return returnedHostList;
|
||||||
@ -410,7 +460,12 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
}
|
}
|
||||||
|
|
||||||
// prepare at least one network on the vswitch to enable OVF importing
|
// prepare at least one network on the vswitch to enable OVF importing
|
||||||
|
if(!_nexusVSwitchActive) {
|
||||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000);
|
||||||
|
}
|
||||||
returnedHostList.add(mor);
|
returnedHostList.add(mor);
|
||||||
return returnedHostList;
|
return returnedHostList;
|
||||||
} else {
|
} else {
|
||||||
@ -490,6 +545,10 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
params.put("private.network.vswitch.name", _privateNetworkVSwitchName);
|
params.put("private.network.vswitch.name", _privateNetworkVSwitchName);
|
||||||
params.put("public.network.vswitch.name", _publicNetworkVSwitchName);
|
params.put("public.network.vswitch.name", _publicNetworkVSwitchName);
|
||||||
params.put("guest.network.vswitch.name", _guestNetworkVSwitchName);
|
params.put("guest.network.vswitch.name", _guestNetworkVSwitchName);
|
||||||
|
params.put("private.network.vswitch.type", _privateNetworkVSwitchType);
|
||||||
|
params.put("public.network.vswitch.type", _publicNetworkVSwitchType);
|
||||||
|
params.put("guest.network.vswitch.type", _guestNetworkVSwitchType);
|
||||||
|
params.put("vmware.use.nexus.vswitch", _nexusVSwitchActive);
|
||||||
params.put("service.console.name", _serviceConsoleName);
|
params.put("service.console.name", _serviceConsoleName);
|
||||||
params.put("management.portgroup.name", _managemetPortGroupName);
|
params.put("management.portgroup.name", _managemetPortGroupName);
|
||||||
params.put("cpu.overprovisioning.factor", _cpuOverprovisioningFactor);
|
params.put("cpu.overprovisioning.factor", _cpuOverprovisioningFactor);
|
||||||
@ -766,6 +825,21 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DB
|
||||||
|
public Map<String, String> getNexusVSMCredentials(String hostGuid) {
|
||||||
|
//Get clusterId from host guid
|
||||||
|
HostVO host = _hostDao.findByGuid(hostGuid);
|
||||||
|
ClusterVSMMapVO vsmMapVO = _vsmMapDao.findByClusterId(host.getClusterId());
|
||||||
|
CiscoNexusVSMDeviceVO nexusVSM = _nexusDao.findById(vsmMapVO.getVsmId());
|
||||||
|
if(nexusVSM == null)
|
||||||
|
return null;
|
||||||
|
Map<String, String> nexusVSMCredentials = new HashMap<String, String>();
|
||||||
|
nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr());
|
||||||
|
nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName());
|
||||||
|
nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword());
|
||||||
|
return nexusVSMCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
@Override @DB
|
@Override @DB
|
||||||
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
|
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
|
||||||
if(answers != null) {
|
if(answers != null) {
|
||||||
|
|||||||
@ -43,6 +43,7 @@ import com.cloud.hypervisor.vmware.mo.HostMO;
|
|||||||
import com.cloud.hypervisor.vmware.resource.VmwareContextFactory;
|
import com.cloud.hypervisor.vmware.resource.VmwareContextFactory;
|
||||||
import com.cloud.hypervisor.vmware.resource.VmwareResource;
|
import com.cloud.hypervisor.vmware.resource.VmwareResource;
|
||||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||||
|
import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
|
||||||
import com.cloud.resource.Discoverer;
|
import com.cloud.resource.Discoverer;
|
||||||
import com.cloud.resource.DiscovererBase;
|
import com.cloud.resource.DiscovererBase;
|
||||||
import com.cloud.resource.ResourceManager;
|
import com.cloud.resource.ResourceManager;
|
||||||
@ -73,6 +74,8 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer
|
|||||||
@Inject HostDao _hostDao;
|
@Inject HostDao _hostDao;
|
||||||
@Inject ResourceManager _resourceMgr;
|
@Inject ResourceManager _resourceMgr;
|
||||||
|
|
||||||
|
@Inject CiscoNexusVSMDeviceDao _nexusDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url,
|
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url,
|
||||||
String username, String password, List<String> hostTags) throws DiscoveryException {
|
String username, String password, List<String> hostTags) throws DiscoveryException {
|
||||||
|
|||||||
@ -15,8 +15,6 @@ package com.cloud.network;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.cloud.exception.InvalidParameterValueException;
|
import com.cloud.exception.InvalidParameterValueException;
|
||||||
import com.cloud.hypervisor.vmware.manager.VmwareManager;
|
|
||||||
import com.cloud.utils.component.Inject;
|
|
||||||
import com.cloud.utils.db.DB;
|
import com.cloud.utils.db.DB;
|
||||||
import com.cloud.utils.db.Transaction;
|
import com.cloud.utils.db.Transaction;
|
||||||
import com.cloud.utils.exception.CloudRuntimeException;
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
@ -26,11 +24,6 @@ import com.cloud.network.dao.PortProfileDaoImpl;
|
|||||||
|
|
||||||
public class PortProfileManagerImpl {
|
public class PortProfileManagerImpl {
|
||||||
|
|
||||||
//@Inject
|
|
||||||
//static PortProfileDao _portProfileDao;
|
|
||||||
@Inject
|
|
||||||
VmwareManager _vmwareMgr;
|
|
||||||
|
|
||||||
private PortProfileDaoImpl _portProfileDao;
|
private PortProfileDaoImpl _portProfileDao;
|
||||||
|
|
||||||
private static final org.apache.log4j.Logger s_logger = Logger.getLogger(PortProfileManagerImpl.class);
|
private static final org.apache.log4j.Logger s_logger = Logger.getLogger(PortProfileManagerImpl.class);
|
||||||
|
|||||||
@ -27,7 +27,9 @@ import com.vmware.apputils.vim25.ServiceUtil;
|
|||||||
import com.vmware.vim25.AboutInfo;
|
import com.vmware.vim25.AboutInfo;
|
||||||
import com.vmware.vim25.ClusterDasConfigInfo;
|
import com.vmware.vim25.ClusterDasConfigInfo;
|
||||||
import com.vmware.vim25.ComputeResourceSummary;
|
import com.vmware.vim25.ComputeResourceSummary;
|
||||||
|
import com.vmware.vim25.DVPortgroupConfigSpec;
|
||||||
import com.vmware.vim25.DatastoreSummary;
|
import com.vmware.vim25.DatastoreSummary;
|
||||||
|
import com.vmware.vim25.DistributedVirtualSwitchInfo;
|
||||||
import com.vmware.vim25.DynamicProperty;
|
import com.vmware.vim25.DynamicProperty;
|
||||||
import com.vmware.vim25.HostConfigManager;
|
import com.vmware.vim25.HostConfigManager;
|
||||||
import com.vmware.vim25.HostConnectInfo;
|
import com.vmware.vim25.HostConnectInfo;
|
||||||
@ -884,6 +886,7 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
|
|||||||
|
|
||||||
if(s_logger.isTraceEnabled())
|
if(s_logger.isTraceEnabled())
|
||||||
s_logger.trace("vCenter API trace - getHyperHostHardwareSummary() done");
|
s_logger.trace("vCenter API trace - getHyperHostHardwareSummary() done");
|
||||||
|
|
||||||
return resourceSummary;
|
return resourceSummary;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -892,4 +895,95 @@ public class HostMO extends BaseMO implements VmwareHypervisorHost {
|
|||||||
HostRuntimeInfo runtimeInfo = (HostRuntimeInfo)_context.getServiceUtil().getDynamicProperty(_mor, "runtime");
|
HostRuntimeInfo runtimeInfo = (HostRuntimeInfo)_context.getServiceUtil().getDynamicProperty(_mor, "runtime");
|
||||||
return runtimeInfo.getConnectionState() == HostSystemConnectionState.connected;
|
return runtimeInfo.getConnectionState() == HostSystemConnectionState.connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DVPortgroupConfigSpec getDvPortGroupSpec(String dvPortGroupName) throws Exception {
|
||||||
|
DVPortgroupConfigSpec configSpec = null;
|
||||||
|
String nameProperty = null;
|
||||||
|
PropertySpec pSpec = new PropertySpec();
|
||||||
|
pSpec.setType("DistributedVirtualPortgroup");
|
||||||
|
pSpec.setPathSet(new String[] {"summary.name", "config"});
|
||||||
|
|
||||||
|
TraversalSpec host2DvPortGroupTraversal = new TraversalSpec();
|
||||||
|
host2DvPortGroupTraversal.setType("HostSystem");
|
||||||
|
host2DvPortGroupTraversal.setPath("network");
|
||||||
|
host2DvPortGroupTraversal.setName("host2DvPortgroupTraversal");
|
||||||
|
|
||||||
|
ObjectSpec oSpec = new ObjectSpec();
|
||||||
|
oSpec.setObj(_mor);
|
||||||
|
oSpec.setSkip(Boolean.TRUE);
|
||||||
|
oSpec.setSelectSet(new SelectionSpec[] { host2DvPortGroupTraversal });
|
||||||
|
|
||||||
|
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||||
|
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||||
|
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||||
|
|
||||||
|
ObjectContent[] ocs = _context.getService().retrieveProperties(
|
||||||
|
_context.getServiceContent().getPropertyCollector(),
|
||||||
|
new PropertyFilterSpec[] { pfSpec });
|
||||||
|
|
||||||
|
if(ocs != null) {
|
||||||
|
for(ObjectContent oc : ocs) {
|
||||||
|
DynamicProperty[] props = oc.getPropSet();
|
||||||
|
if(props != null) {
|
||||||
|
assert(props.length == 2);
|
||||||
|
for(DynamicProperty prop : props) {
|
||||||
|
if(prop.getName().equals("config")) {
|
||||||
|
configSpec = (DVPortgroupConfigSpec) prop.getVal();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nameProperty = prop.getVal().toString();
|
||||||
|
}
|
||||||
|
if(nameProperty.equalsIgnoreCase(dvPortGroupName)) {
|
||||||
|
return configSpec;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ManagedObjectReference getDvPortGroupMor(String dvPortGroupName) throws Exception {
|
||||||
|
PropertySpec pSpec = new PropertySpec();
|
||||||
|
pSpec.setType("DistributedVirtualPortgroup");
|
||||||
|
pSpec.setPathSet(new String[] {"summary.name"});
|
||||||
|
|
||||||
|
TraversalSpec host2DvPortGroupTraversal = new TraversalSpec();
|
||||||
|
host2DvPortGroupTraversal.setType("HostSystem");
|
||||||
|
host2DvPortGroupTraversal.setPath("network");
|
||||||
|
host2DvPortGroupTraversal.setName("host2DvPortgroupTraversal");
|
||||||
|
|
||||||
|
ObjectSpec oSpec = new ObjectSpec();
|
||||||
|
oSpec.setObj(_mor);
|
||||||
|
oSpec.setSkip(Boolean.TRUE);
|
||||||
|
oSpec.setSelectSet(new SelectionSpec[] { host2DvPortGroupTraversal });
|
||||||
|
|
||||||
|
PropertyFilterSpec pfSpec = new PropertyFilterSpec();
|
||||||
|
pfSpec.setPropSet(new PropertySpec[] { pSpec });
|
||||||
|
pfSpec.setObjectSet(new ObjectSpec[] { oSpec });
|
||||||
|
|
||||||
|
ObjectContent[] ocs = _context.getService().retrieveProperties(
|
||||||
|
_context.getServiceContent().getPropertyCollector(),
|
||||||
|
new PropertyFilterSpec[] { pfSpec });
|
||||||
|
|
||||||
|
if(ocs != null) {
|
||||||
|
for(ObjectContent oc : ocs) {
|
||||||
|
DynamicProperty[] props = oc.getPropSet();
|
||||||
|
if(props != null) {
|
||||||
|
for(DynamicProperty prop : props) {
|
||||||
|
if(prop.getVal().equals(dvPortGroupName))
|
||||||
|
return oc.getObj();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasDvPortGroup(String dvPortGroupName) throws Exception {
|
||||||
|
ManagedObjectReference morNetwork = getDvPortGroupMor(dvPortGroupName);
|
||||||
|
if(morNetwork != null)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,15 +15,29 @@ package com.cloud.hypervisor.vmware.mo;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.mortbay.jetty.servlet.Context;
|
||||||
|
|
||||||
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
import com.cloud.hypervisor.vmware.util.VmwareContext;
|
||||||
import com.cloud.hypervisor.vmware.util.VmwareHelper;
|
import com.cloud.hypervisor.vmware.util.VmwareHelper;
|
||||||
import com.cloud.utils.ActionDelegate;
|
import com.cloud.utils.ActionDelegate;
|
||||||
import com.cloud.utils.Pair;
|
import com.cloud.utils.Pair;
|
||||||
|
import com.cloud.utils.cisco.n1kv.vsm.NetconfHelper;
|
||||||
|
import com.cloud.utils.cisco.n1kv.vsm.VsmCommand.BindingType;
|
||||||
|
import com.cloud.utils.cisco.n1kv.vsm.VsmCommand.OperationType;
|
||||||
|
import com.cloud.utils.cisco.n1kv.vsm.VsmCommand.PortProfileType;
|
||||||
|
import com.cloud.utils.cisco.n1kv.vsm.VsmCommand.SwitchPortMode;
|
||||||
import com.cloud.utils.db.GlobalLock;
|
import com.cloud.utils.db.GlobalLock;
|
||||||
|
import com.cloud.utils.exception.CloudRuntimeException;
|
||||||
import com.cloud.utils.net.NetUtils;
|
import com.cloud.utils.net.NetUtils;
|
||||||
|
import com.vmware.vim25.BoolPolicy;
|
||||||
|
import com.vmware.vim25.DVPortgroupConfigSpec;
|
||||||
|
import com.vmware.vim25.DVSTrafficShapingPolicy;
|
||||||
|
//import com.vmware.vim25.DistributedVirtualSwitchKeyedOpaqueBlob;
|
||||||
import com.vmware.vim25.DynamicProperty;
|
import com.vmware.vim25.DynamicProperty;
|
||||||
import com.vmware.vim25.HostNetworkTrafficShapingPolicy;
|
import com.vmware.vim25.HostNetworkTrafficShapingPolicy;
|
||||||
import com.vmware.vim25.HostPortGroupSpec;
|
import com.vmware.vim25.HostPortGroupSpec;
|
||||||
@ -31,6 +45,7 @@ import com.vmware.vim25.HostVirtualSwitch;
|
|||||||
import com.vmware.vim25.HttpNfcLeaseDeviceUrl;
|
import com.vmware.vim25.HttpNfcLeaseDeviceUrl;
|
||||||
import com.vmware.vim25.HttpNfcLeaseInfo;
|
import com.vmware.vim25.HttpNfcLeaseInfo;
|
||||||
import com.vmware.vim25.HttpNfcLeaseState;
|
import com.vmware.vim25.HttpNfcLeaseState;
|
||||||
|
import com.vmware.vim25.LongPolicy;
|
||||||
import com.vmware.vim25.ManagedObjectReference;
|
import com.vmware.vim25.ManagedObjectReference;
|
||||||
import com.vmware.vim25.ObjectContent;
|
import com.vmware.vim25.ObjectContent;
|
||||||
import com.vmware.vim25.OvfCreateImportSpecParams;
|
import com.vmware.vim25.OvfCreateImportSpecParams;
|
||||||
@ -114,6 +129,224 @@ public class HypervisorHostHelper {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Map<String, String> getValidatedVsmCredentials(VmwareContext context) throws Exception, CloudRuntimeException {
|
||||||
|
Map<String, String> vsmCredentials = context.getStockObject("vsmcredentials");
|
||||||
|
String msg;
|
||||||
|
if(vsmCredentials == null || vsmCredentials.size() != 3) {
|
||||||
|
msg = "Failed to retrieve required credentials of Nexus VSM from database.";
|
||||||
|
s_logger.error(msg);
|
||||||
|
throw new Exception(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
String vsmIp = vsmCredentials.containsKey("vsmip") ? vsmCredentials.get("vsmip") : null;
|
||||||
|
String vsmUserName = vsmCredentials.containsKey("vsmusername") ? vsmCredentials.get("vsmusername") : null;
|
||||||
|
String vsmPassword = vsmCredentials.containsKey("vsmpassword") ? vsmCredentials.get("vsmpassword") : null;
|
||||||
|
if(vsmIp == null || vsmIp.isEmpty() || vsmUserName == null || vsmUserName.isEmpty() || vsmPassword == null || vsmPassword.isEmpty()) {
|
||||||
|
msg = "Detected invalid credentials for Nexus VSM";
|
||||||
|
s_logger.error(msg);
|
||||||
|
throw new CloudRuntimeException(msg);
|
||||||
|
}
|
||||||
|
return vsmCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createPortProfile(VmwareContext context, String ethPortProfileName, String networkName, Integer vid, Integer networkRateMbps) throws Exception, CloudRuntimeException {
|
||||||
|
Map<String, String> vsmCredentials = getValidatedVsmCredentials(context);
|
||||||
|
String vsmIp = vsmCredentials.get("vsmip");
|
||||||
|
String vsmUserName = vsmCredentials.get("vsmusername");
|
||||||
|
String vsmPassword = vsmCredentials.get("vsmpassword");
|
||||||
|
String msg;
|
||||||
|
|
||||||
|
NetconfHelper netconfClient;
|
||||||
|
try {
|
||||||
|
netconfClient = new NetconfHelper(vsmIp, vsmUserName, vsmPassword);
|
||||||
|
} catch(CloudRuntimeException e) {
|
||||||
|
msg = "Failed to connect to Nexus VSM " + vsmIp + " with credentials of user " + vsmUserName;
|
||||||
|
s_logger.error(msg);
|
||||||
|
throw new CloudRuntimeException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Pair<OperationType, String>> params = new ArrayList<Pair<OperationType, String>>();
|
||||||
|
params.add(new Pair<OperationType, String>(OperationType.addvlanid, vid.toString()));
|
||||||
|
params.add(new Pair<OperationType, String>(OperationType.setrate, networkRateMbps.toString()));
|
||||||
|
|
||||||
|
try {
|
||||||
|
netconfClient.updatePortProfile(ethPortProfileName, SwitchPortMode.access, params);
|
||||||
|
} catch(CloudRuntimeException e) {
|
||||||
|
msg = "Failed to modify ethernet port profile " + ethPortProfileName + " with parameters " + params.toString();
|
||||||
|
s_logger.error(msg);
|
||||||
|
throw new CloudRuntimeException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
netconfClient.addPortProfile(networkName, PortProfileType.vethernet, BindingType.portbindingstatic, SwitchPortMode.access, vid, networkRateMbps);
|
||||||
|
} catch(CloudRuntimeException e) {
|
||||||
|
msg = "Failed to add vethernet port profile " + networkName + " with parameters " + params.toString();
|
||||||
|
s_logger.error(msg);
|
||||||
|
throw new CloudRuntimeException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updatePortProfile(VmwareContext context, String ethPortProfileName, Integer vid, Integer networkRateMbps) throws CloudRuntimeException, Exception {
|
||||||
|
Map<String, String> vsmCredentials = getValidatedVsmCredentials(context);
|
||||||
|
String vsmIp = vsmCredentials.get("vsmip");
|
||||||
|
String vsmUserName = vsmCredentials.get("vsmusername");
|
||||||
|
String vsmPassword = vsmCredentials.get("vsmpassword");
|
||||||
|
String msg;
|
||||||
|
|
||||||
|
NetconfHelper netconfClient;
|
||||||
|
try {
|
||||||
|
netconfClient = new NetconfHelper(vsmIp, vsmUserName, vsmPassword);
|
||||||
|
} catch(CloudRuntimeException e) {
|
||||||
|
msg = "Failed to connect to Nexus VSM " + vsmIp + " with credentials of user " + vsmUserName;
|
||||||
|
s_logger.error(msg);
|
||||||
|
throw new CloudRuntimeException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Pair<OperationType, String>> params = new ArrayList<Pair<OperationType, String>>();
|
||||||
|
params.add(new Pair<OperationType, String>(OperationType.addvlanid, vid.toString()));
|
||||||
|
params.add(new Pair<OperationType, String>(OperationType.setrate, networkRateMbps.toString()));
|
||||||
|
|
||||||
|
try {
|
||||||
|
netconfClient.updatePortProfile(ethPortProfileName, SwitchPortMode.access, params);
|
||||||
|
} catch(CloudRuntimeException e) {
|
||||||
|
msg = "Failed to modify ethernet port profile " + ethPortProfileName + " with parameters " + params.toString();
|
||||||
|
s_logger.error(msg);
|
||||||
|
throw new CloudRuntimeException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Pair<ManagedObjectReference, String> prepareNetwork(String ethPortProfileName, String namePrefix,
|
||||||
|
HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps,
|
||||||
|
long timeOutMs) throws Exception, CloudRuntimeException {
|
||||||
|
ManagedObjectReference morNetwork = null;
|
||||||
|
VmwareContext context = hostMo.getContext();
|
||||||
|
|
||||||
|
ManagedObjectReference morEthernetPortProfile = hostMo.getDvPortGroupMor(ethPortProfileName);
|
||||||
|
|
||||||
|
if (morEthernetPortProfile == null) {
|
||||||
|
String msg = "Unable to find Ethernet port profile " + ethPortProfileName;
|
||||||
|
s_logger.error(msg);
|
||||||
|
throw new Exception(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean createGCTag = false;
|
||||||
|
String networkName;
|
||||||
|
Integer vid = null;
|
||||||
|
|
||||||
|
if(vlanId != null && !UNTAGGED_VLAN_NAME.equalsIgnoreCase(vlanId)) {
|
||||||
|
createGCTag = true;
|
||||||
|
vid = Integer.parseInt(vlanId);
|
||||||
|
}
|
||||||
|
|
||||||
|
networkName = composeCloudNetworkName(namePrefix, vlanId, networkRateMbps, ethPortProfileName);
|
||||||
|
|
||||||
|
DVSTrafficShapingPolicy shapingPolicy = null;
|
||||||
|
if(networkRateMbps != null && networkRateMbps.intValue() > 0) {
|
||||||
|
shapingPolicy = new DVSTrafficShapingPolicy();
|
||||||
|
BoolPolicy isEnabled = new BoolPolicy();
|
||||||
|
LongPolicy averageBandwidth = new LongPolicy();
|
||||||
|
LongPolicy peakBandwidth = new LongPolicy();
|
||||||
|
LongPolicy burstSize = new LongPolicy();
|
||||||
|
|
||||||
|
isEnabled.setValue(true);
|
||||||
|
averageBandwidth.setValue((long)networkRateMbps.intValue()*1024L*1024L);
|
||||||
|
// We chose 50% higher allocation than average bandwidth.
|
||||||
|
// TODO(sateesh): Also let user specify the peak coefficient
|
||||||
|
peakBandwidth.setValue((long)(averageBandwidth.getValue()*1.5));
|
||||||
|
// TODO(sateesh): Also let user specify the burst coefficient
|
||||||
|
burstSize.setValue((long)(5*averageBandwidth.getValue()/8));
|
||||||
|
|
||||||
|
shapingPolicy.setEnabled(isEnabled);
|
||||||
|
shapingPolicy.setAverageBandwidth(averageBandwidth);
|
||||||
|
shapingPolicy.setPeakBandwidth(peakBandwidth);
|
||||||
|
shapingPolicy.setBurstSize(burstSize);
|
||||||
|
}
|
||||||
|
boolean bWaitPortGroupReady = false;
|
||||||
|
if (!hostMo.hasDvPortGroup(networkName)) {
|
||||||
|
createPortProfile(context, ethPortProfileName, networkName, vid, networkRateMbps);
|
||||||
|
bWaitPortGroupReady = true;
|
||||||
|
} else {
|
||||||
|
DVPortgroupConfigSpec spec = hostMo.getDvPortGroupSpec(networkName);
|
||||||
|
if(!isSpecMatch(spec, vid, shapingPolicy)) {
|
||||||
|
updatePortProfile(context, ethPortProfileName, vid, networkRateMbps);
|
||||||
|
bWaitPortGroupReady = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Wait for dvPortGroup on vCenter
|
||||||
|
if(bWaitPortGroupReady)
|
||||||
|
morNetwork = waitForDvPortGroupReady(hostMo, networkName, timeOutMs);
|
||||||
|
else
|
||||||
|
morNetwork = hostMo.getDvPortGroupMor(networkName);
|
||||||
|
if (morNetwork == null) {
|
||||||
|
String msg = "Failed to create guest network " + networkName;
|
||||||
|
s_logger.error(msg);
|
||||||
|
throw new Exception(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(createGCTag) {
|
||||||
|
NetworkMO networkMo = new NetworkMO(hostMo.getContext(), morNetwork);
|
||||||
|
networkMo.setCustomFieldValue(CustomFieldConstants.CLOUD_GC, "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Pair<ManagedObjectReference, String>(morNetwork, networkName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ManagedObjectReference waitForDvPortGroupReady(
|
||||||
|
HostMO hostMo, String dvPortGroupName, long timeOutMs) throws Exception {
|
||||||
|
ManagedObjectReference morDvPortGroup = null;
|
||||||
|
|
||||||
|
// if DvPortGroup is just created, we may fail to retrieve it, we
|
||||||
|
// need to retry
|
||||||
|
long startTick = System.currentTimeMillis();
|
||||||
|
while (System.currentTimeMillis() - startTick <= timeOutMs) {
|
||||||
|
morDvPortGroup = hostMo.getDvPortGroupMor(dvPortGroupName);
|
||||||
|
if (morDvPortGroup != null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
s_logger.info("Waiting for dvPortGroup " + dvPortGroupName + " to be ready");
|
||||||
|
Thread.sleep(1000);
|
||||||
|
}
|
||||||
|
return morDvPortGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isSpecMatch(DVPortgroupConfigSpec spec, Integer vid,
|
||||||
|
DVSTrafficShapingPolicy shapingPolicy) {
|
||||||
|
DVSTrafficShapingPolicy currentTrafficShapingPolicy;
|
||||||
|
currentTrafficShapingPolicy = spec.getDefaultPortConfig().getInShapingPolicy();
|
||||||
|
// TODO(sateesh): Extract and compare vendor specific configuration specification as well.
|
||||||
|
// DistributedVirtualSwitchKeyedOpaqueBlob[] vendorSpecificConfig = spec.getVendorSpecificConfig();
|
||||||
|
|
||||||
|
assert(currentTrafficShapingPolicy != null);
|
||||||
|
|
||||||
|
LongPolicy averageBandwidth = currentTrafficShapingPolicy.getAverageBandwidth();
|
||||||
|
LongPolicy burstSize = currentTrafficShapingPolicy.getBurstSize();
|
||||||
|
LongPolicy peakBandwidth = currentTrafficShapingPolicy.getPeakBandwidth();
|
||||||
|
BoolPolicy isEnabled = currentTrafficShapingPolicy.getEnabled();
|
||||||
|
|
||||||
|
if(!isEnabled.getValue())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(averageBandwidth != null && !averageBandwidth.equals(shapingPolicy.getAverageBandwidth())) {
|
||||||
|
if(s_logger.isInfoEnabled()) {
|
||||||
|
s_logger.info("Average bandwidth setting in shaping policy doesn't match with existing setting.");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} else if(burstSize != null && !burstSize.equals(shapingPolicy.getBurstSize())) {
|
||||||
|
if(s_logger.isInfoEnabled()) {
|
||||||
|
s_logger.info("Burst size setting in shaping policy doesn't match with existing setting.");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} else if(peakBandwidth != null && !peakBandwidth.equals(shapingPolicy.getPeakBandwidth())) {
|
||||||
|
if(s_logger.isInfoEnabled()) {
|
||||||
|
s_logger.info("Peak bandwidth setting in shaping policy doesn't match with existing setting.");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public static Pair<ManagedObjectReference, String> prepareNetwork(String vSwitchName, String namePrefix,
|
public static Pair<ManagedObjectReference, String> prepareNetwork(String vSwitchName, String namePrefix,
|
||||||
HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps,
|
HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps,
|
||||||
long timeOutMs, boolean syncPeerHosts) throws Exception {
|
long timeOutMs, boolean syncPeerHosts) throws Exception {
|
||||||
|
|||||||
@ -66,7 +66,6 @@ public class VmwareContext {
|
|||||||
private Map<String, Object> _stockMap = new HashMap<String, Object>();
|
private Map<String, Object> _stockMap = new HashMap<String, Object>();
|
||||||
private int _CHUNKSIZE = 1*1024*1024; // 1M
|
private int _CHUNKSIZE = 1*1024*1024; // 1M
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
|
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user