mirror of https://github.com/apache/cloudstack.git
CS-9919: Support for Nexus Swiches (Cisco Vswitches)
Description: Incorporating more changes post review by Alena. 1. Renamed the ListCiscoVSMDetailsCmd command to ListCiscoNexusVSMsCmd. The command will return a list of VSMs always, depending on what parameter is passed to it. If a clusterId is passed to it, it will return the VSM associated to that cluster, if present. If a zoneId is passed in, it will return a list of all VSMs configured for any clusters of type VMware within that zone. If neither is passed, it will return a list of all VSMs configured in the management server. If no VSMs are found, it will return an exception response. 2. Cleaned up miscellaneous code. Conflicts: client/tomcatconf/cisconexusvsm_commands.properties.in server/src/com/cloud/server/ManagementServerImpl.java
This commit is contained in:
parent
5fc5b7a0eb
commit
ed0ba1a0e6
|
|
@ -184,6 +184,10 @@ public abstract class BaseCmd {
|
|||
_responseObject = responseObject;
|
||||
}
|
||||
|
||||
public ManagementService getMgmtServiceRef() {
|
||||
return _mgr;
|
||||
}
|
||||
|
||||
public static String getDateString(Date date) {
|
||||
if (date == null) {
|
||||
return "";
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import com.cloud.api.BaseListCmd;
|
|||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.BaseCmd.CommandType;
|
||||
import com.cloud.api.response.ClusterResponse;
|
||||
import com.cloud.api.response.ListResponse;
|
||||
import com.cloud.org.Cluster;
|
||||
|
|
|
|||
|
|
@ -127,6 +127,13 @@ public interface ManagementService {
|
|||
* @return
|
||||
*/
|
||||
List<? extends Cluster> searchForClusters(ListClustersCmd c);
|
||||
|
||||
/**
|
||||
* Searches for Clusters by the specified zone Id.
|
||||
* @param zoneId
|
||||
* @return
|
||||
*/
|
||||
List<? extends Cluster> searchForClusters(long zoneId, Long startIndex, Long pageSizeVal, String hypervisorType);
|
||||
|
||||
/**
|
||||
* Searches for Pods by the specified search criteria Can search by: pod name and/or zone name
|
||||
|
|
|
|||
|
|
@ -4,5 +4,5 @@
|
|||
#### Cisco Nexus 1000v Virtual Supervisor Module (VSM) commands
|
||||
deleteCiscoNexusVSM = com.cloud.api.commands.DeleteCiscoNexusVSMCmd;1
|
||||
enableCiscoNexusVSM = com.cloud.api.commands.EnableCiscoNexusVSMCmd;1
|
||||
disableCiscoNexusVSM = com.cloud.api.commands.DisableCiscoNexusVSMCmd;1
|
||||
listCiscoVSMDetails = com.cloud.api.commands.ListCiscoVSMDetailsCmd;1
|
||||
disableCiscoNexusVSM = com.cloud.api.commands.DisableCiscoNexusVSMCmd;1
|
||||
listCiscoNexusVSMs = com.cloud.api.commands.ListCiscoNexusVSMsCmd;1
|
||||
|
|
|
|||
|
|
@ -20,13 +20,14 @@ package com.cloud.api.commands;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.BaseListCmd;
|
||||
import com.cloud.api.IdentityMapper;
|
||||
import com.cloud.api.Implementation;
|
||||
import com.cloud.api.Parameter;
|
||||
import com.cloud.api.PlugService;
|
||||
import com.cloud.api.ServerApiException;
|
||||
import com.cloud.api.response.CiscoNexusVSMResponse;
|
||||
import com.cloud.api.response.ListResponse;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
|
|
@ -34,13 +35,22 @@ import com.cloud.exception.ResourceUnavailableException;
|
|||
import com.cloud.network.CiscoNexusVSMDevice;
|
||||
import com.cloud.network.element.CiscoNexusVSMElementService;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.UserContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Implementation(responseObject=CiscoNexusVSMResponse.class, description="Retrieves a Cisco Nexus 1000v Virtual Switch Manager device associated with a Cluster")
|
||||
public class ListCiscoVSMDetailsCmd extends BaseCmd {
|
||||
public class ListCiscoNexusVSMsCmd extends BaseListCmd {
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(ListCiscoVSMDetailsCmd.class.getName());
|
||||
private static final String s_name = "listciscovsmdetailscmdresponse";
|
||||
/**
|
||||
* This command returns a list of all the VSMs configured in the management server.
|
||||
* If a clusterId is specified, it will return a list containing only that VSM
|
||||
* that is associated with that cluster. If a zone is specified, it will pull
|
||||
* up all the clusters of type vmware in that zone, and prepare a list of VSMs
|
||||
* associated with those clusters.
|
||||
*/
|
||||
public static final Logger s_logger = Logger.getLogger(ListCiscoNexusVSMsCmd.class.getName());
|
||||
private static final String s_name = "listcisconexusvsmscmdresponse";
|
||||
@PlugService CiscoNexusVSMElementService _ciscoNexusVSMService;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
|
|
@ -48,8 +58,12 @@ public class ListCiscoVSMDetailsCmd extends BaseCmd {
|
|||
/////////////////////////////////////////////////////
|
||||
|
||||
@IdentityMapper(entityTableName="cluster")
|
||||
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required = true, description="Id of the CloudStack cluster in which the Cisco Nexus 1000v VSM appliance.")
|
||||
@Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, required = false, description="Id of the CloudStack cluster in which the Cisco Nexus 1000v VSM appliance.")
|
||||
private long clusterId;
|
||||
|
||||
@IdentityMapper(entityTableName="data_center")
|
||||
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required = false, description="Id of the CloudStack cluster in which the Cisco Nexus 1000v VSM appliance.")
|
||||
private long zoneId;
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////////// Accessors ///////////////////////
|
||||
|
|
@ -58,6 +72,10 @@ public class ListCiscoVSMDetailsCmd extends BaseCmd {
|
|||
public long getClusterId() {
|
||||
return clusterId;
|
||||
}
|
||||
|
||||
public long getZoneId() {
|
||||
return zoneId;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
/////////////// API Implementation///////////////////
|
||||
|
|
@ -68,14 +86,22 @@ public class ListCiscoVSMDetailsCmd extends BaseCmd {
|
|||
// is invoked. That's the reason why we don't have any uuid-dbid translation code here.
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
|
||||
CiscoNexusVSMDevice vsmDevice = _ciscoNexusVSMService.getCiscoNexusVSMByClusId(this);
|
||||
if (vsmDevice != null) {
|
||||
CiscoNexusVSMResponse response = _ciscoNexusVSMService.createCiscoNexusVSMDetailedResponse(vsmDevice);
|
||||
response.setObjectName("cisconexusvsm");
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to retrieve Cisco Nexus Virtual Switch Manager for the specified cluster due to an internal error.");
|
||||
List<? extends CiscoNexusVSMDevice> vsmDeviceList = _ciscoNexusVSMService.getCiscoNexusVSMs(this);
|
||||
|
||||
if (vsmDeviceList.size() > 0) {
|
||||
ListResponse<CiscoNexusVSMResponse> response = new ListResponse<CiscoNexusVSMResponse>();
|
||||
List<CiscoNexusVSMResponse> vsmResponses = new ArrayList<CiscoNexusVSMResponse>();
|
||||
for (CiscoNexusVSMDevice vsmDevice : vsmDeviceList) {
|
||||
CiscoNexusVSMResponse vsmresponse = _ciscoNexusVSMService.createCiscoNexusVSMDetailedResponse(vsmDevice);
|
||||
vsmresponse.setObjectName("cisconexusvsm");
|
||||
response.setResponseName(getCommandName());
|
||||
vsmResponses.add(vsmresponse);
|
||||
}
|
||||
response.setResponses(vsmResponses);
|
||||
response.setResponseName(getCommandName());
|
||||
this.setResponseObject(response);
|
||||
} else {
|
||||
throw new ServerApiException(BaseListCmd.INTERNAL_ERROR, "No VSM found.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -53,6 +53,13 @@ public interface CiscoNexusVSMDeviceDao extends GenericDao<CiscoNexusVSMDeviceVO
|
|||
*/
|
||||
List<CiscoNexusVSMDeviceVO> listByMgmtVlan(int vlanId);
|
||||
|
||||
/**
|
||||
* Lists all configured VSMs on the management server.
|
||||
* @return
|
||||
*/
|
||||
List<CiscoNexusVSMDeviceVO> listAllVSMs();
|
||||
|
||||
|
||||
/**
|
||||
* Below is a big list of other functions that we may need, but will declare/define/implement once we implement
|
||||
* the functions above. Pasting those below to not lose track of them.
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public class CiscoNexusVSMDeviceDaoImpl extends GenericDaoBase<CiscoNexusVSMDevi
|
|||
final SearchBuilder<CiscoNexusVSMDeviceVO> nameSearch;
|
||||
final SearchBuilder<CiscoNexusVSMDeviceVO> ipaddrSearch;
|
||||
final SearchBuilder<CiscoNexusVSMDeviceVO> genericVlanIdSearch;
|
||||
final SearchBuilder<CiscoNexusVSMDeviceVO> fullTableSearch;
|
||||
// We will add more searchbuilder objects.
|
||||
|
||||
|
||||
|
|
@ -61,6 +62,9 @@ public class CiscoNexusVSMDeviceDaoImpl extends GenericDaoBase<CiscoNexusVSMDevi
|
|||
ipaddrSearch.and("ipaddr", ipaddrSearch.entity().getipaddr(), Op.EQ);
|
||||
ipaddrSearch.done();
|
||||
|
||||
fullTableSearch = createSearchBuilder();
|
||||
fullTableSearch.done();
|
||||
|
||||
// We may add more and conditions by specifying more fields, like say, accountId.
|
||||
}
|
||||
|
||||
|
|
@ -87,6 +91,11 @@ public class CiscoNexusVSMDeviceDaoImpl extends GenericDaoBase<CiscoNexusVSMDevi
|
|||
sc.setParameters("managementVlan", vlanId);
|
||||
return search(sc, null);
|
||||
}
|
||||
|
||||
public List<CiscoNexusVSMDeviceVO> listAllVSMs() {
|
||||
SearchCriteria<CiscoNexusVSMDeviceVO> sc = fullTableSearch.create();
|
||||
return search(sc, null);
|
||||
}
|
||||
|
||||
public List<CiscoNexusVSMDeviceVO> listByVlanId(int vlanId) {
|
||||
SearchCriteria<CiscoNexusVSMDeviceVO> sc = genericVlanIdSearch.create();
|
||||
|
|
|
|||
|
|
@ -14,40 +14,32 @@ package com.cloud.network.element;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.api.commands.DeleteCiscoNexusVSMCmd;
|
||||
import com.cloud.api.commands.EnableCiscoNexusVSMCmd;
|
||||
import com.cloud.api.commands.DisableCiscoNexusVSMCmd;
|
||||
import com.cloud.api.commands.ListCiscoVSMDetailsCmd;
|
||||
import com.cloud.api.commands.ListCiscoNexusVSMsCmd;
|
||||
import com.cloud.api.response.CiscoNexusVSMResponse;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.deploy.DeployDestination;
|
||||
import com.cloud.event.ActionEvent;
|
||||
import com.cloud.event.EventTypes;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.host.dao.HostDetailsDao;
|
||||
import com.cloud.network.CiscoNexusVSMDeviceVO;
|
||||
import com.cloud.network.CiscoNexusVSMDevice;
|
||||
import com.cloud.network.CiscoNexusVSMDeviceManagerImpl;
|
||||
import com.cloud.network.Network;
|
||||
import com.cloud.network.NetworkManager;
|
||||
import com.cloud.network.PhysicalNetworkServiceProvider;
|
||||
import com.cloud.network.Network.Capability;
|
||||
import com.cloud.network.Network.Provider;
|
||||
import com.cloud.network.Network.Service;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.network.dao.NetworkServiceMapDao;
|
||||
import com.cloud.network.dao.PhysicalNetworkDao;
|
||||
import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
|
||||
import com.cloud.utils.component.Inject;
|
||||
import com.cloud.vm.NicProfile;
|
||||
import com.cloud.vm.ReservationContext;
|
||||
|
|
@ -55,10 +47,11 @@ import com.cloud.vm.VirtualMachine;
|
|||
import com.cloud.vm.VirtualMachineProfile;
|
||||
import com.cloud.network.element.NetworkElement;
|
||||
import com.cloud.offering.NetworkOffering;
|
||||
import com.cloud.org.Cluster;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.exception.ResourceInUseException;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.server.ManagementService;
|
||||
|
||||
@Local(value = NetworkElement.class)
|
||||
public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl implements CiscoNexusVSMElementService, NetworkElement, Manager {
|
||||
|
|
@ -66,30 +59,7 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme
|
|||
private static final Logger s_logger = Logger.getLogger(CiscoNexusVSMElement.class);
|
||||
|
||||
@Inject
|
||||
NetworkManager _networkManager;
|
||||
@Inject
|
||||
ConfigurationManager _configMgr;
|
||||
@Inject
|
||||
NetworkServiceMapDao _ntwkSrvcDao;
|
||||
@Inject
|
||||
AgentManager _agentMgr;
|
||||
@Inject
|
||||
NetworkManager _networkMgr;
|
||||
@Inject
|
||||
HostDao _hostDao;
|
||||
@Inject
|
||||
DataCenterDao _dcDao;
|
||||
@Inject
|
||||
HostDetailsDao _hostDetailDao;
|
||||
@Inject
|
||||
PhysicalNetworkDao _physicalNetworkDao;
|
||||
@Inject
|
||||
NetworkDao _networkDao;
|
||||
@Inject
|
||||
HostDetailsDao _detailsDao;
|
||||
@Inject
|
||||
ConfigurationDao _configDao;
|
||||
|
||||
CiscoNexusVSMDeviceDao _vsmDao;
|
||||
|
||||
@Override
|
||||
public Map<Service, Map<Capability, String>> getCapabilities() {
|
||||
|
|
@ -161,7 +131,6 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@ActionEvent(eventType = EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DELETE, eventDescription = "deleting VSM", async = true)
|
||||
public boolean deleteCiscoNexusVSM(DeleteCiscoNexusVSMCmd cmd) {
|
||||
|
|
@ -178,7 +147,7 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme
|
|||
|
||||
@Override
|
||||
public boolean enableCiscoNexusVSM(EnableCiscoNexusVSMCmd cmd) {
|
||||
boolean result;
|
||||
boolean result;
|
||||
result = enableCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId());
|
||||
return result;
|
||||
}
|
||||
|
|
@ -191,11 +160,45 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme
|
|||
}
|
||||
|
||||
@Override
|
||||
public CiscoNexusVSMDeviceVO getCiscoNexusVSMByClusId(ListCiscoVSMDetailsCmd cmd) {
|
||||
CiscoNexusVSMDeviceVO result = getCiscoVSMbyClusId(cmd.getClusterId());
|
||||
if (result == null) {
|
||||
throw new CloudRuntimeException("No Cisco VSM associated with specified Cluster Id");
|
||||
public List<CiscoNexusVSMDeviceVO> getCiscoNexusVSMs(ListCiscoNexusVSMsCmd cmd) {
|
||||
// If clusterId is defined, then it takes precedence, and we will return
|
||||
// the VSM associated with this cluster.
|
||||
|
||||
Long clusterId = cmd.getClusterId();
|
||||
Long zoneId = cmd.getZoneId();
|
||||
List<CiscoNexusVSMDeviceVO> result = new ArrayList<CiscoNexusVSMDeviceVO>();
|
||||
if (clusterId != null && clusterId.longValue() != 0) {
|
||||
// Find the VSM associated with this clusterId and return a list.
|
||||
CiscoNexusVSMDeviceVO vsm = getCiscoVSMbyClusId(cmd.getClusterId());
|
||||
if (vsm == null) {
|
||||
throw new CloudRuntimeException("No Cisco VSM associated with specified Cluster Id");
|
||||
}
|
||||
// Else, add it to a list and return the list.
|
||||
result.add(vsm);
|
||||
return result;
|
||||
}
|
||||
// Else if there is only a zoneId defined, get a list of all vmware clusters
|
||||
// in the zone, and then for each cluster, pull the VSM and prepare a list.
|
||||
if (zoneId != null && zoneId.longValue() != 0) {
|
||||
ManagementService ref = cmd.getMgmtServiceRef();
|
||||
List<? extends Cluster> clusterList = ref.searchForClusters(zoneId, cmd.getStartIndex(), cmd.getPageSizeVal(), "VMware");
|
||||
|
||||
if (clusterList.size() == 0) {
|
||||
throw new CloudRuntimeException("No VMWare clusters found in the specified zone!");
|
||||
}
|
||||
// Else, iterate through each vmware cluster, pull its VSM if it has one, and add to the list.
|
||||
for (Cluster clus : clusterList) {
|
||||
CiscoNexusVSMDeviceVO vsm = getCiscoVSMbyClusId(clus.getId());
|
||||
if (vsm != null)
|
||||
result.add(vsm);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// If neither is defined, we will simply return the entire list of VSMs
|
||||
// configured in the management server.
|
||||
// TODO: Is this a safe thing to do? Only ROOT admin can invoke this call.
|
||||
result = _vsmDao.listAllVSMs();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,10 +18,12 @@
|
|||
|
||||
package com.cloud.network.element;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.api.commands.DeleteCiscoNexusVSMCmd;
|
||||
import com.cloud.api.commands.EnableCiscoNexusVSMCmd;
|
||||
import com.cloud.api.commands.DisableCiscoNexusVSMCmd;
|
||||
import com.cloud.api.commands.ListCiscoVSMDetailsCmd;
|
||||
import com.cloud.api.commands.ListCiscoNexusVSMsCmd;
|
||||
import com.cloud.api.response.CiscoNexusVSMResponse;
|
||||
import com.cloud.network.CiscoNexusVSMDeviceVO;
|
||||
import com.cloud.network.CiscoNexusVSMDevice;
|
||||
|
|
@ -47,11 +49,11 @@ public interface CiscoNexusVSMElementService extends PluggableService {
|
|||
public boolean disableCiscoNexusVSM(DisableCiscoNexusVSMCmd cmd);
|
||||
|
||||
/**
|
||||
* Returns a VSM associated with a cluster.
|
||||
* @param GetCiscoVSMByClusterIdCmd
|
||||
* @return CiscoNexusVSMDeviceVO
|
||||
* Returns a list of VSMs.
|
||||
* @param ListCiscoNexusVSMsCmd
|
||||
* @return List<CiscoNexusVSMDeviceVO>
|
||||
*/
|
||||
public CiscoNexusVSMDeviceVO getCiscoNexusVSMByClusId(ListCiscoVSMDetailsCmd cmd);
|
||||
public List<CiscoNexusVSMDeviceVO> getCiscoNexusVSMs(ListCiscoNexusVSMsCmd cmd);
|
||||
|
||||
/**
|
||||
* creates API response object for Cisco Nexus VSMs
|
||||
|
|
|
|||
|
|
@ -160,6 +160,7 @@ import com.cloud.network.NetworkVO;
|
|||
import com.cloud.network.dao.IPAddressDao;
|
||||
import com.cloud.network.dao.LoadBalancerDao;
|
||||
import com.cloud.network.dao.NetworkDao;
|
||||
import com.cloud.org.Cluster;
|
||||
import com.cloud.org.Grouping.AllocationState;
|
||||
import com.cloud.projects.Project;
|
||||
import com.cloud.projects.Project.ListProjectResourcesCriteria;
|
||||
|
|
@ -793,7 +794,20 @@ public class ManagementServerImpl implements ManagementServer {
|
|||
|
||||
return sol;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Cluster> searchForClusters(long zoneId, Long startIndex, Long pageSizeVal, String hypervisorType) {
|
||||
Filter searchFilter = new Filter(ClusterVO.class, "id", true, startIndex, pageSizeVal);
|
||||
SearchCriteria<ClusterVO> sc = _clusterDao.createSearchCriteria();
|
||||
|
||||
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
|
||||
|
||||
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
|
||||
sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hypervisorType);
|
||||
|
||||
return _clusterDao.search(sc, searchFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ClusterVO> searchForClusters(ListClustersCmd cmd) {
|
||||
Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());
|
||||
|
|
|
|||
Loading…
Reference in New Issue