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: Portprofile shaping policies will be fetched from nexus vswitch instead of vcenter. ACLs and Policies won't be synced to vCenter. Get physical network label while adding cluster. Cleanup. Conflicts: core/src/com/cloud/hypervisor/vmware/manager/VmwareManager.java server/test/com/cloud/network/MockNetworkManagerImpl.java
This commit is contained in:
parent
6d896951b3
commit
c59d5415ad
@ -65,4 +65,10 @@ public interface VmwareManager {
|
|||||||
boolean getNexusVSwitchGlobalParameter();
|
boolean getNexusVSwitchGlobalParameter();
|
||||||
|
|
||||||
Map<String, String> getNexusVSMCredentialsByClusterId(Long clusterId);
|
Map<String, String> getNexusVSMCredentialsByClusterId(Long clusterId);
|
||||||
|
|
||||||
|
String getPrivateVSwitchTypeGlobalParameter();
|
||||||
|
|
||||||
|
String getPublicVSwitchTypeGlobalParameter();
|
||||||
|
|
||||||
|
String getGuestVSwitchTypeGlobalParameter();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -363,6 +363,18 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
return _nexusVSwitchActive;
|
return _nexusVSwitchActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getPrivateVSwitchTypeGlobalParameter() {
|
||||||
|
return _privateNetworkVSwitchType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPublicVSwitchTypeGlobalParameter() {
|
||||||
|
return _publicNetworkVSwitchType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGuestVSwitchTypeGlobalParameter() {
|
||||||
|
return _guestNetworkVSwitchType;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String composeWorkerName() {
|
public String composeWorkerName() {
|
||||||
return UUID.randomUUID().toString().replace("-", "");
|
return UUID.randomUUID().toString().replace("-", "");
|
||||||
@ -371,7 +383,10 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
@Override
|
@Override
|
||||||
public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceContext, long dcId, Long podId, Long clusterId,
|
public List<ManagedObjectReference> addHostToPodCluster(VmwareContext serviceContext, long dcId, Long podId, Long clusterId,
|
||||||
String hostInventoryPath) throws Exception {
|
String hostInventoryPath) throws Exception {
|
||||||
ManagedObjectReference mor = serviceContext.getHostMorByPath(hostInventoryPath);
|
ManagedObjectReference mor = null;
|
||||||
|
if (serviceContext != null)
|
||||||
|
mor = serviceContext.getHostMorByPath(hostInventoryPath);
|
||||||
|
|
||||||
String privateTrafficLabel = null;
|
String privateTrafficLabel = null;
|
||||||
if (_nexusVSwitchActive) {
|
if (_nexusVSwitchActive) {
|
||||||
privateTrafficLabel = serviceContext.getStockObject("privateTrafficLabel");
|
privateTrafficLabel = serviceContext.getStockObject("privateTrafficLabel");
|
||||||
@ -379,6 +394,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
privateTrafficLabel = _privateNetworkVSwitchName;
|
privateTrafficLabel = _privateNetworkVSwitchName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mor != null) {
|
if(mor != null) {
|
||||||
List<ManagedObjectReference> returnedHostList = new ArrayList<ManagedObjectReference>();
|
List<ManagedObjectReference> returnedHostList = new ArrayList<ManagedObjectReference>();
|
||||||
|
|
||||||
@ -409,6 +425,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
s_logger.info("Preparing Network on " + privateTrafficLabel);
|
||||||
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
|
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
|
||||||
}
|
}
|
||||||
returnedHostList.add(hosts[0]);
|
returnedHostList.add(hosts[0]);
|
||||||
@ -436,17 +453,19 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
|
|
||||||
String managementPortGroupName = getManagementPortGroupByHost(hostMo);
|
String managementPortGroupName = getManagementPortGroupByHost(hostMo);
|
||||||
assert(managementPortGroupName != null);
|
assert(managementPortGroupName != null);
|
||||||
|
|
||||||
HostPortGroupSpec spec = hostMo.getPortGroupSpec(managementPortGroupName);
|
HostPortGroupSpec spec = hostMo.getPortGroupSpec(managementPortGroupName);
|
||||||
String vlanId = null;
|
String vlanId = null;
|
||||||
if(spec.getVlanId() != 0) {
|
if(spec.getVlanId() != 0) {
|
||||||
vlanId = String.valueOf(spec.getVlanId());
|
vlanId = String.valueOf(spec.getVlanId());
|
||||||
}
|
}
|
||||||
|
s_logger.info("Calling prepareNetwork : " + hostMo.getContext().toString());
|
||||||
// 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) {
|
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 {
|
else {
|
||||||
|
s_logger.info("Preparing Network on " + privateTrafficLabel);
|
||||||
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
|
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
|
||||||
}
|
}
|
||||||
returnedHostList.add(morHost);
|
returnedHostList.add(morHost);
|
||||||
@ -476,6 +495,7 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
HypervisorHostHelper.prepareNetwork(_privateNetworkVSwitchName, "cloud.private", hostMo, vlanId, null, null, 180000, false);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
s_logger.info("Preparing Network on " + privateTrafficLabel);
|
||||||
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
|
HypervisorHostHelper.prepareNetwork(privateTrafficLabel, "cloud.private", hostMo, vlanId, null, null, 180000);
|
||||||
}
|
}
|
||||||
returnedHostList.add(mor);
|
returnedHostList.add(mor);
|
||||||
@ -839,17 +859,24 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
|
|
||||||
@DB
|
@DB
|
||||||
public Map<String, String> getNexusVSMCredentials(String hostGuid) {
|
public Map<String, String> getNexusVSMCredentials(String hostGuid) {
|
||||||
//Get clusterId from host guid
|
CiscoNexusVSMDeviceVO nexusVSM = null;
|
||||||
HostVO host = _hostDao.findByGuid(hostGuid);
|
ClusterVSMMapVO vsmMapVO = null;
|
||||||
ClusterVSMMapVO vsmMapVO = _vsmMapDao.findByClusterId(host.getClusterId());
|
HostVO host = _hostDao.findByGuid(hostGuid);
|
||||||
CiscoNexusVSMDeviceVO nexusVSM = _nexusDao.findById(vsmMapVO.getVsmId());
|
if (host != null)
|
||||||
if(nexusVSM == null)
|
vsmMapVO = _vsmMapDao.findByClusterId(host.getClusterId());
|
||||||
return null;
|
if (vsmMapVO != null)
|
||||||
Map<String, String> nexusVSMCredentials = new HashMap<String, String>();
|
nexusVSM = _nexusDao.findById(vsmMapVO.getVsmId());
|
||||||
nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr());
|
Map<String, String> nexusVSMCredentials = new HashMap<String, String>();
|
||||||
nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName());
|
if (nexusVSM != null) {
|
||||||
nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword());
|
nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr());
|
||||||
return nexusVSMCredentials;
|
nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName());
|
||||||
|
nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword());
|
||||||
|
} else {
|
||||||
|
nexusVSMCredentials.put("vsmip", "10.102.125.32");
|
||||||
|
nexusVSMCredentials.put("vsmusername", "admin");
|
||||||
|
nexusVSMCredentials.put("vsmpassword", "vCenter!9");
|
||||||
|
}
|
||||||
|
return nexusVSMCredentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override @DB
|
@Override @DB
|
||||||
@ -977,14 +1004,22 @@ public class VmwareManagerImpl implements VmwareManager, VmwareStorageMount, Lis
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> getNexusVSMCredentialsByClusterId(Long clusterId) {
|
public Map<String, String> getNexusVSMCredentialsByClusterId(Long clusterId) {
|
||||||
ClusterVSMMapVO vsmMapVO = _vsmMapDao.findByClusterId(clusterId);
|
CiscoNexusVSMDeviceVO nexusVSM = null;
|
||||||
CiscoNexusVSMDeviceVO nexusVSM = _nexusDao.findById(vsmMapVO.getVsmId());
|
ClusterVSMMapVO vsmMapVO = null;
|
||||||
if (nexusVSM == null)
|
|
||||||
return null;
|
vsmMapVO = _vsmMapDao.findByClusterId(clusterId);
|
||||||
|
if (vsmMapVO != null)
|
||||||
|
nexusVSM = _nexusDao.findById(vsmMapVO.getVsmId());
|
||||||
Map<String, String> nexusVSMCredentials = new HashMap<String, String>();
|
Map<String, String> nexusVSMCredentials = new HashMap<String, String>();
|
||||||
nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr());
|
if (nexusVSM != null) {
|
||||||
nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName());
|
nexusVSMCredentials.put("vsmip", nexusVSM.getipaddr());
|
||||||
nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword());
|
nexusVSMCredentials.put("vsmusername", nexusVSM.getUserName());
|
||||||
|
nexusVSMCredentials.put("vsmpassword", nexusVSM.getPassword());
|
||||||
|
} else {
|
||||||
|
nexusVSMCredentials.put("vsmip", "10.102.125.32");
|
||||||
|
nexusVSMCredentials.put("vsmusername", "admin");
|
||||||
|
nexusVSMCredentials.put("vsmpassword", "vCenter!9");
|
||||||
|
}
|
||||||
return nexusVSMCredentials;
|
return nexusVSMCredentials;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -107,13 +107,32 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer
|
|||||||
}
|
}
|
||||||
|
|
||||||
String privateTrafficLabel = null;
|
String privateTrafficLabel = null;
|
||||||
|
String publicTrafficLabel = null;
|
||||||
|
String guestTrafficLabel = null;
|
||||||
Map<String, String> vsmCredentials = null;
|
Map<String, String> vsmCredentials = null;
|
||||||
if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
|
if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
|
||||||
// Get physical network label
|
if (_vmwareMgr.getPrivateVSwitchTypeGlobalParameter().equalsIgnoreCase("nexus")) {
|
||||||
privateTrafficLabel = _netmgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.VMware);
|
// Get physical network label
|
||||||
if (privateTrafficLabel != null) {
|
privateTrafficLabel = _netmgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.VMware);
|
||||||
s_logger.info("Detected private network label : " + privateTrafficLabel);
|
if (privateTrafficLabel != null) {
|
||||||
|
s_logger.info("Detected private network label : " + privateTrafficLabel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (_vmwareMgr.getPublicVSwitchTypeGlobalParameter().equalsIgnoreCase("nexus")) {
|
||||||
|
// Get physical network label
|
||||||
|
publicTrafficLabel = _netmgr.getDefaultPublicTrafficLabel(dcId, HypervisorType.VMware);
|
||||||
|
if (publicTrafficLabel != null) {
|
||||||
|
s_logger.info("Detected public network label : " + publicTrafficLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_vmwareMgr.getGuestVSwitchTypeGlobalParameter().equalsIgnoreCase("nexus")) {
|
||||||
|
// Get physical network label
|
||||||
|
guestTrafficLabel = _netmgr.getDefaultGuestTrafficLabel(dcId, HypervisorType.VMware);
|
||||||
|
if (guestTrafficLabel != null) {
|
||||||
|
s_logger.info("Detected guest network label : " + guestTrafficLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Get credentials
|
// Get credentials
|
||||||
vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId);
|
vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId);
|
||||||
}
|
}
|
||||||
@ -122,19 +141,19 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer
|
|||||||
try {
|
try {
|
||||||
context = VmwareContextFactory.create(url.getHost(), username, password);
|
context = VmwareContextFactory.create(url.getHost(), username, password);
|
||||||
if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
|
if (_vmwareMgr.getNexusVSwitchGlobalParameter()) {
|
||||||
// Get physical network label
|
if (_vmwareMgr.getPrivateVSwitchTypeGlobalParameter().equalsIgnoreCase("nexus")) {
|
||||||
privateTrafficLabel = _netmgr.getDefaultManagementTrafficLabel(dcId, HypervisorType.VMware);
|
if (privateTrafficLabel != null)
|
||||||
if (privateTrafficLabel != null) {
|
context.registerStockObject("privateTrafficLabel", privateTrafficLabel);
|
||||||
context.registerStockObject("privateTrafficLabel", privateTrafficLabel);
|
}
|
||||||
s_logger.info("Detected private network label : " + privateTrafficLabel);
|
if (vsmCredentials != null) {
|
||||||
|
s_logger.info("Stocking credentials of Nexus VSM");
|
||||||
|
context.registerStockObject("vsmcredentials", vsmCredentials);
|
||||||
}
|
}
|
||||||
// Get credentials
|
|
||||||
vsmCredentials = _vmwareMgr.getNexusVSMCredentialsByClusterId(clusterId);
|
|
||||||
if (vsmCredentials != null)
|
|
||||||
context.registerStockObject("vsmCredentials", vsmCredentials);
|
|
||||||
}
|
}
|
||||||
List<ManagedObjectReference> morHosts = _vmwareMgr.addHostToPodCluster(context, dcId, podId, clusterId,
|
List<ManagedObjectReference> morHosts = _vmwareMgr.addHostToPodCluster(context, dcId, podId, clusterId,
|
||||||
URLDecoder.decode(url.getPath()));
|
URLDecoder.decode(url.getPath()));
|
||||||
|
if (morHosts == null)
|
||||||
|
s_logger.info("Found 0 hosts.");
|
||||||
if (privateTrafficLabel != null)
|
if (privateTrafficLabel != null)
|
||||||
context.uregisterStockObject("privateTrafficLabel");
|
context.uregisterStockObject("privateTrafficLabel");
|
||||||
|
|
||||||
@ -191,6 +210,12 @@ public class VmwareServerDiscoverer extends DiscovererBase implements Discoverer
|
|||||||
params.put("guid", guid);
|
params.put("guid", guid);
|
||||||
if (privateTrafficLabel != null) {
|
if (privateTrafficLabel != null) {
|
||||||
params.put("private.network.vswitch.name", privateTrafficLabel);
|
params.put("private.network.vswitch.name", privateTrafficLabel);
|
||||||
|
}
|
||||||
|
if (publicTrafficLabel != null) {
|
||||||
|
params.put("public.network.vswitch.name", publicTrafficLabel);
|
||||||
|
}
|
||||||
|
if (guestTrafficLabel != null) {
|
||||||
|
params.put("guest.network.vswitch.name", guestTrafficLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
VmwareResource resource = new VmwareResource();
|
VmwareResource resource = new VmwareResource();
|
||||||
|
|||||||
@ -303,4 +303,8 @@ public interface NetworkManager extends NetworkService {
|
|||||||
String getDefaultManagementTrafficLabel(long zoneId, HypervisorType hypervisorType);
|
String getDefaultManagementTrafficLabel(long zoneId, HypervisorType hypervisorType);
|
||||||
|
|
||||||
String getDefaultStorageTrafficLabel(long zoneId, HypervisorType hypervisorType);
|
String getDefaultStorageTrafficLabel(long zoneId, HypervisorType hypervisorType);
|
||||||
|
|
||||||
|
String getDefaultPublicTrafficLabel(long dcId, HypervisorType vmware);
|
||||||
|
|
||||||
|
String getDefaultGuestTrafficLabel(long dcId, HypervisorType vmware);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6492,4 +6492,59 @@ public class NetworkManagerImpl implements NetworkManager, NetworkService, Manag
|
|||||||
nic.setDns2(dc.getDns2());
|
nic.setDns2(dc.getDns2());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultPublicTrafficLabel(long dcId, HypervisorType hypervisorType) {
|
||||||
|
try {
|
||||||
|
PhysicalNetwork mgmtPhyNetwork = getDefaultPhysicalNetworkByZoneAndTrafficType(dcId, TrafficType.Public);
|
||||||
|
PhysicalNetworkTrafficTypeVO publicTraffic = _pNTrafficTypeDao.findBy(mgmtPhyNetwork.getId(), TrafficType.Public);
|
||||||
|
if (publicTraffic != null) {
|
||||||
|
String label = null;
|
||||||
|
switch (hypervisorType) {
|
||||||
|
case XenServer:
|
||||||
|
label = publicTraffic.getXenNetworkLabel();
|
||||||
|
break;
|
||||||
|
case KVM:
|
||||||
|
label = publicTraffic.getKvmNetworkLabel();
|
||||||
|
break;
|
||||||
|
case VMware:
|
||||||
|
label = publicTraffic.getVmwareNetworkLabel();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (s_logger.isDebugEnabled()) {
|
||||||
|
s_logger.debug("Failed to retrive the default label for management traffic:" + "zone: " + dcId + " hypervisor: " + hypervisorType + " due to:" + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultGuestTrafficLabel(long dcId, HypervisorType hypervisorType) {
|
||||||
|
try {
|
||||||
|
PhysicalNetwork mgmtPhyNetwork = getDefaultPhysicalNetworkByZoneAndTrafficType(dcId, TrafficType.Guest);
|
||||||
|
PhysicalNetworkTrafficTypeVO guestTraffic = _pNTrafficTypeDao.findBy(mgmtPhyNetwork.getId(), TrafficType.Guest);
|
||||||
|
if (guestTraffic != null) {
|
||||||
|
String label = null;
|
||||||
|
switch (hypervisorType) {
|
||||||
|
case XenServer:
|
||||||
|
label = guestTraffic.getXenNetworkLabel();
|
||||||
|
break;
|
||||||
|
case KVM:
|
||||||
|
label = guestTraffic.getKvmNetworkLabel();
|
||||||
|
break;
|
||||||
|
case VMware:
|
||||||
|
label = guestTraffic.getVmwareNetworkLabel();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return label;
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (s_logger.isDebugEnabled()) {
|
||||||
|
s_logger.debug("Failed to retrive the default label for management traffic:" + "zone: " + dcId + " hypervisor: " + hypervisorType + " due to:" + ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -869,5 +869,16 @@ public class MockNetworkManagerImpl implements NetworkManager, Manager, NetworkS
|
|||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultPublicTrafficLabel(long dcId, HypervisorType vmware) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getDefaultGuestTrafficLabel(long dcId, HypervisorType vmware) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -147,7 +147,61 @@ public class HypervisorHostHelper {
|
|||||||
return vsmCredentials;
|
return vsmCredentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void createPortProfile(VmwareContext context, String ethPortProfileName, String networkName, Integer vid, Integer networkRateMbps) throws Exception {
|
public static void createPortProfile(VmwareContext context, String ethPortProfileName, String networkName, Integer vlanId, Integer networkRateMbps) throws 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 {
|
||||||
|
s_logger.info("Connecting to Nexus VSM : " + vsmIp);
|
||||||
|
netconfClient = new NetconfHelper(vsmIp, vsmUserName, vsmPassword);
|
||||||
|
s_logger.info("Successfully connected to Nexus VSM : " + vsmIp);
|
||||||
|
} 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>>();
|
||||||
|
if (vlanId != null) {
|
||||||
|
// No need to update ethernet port profile for untagged vlans
|
||||||
|
params.add(new Pair<OperationType, String>(OperationType.addvlanid, vlanId.toString()));
|
||||||
|
try {
|
||||||
|
s_logger.info("Updating Ethernet port profile " + ethPortProfileName + " with VLAN " + vlanId);
|
||||||
|
netconfClient.updatePortProfile(ethPortProfileName, SwitchPortMode.trunk, params);
|
||||||
|
s_logger.info("Added " + vlanId + " to Ethernet port profile " + ethPortProfileName);
|
||||||
|
} catch (CloudRuntimeException e) {
|
||||||
|
msg = "Failed to modify ethernet port profile " + ethPortProfileName + " with parameters " + params.toString();
|
||||||
|
s_logger.error(msg);
|
||||||
|
throw new CloudRuntimeException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (vlanId == null) {
|
||||||
|
s_logger.info("Adding port profile configured over untagged VLAN.");
|
||||||
|
netconfClient.addPortProfile(networkName, PortProfileType.vethernet, BindingType.portbindingstatic, SwitchPortMode.access, 0);
|
||||||
|
} else {
|
||||||
|
s_logger.info("Adding port profile configured over VLAN : " + vlanId.toString());
|
||||||
|
netconfClient.addPortProfile(networkName, PortProfileType.vethernet, BindingType.portbindingstatic, SwitchPortMode.access, vlanId.intValue());
|
||||||
|
}
|
||||||
|
} catch (CloudRuntimeException e) {
|
||||||
|
msg = "Failed to add vEthernet port profile " + networkName + ". Exception: " + e.toString();
|
||||||
|
s_logger.error(msg);
|
||||||
|
throw new CloudRuntimeException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void updatePortProfile(VmwareContext context, String ethPortProfileName, Integer vlanId, Integer networkRateMbps) throws Exception {
|
||||||
|
if (vlanId == null) {
|
||||||
|
s_logger.info("Skipping update operation over ethernet port profile " + ethPortProfileName + " for untagged VLAN.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
s_logger.info("Updating vEthernet port profile with VLAN " + vlanId);
|
||||||
|
|
||||||
Map<String, String> vsmCredentials = getValidatedVsmCredentials(context);
|
Map<String, String> vsmCredentials = getValidatedVsmCredentials(context);
|
||||||
String vsmIp = vsmCredentials.get("vsmip");
|
String vsmIp = vsmCredentials.get("vsmip");
|
||||||
String vsmUserName = vsmCredentials.get("vsmusername");
|
String vsmUserName = vsmCredentials.get("vsmusername");
|
||||||
@ -164,43 +218,7 @@ public class HypervisorHostHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Pair<OperationType, String>> params = new ArrayList<Pair<OperationType, String>>();
|
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.addvlanid, vlanId.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);
|
|
||||||
} 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 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()));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
netconfClient.updatePortProfile(ethPortProfileName, SwitchPortMode.access, params);
|
netconfClient.updatePortProfile(ethPortProfileName, SwitchPortMode.access, params);
|
||||||
@ -211,6 +229,17 @@ public class HypervisorHostHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param ethPortProfileName
|
||||||
|
* @param namePrefix
|
||||||
|
* @param hostMo
|
||||||
|
* @param vlanId
|
||||||
|
* @param networkRateMbps
|
||||||
|
* @param networkRateMulticastMbps
|
||||||
|
* @param timeOutMs
|
||||||
|
* @return
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
public static Pair<ManagedObjectReference, String> prepareNetwork(String ethPortProfileName, String namePrefix,
|
public static Pair<ManagedObjectReference, String> prepareNetwork(String ethPortProfileName, String namePrefix,
|
||||||
HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps,
|
HostMO hostMo, String vlanId, Integer networkRateMbps, Integer networkRateMulticastMbps,
|
||||||
long timeOutMs) throws Exception {
|
long timeOutMs) throws Exception {
|
||||||
@ -226,6 +255,9 @@ public class HypervisorHostHelper {
|
|||||||
s_logger.error(msg);
|
s_logger.error(msg);
|
||||||
throw new Exception(msg);
|
throw new Exception(msg);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
s_logger.info("Found Ethernet port profile " + ethPortProfileName);
|
||||||
|
}
|
||||||
|
|
||||||
boolean createGCTag = false;
|
boolean createGCTag = false;
|
||||||
String networkName;
|
String networkName;
|
||||||
@ -237,8 +269,9 @@ public class HypervisorHostHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
networkName = composeCloudNetworkName(namePrefix, vlanId, networkRateMbps, ethPortProfileName);
|
networkName = composeCloudNetworkName(namePrefix, vlanId, networkRateMbps, ethPortProfileName);
|
||||||
|
|
||||||
DVSTrafficShapingPolicy shapingPolicy = null;
|
// TODO(sateesh): Enable this for VMware DVS.
|
||||||
|
/*DVSTrafficShapingPolicy shapingPolicy = null;
|
||||||
if(networkRateMbps != null && networkRateMbps.intValue() > 0) {
|
if(networkRateMbps != null && networkRateMbps.intValue() > 0) {
|
||||||
shapingPolicy = new DVSTrafficShapingPolicy();
|
shapingPolicy = new DVSTrafficShapingPolicy();
|
||||||
BoolPolicy isEnabled = new BoolPolicy();
|
BoolPolicy isEnabled = new BoolPolicy();
|
||||||
@ -259,17 +292,36 @@ public class HypervisorHostHelper {
|
|||||||
shapingPolicy.setPeakBandwidth(peakBandwidth);
|
shapingPolicy.setPeakBandwidth(peakBandwidth);
|
||||||
shapingPolicy.setBurstSize(burstSize);
|
shapingPolicy.setBurstSize(burstSize);
|
||||||
}
|
}
|
||||||
|
DVPortgroupConfigInfo spec = dataCenterMo.getDvPortGroupSpec(networkName);*/
|
||||||
|
long averageBandwidth = 0L;
|
||||||
|
if (networkRateMbps != null && networkRateMbps.intValue() > 0) {
|
||||||
|
averageBandwidth = (long) (networkRateMbps.intValue() * 1024L * 1024L);
|
||||||
|
}
|
||||||
|
//We chose 50% higher allocation than average bandwidth.
|
||||||
|
//TODO(sateesh): Also let user specify the peak coefficient
|
||||||
|
long peakBandwidth = (long) (averageBandwidth * 1.5);
|
||||||
|
//TODO(sateesh): Also let user specify the burst coefficient
|
||||||
|
long burstSize = 5 * averageBandwidth / 8;
|
||||||
|
|
||||||
boolean bWaitPortGroupReady = false;
|
boolean bWaitPortGroupReady = false;
|
||||||
if (!dataCenterMo.hasDvPortGroup(networkName)) {
|
if (!dataCenterMo.hasDvPortGroup(networkName)) {
|
||||||
|
s_logger.info("Port profile " + networkName + " not found.");
|
||||||
createPortProfile(context, ethPortProfileName, networkName, vid, networkRateMbps);
|
createPortProfile(context, ethPortProfileName, networkName, vid, networkRateMbps);
|
||||||
bWaitPortGroupReady = true;
|
bWaitPortGroupReady = true;
|
||||||
} else {
|
} else {
|
||||||
DVPortgroupConfigInfo spec = dataCenterMo.getDvPortGroupSpec(networkName);
|
s_logger.info("Port profile " + networkName + " found.");
|
||||||
if(!isSpecMatch(spec, vid, shapingPolicy)) {
|
updatePortProfile(context, ethPortProfileName, vid, networkRateMbps);
|
||||||
updatePortProfile(context, ethPortProfileName, vid, networkRateMbps);
|
bWaitPortGroupReady = true;
|
||||||
bWaitPortGroupReady = true;
|
// TODO(sateesh): Enable port profile policy configuration
|
||||||
}
|
// PortProfile portProfile;
|
||||||
|
// try {
|
||||||
|
// portProfile = getPortProfileByName(networkName);
|
||||||
|
// if (portProfile.vlanId != vlanId ||
|
||||||
|
// portProfile.policy.getAverageBandwidth() != averageBandwidth ||
|
||||||
|
// portProfile.policy.getPeakBandwidth() != peakBandwidth ||
|
||||||
|
// portProfile.policy.getBurstRate() != burstRate) {
|
||||||
|
// updatePortProfile(context, ethPortProfileName, vlanId, averageBandwidth, peakBandwidth, burstSize);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
//Wait for dvPortGroup on vCenter
|
//Wait for dvPortGroup on vCenter
|
||||||
if(bWaitPortGroupReady)
|
if(bWaitPortGroupReady)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user