Skip to content

Commit ed0ba1a

Browse files
author
Vijayendra Bhamidipati
committed
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
1 parent 5fc5b7a commit ed0ba1a

10 files changed

+135
-64
lines changed

api/src/com/cloud/api/BaseCmd.java

+4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ public void setResponseObject(Object responseObject) {
184184
_responseObject = responseObject;
185185
}
186186

187+
public ManagementService getMgmtServiceRef() {
188+
return _mgr;
189+
}
190+
187191
public static String getDateString(Date date) {
188192
if (date == null) {
189193
return "";

api/src/com/cloud/api/commands/ListClustersCmd.java

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.cloud.api.IdentityMapper;
2323
import com.cloud.api.Implementation;
2424
import com.cloud.api.Parameter;
25-
import com.cloud.api.BaseCmd.CommandType;
2625
import com.cloud.api.response.ClusterResponse;
2726
import com.cloud.api.response.ListResponse;
2827
import com.cloud.org.Cluster;

api/src/com/cloud/server/ManagementService.java

+7
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ public interface ManagementService {
127127
* @return
128128
*/
129129
List<? extends Cluster> searchForClusters(ListClustersCmd c);
130+
131+
/**
132+
* Searches for Clusters by the specified zone Id.
133+
* @param zoneId
134+
* @return
135+
*/
136+
List<? extends Cluster> searchForClusters(long zoneId, Long startIndex, Long pageSizeVal, String hypervisorType);
130137

131138
/**
132139
* Searches for Pods by the specified search criteria Can search by: pod name and/or zone name

client/tomcatconf/cisconexusvsm_commands.properties.in

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
#### Cisco Nexus 1000v Virtual Supervisor Module (VSM) commands
55
deleteCiscoNexusVSM = com.cloud.api.commands.DeleteCiscoNexusVSMCmd;1
66
enableCiscoNexusVSM = com.cloud.api.commands.EnableCiscoNexusVSMCmd;1
7-
disableCiscoNexusVSM = com.cloud.api.commands.DisableCiscoNexusVSMCmd;1
8-
listCiscoVSMDetails = com.cloud.api.commands.ListCiscoVSMDetailsCmd;1
7+
disableCiscoNexusVSM = com.cloud.api.commands.DisableCiscoNexusVSMCmd;1
8+
listCiscoNexusVSMs = com.cloud.api.commands.ListCiscoNexusVSMsCmd;1

server/src/com/cloud/api/commands/ListCiscoVSMDetailsCmd.java server/src/com/cloud/api/commands/ListCiscoNexusVSMsCmd.java

+40-14
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,50 @@
2020

2121
import org.apache.log4j.Logger;
2222
import com.cloud.api.ApiConstants;
23-
import com.cloud.api.BaseCmd;
23+
import com.cloud.api.BaseListCmd;
2424
import com.cloud.api.IdentityMapper;
2525
import com.cloud.api.Implementation;
2626
import com.cloud.api.Parameter;
2727
import com.cloud.api.PlugService;
2828
import com.cloud.api.ServerApiException;
2929
import com.cloud.api.response.CiscoNexusVSMResponse;
30+
import com.cloud.api.response.ListResponse;
3031
import com.cloud.exception.ConcurrentOperationException;
3132
import com.cloud.exception.InsufficientCapacityException;
3233
import com.cloud.exception.ResourceAllocationException;
3334
import com.cloud.exception.ResourceUnavailableException;
3435
import com.cloud.network.CiscoNexusVSMDevice;
3536
import com.cloud.network.element.CiscoNexusVSMElementService;
3637
import com.cloud.user.Account;
37-
import com.cloud.user.UserContext;
38+
39+
import java.util.ArrayList;
40+
import java.util.List;
3841

3942
@Implementation(responseObject=CiscoNexusVSMResponse.class, description="Retrieves a Cisco Nexus 1000v Virtual Switch Manager device associated with a Cluster")
40-
public class ListCiscoVSMDetailsCmd extends BaseCmd {
43+
public class ListCiscoNexusVSMsCmd extends BaseListCmd {
4144

42-
public static final Logger s_logger = Logger.getLogger(ListCiscoVSMDetailsCmd.class.getName());
43-
private static final String s_name = "listciscovsmdetailscmdresponse";
45+
/**
46+
* This command returns a list of all the VSMs configured in the management server.
47+
* If a clusterId is specified, it will return a list containing only that VSM
48+
* that is associated with that cluster. If a zone is specified, it will pull
49+
* up all the clusters of type vmware in that zone, and prepare a list of VSMs
50+
* associated with those clusters.
51+
*/
52+
public static final Logger s_logger = Logger.getLogger(ListCiscoNexusVSMsCmd.class.getName());
53+
private static final String s_name = "listcisconexusvsmscmdresponse";
4454
@PlugService CiscoNexusVSMElementService _ciscoNexusVSMService;
4555

4656
/////////////////////////////////////////////////////
4757
//////////////// API parameters /////////////////////
4858
/////////////////////////////////////////////////////
4959

5060
@IdentityMapper(entityTableName="cluster")
51-
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required = true, description="Id of the CloudStack cluster in which the Cisco Nexus 1000v VSM appliance.")
61+
@Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.LONG, required = false, description="Id of the CloudStack cluster in which the Cisco Nexus 1000v VSM appliance.")
5262
private long clusterId;
63+
64+
@IdentityMapper(entityTableName="data_center")
65+
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required = false, description="Id of the CloudStack cluster in which the Cisco Nexus 1000v VSM appliance.")
66+
private long zoneId;
5367

5468
/////////////////////////////////////////////////////
5569
/////////////////// Accessors ///////////////////////
@@ -58,6 +72,10 @@ public class ListCiscoVSMDetailsCmd extends BaseCmd {
5872
public long getClusterId() {
5973
return clusterId;
6074
}
75+
76+
public long getZoneId() {
77+
return zoneId;
78+
}
6179

6280
/////////////////////////////////////////////////////
6381
/////////////// API Implementation///////////////////
@@ -68,14 +86,22 @@ public long getClusterId() {
6886
// is invoked. That's the reason why we don't have any uuid-dbid translation code here.
6987
@Override
7088
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
71-
CiscoNexusVSMDevice vsmDevice = _ciscoNexusVSMService.getCiscoNexusVSMByClusId(this);
72-
if (vsmDevice != null) {
73-
CiscoNexusVSMResponse response = _ciscoNexusVSMService.createCiscoNexusVSMDetailedResponse(vsmDevice);
74-
response.setObjectName("cisconexusvsm");
75-
response.setResponseName(getCommandName());
76-
this.setResponseObject(response);
77-
} else {
78-
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to retrieve Cisco Nexus Virtual Switch Manager for the specified cluster due to an internal error.");
89+
List<? extends CiscoNexusVSMDevice> vsmDeviceList = _ciscoNexusVSMService.getCiscoNexusVSMs(this);
90+
91+
if (vsmDeviceList.size() > 0) {
92+
ListResponse<CiscoNexusVSMResponse> response = new ListResponse<CiscoNexusVSMResponse>();
93+
List<CiscoNexusVSMResponse> vsmResponses = new ArrayList<CiscoNexusVSMResponse>();
94+
for (CiscoNexusVSMDevice vsmDevice : vsmDeviceList) {
95+
CiscoNexusVSMResponse vsmresponse = _ciscoNexusVSMService.createCiscoNexusVSMDetailedResponse(vsmDevice);
96+
vsmresponse.setObjectName("cisconexusvsm");
97+
response.setResponseName(getCommandName());
98+
vsmResponses.add(vsmresponse);
99+
}
100+
response.setResponses(vsmResponses);
101+
response.setResponseName(getCommandName());
102+
this.setResponseObject(response);
103+
} else {
104+
throw new ServerApiException(BaseListCmd.INTERNAL_ERROR, "No VSM found.");
79105
}
80106
}
81107

server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDao.java

+7
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ public interface CiscoNexusVSMDeviceDao extends GenericDao<CiscoNexusVSMDeviceVO
5353
*/
5454
List<CiscoNexusVSMDeviceVO> listByMgmtVlan(int vlanId);
5555

56+
/**
57+
* Lists all configured VSMs on the management server.
58+
* @return
59+
*/
60+
List<CiscoNexusVSMDeviceVO> listAllVSMs();
61+
62+
5663
/**
5764
* Below is a big list of other functions that we may need, but will declare/define/implement once we implement
5865
* the functions above. Pasting those below to not lose track of them.

server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class CiscoNexusVSMDeviceDaoImpl extends GenericDaoBase<CiscoNexusVSMDevi
3232
final SearchBuilder<CiscoNexusVSMDeviceVO> nameSearch;
3333
final SearchBuilder<CiscoNexusVSMDeviceVO> ipaddrSearch;
3434
final SearchBuilder<CiscoNexusVSMDeviceVO> genericVlanIdSearch;
35+
final SearchBuilder<CiscoNexusVSMDeviceVO> fullTableSearch;
3536
// We will add more searchbuilder objects.
3637

3738

@@ -61,6 +62,9 @@ public CiscoNexusVSMDeviceDaoImpl() {
6162
ipaddrSearch.and("ipaddr", ipaddrSearch.entity().getipaddr(), Op.EQ);
6263
ipaddrSearch.done();
6364

65+
fullTableSearch = createSearchBuilder();
66+
fullTableSearch.done();
67+
6468
// We may add more and conditions by specifying more fields, like say, accountId.
6569
}
6670

@@ -87,6 +91,11 @@ public List<CiscoNexusVSMDeviceVO> listByMgmtVlan(int vlanId) {
8791
sc.setParameters("managementVlan", vlanId);
8892
return search(sc, null);
8993
}
94+
95+
public List<CiscoNexusVSMDeviceVO> listAllVSMs() {
96+
SearchCriteria<CiscoNexusVSMDeviceVO> sc = fullTableSearch.create();
97+
return search(sc, null);
98+
}
9099

91100
public List<CiscoNexusVSMDeviceVO> listByVlanId(int vlanId) {
92101
SearchCriteria<CiscoNexusVSMDeviceVO> sc = genericVlanIdSearch.create();

server/src/com/cloud/network/element/CiscoNexusVSMElement.java

+45-42
Original file line numberDiff line numberDiff line change
@@ -14,82 +14,52 @@
1414

1515
import java.util.List;
1616
import java.util.Map;
17+
import java.util.ArrayList;
1718

1819
import javax.ejb.Local;
1920

2021
import org.apache.log4j.Logger;
2122

22-
import com.cloud.agent.AgentManager;
2323
import com.cloud.api.commands.DeleteCiscoNexusVSMCmd;
2424
import com.cloud.api.commands.EnableCiscoNexusVSMCmd;
2525
import com.cloud.api.commands.DisableCiscoNexusVSMCmd;
26-
import com.cloud.api.commands.ListCiscoVSMDetailsCmd;
26+
import com.cloud.api.commands.ListCiscoNexusVSMsCmd;
2727
import com.cloud.api.response.CiscoNexusVSMResponse;
28-
import com.cloud.configuration.ConfigurationManager;
29-
import com.cloud.configuration.dao.ConfigurationDao;
30-
import com.cloud.dc.dao.DataCenterDao;
3128
import com.cloud.deploy.DeployDestination;
3229
import com.cloud.event.ActionEvent;
3330
import com.cloud.event.EventTypes;
3431
import com.cloud.exception.ConcurrentOperationException;
3532
import com.cloud.exception.InsufficientCapacityException;
3633
import com.cloud.exception.ResourceUnavailableException;
37-
import com.cloud.host.dao.HostDao;
38-
import com.cloud.host.dao.HostDetailsDao;
3934
import com.cloud.network.CiscoNexusVSMDeviceVO;
4035
import com.cloud.network.CiscoNexusVSMDevice;
4136
import com.cloud.network.CiscoNexusVSMDeviceManagerImpl;
4237
import com.cloud.network.Network;
43-
import com.cloud.network.NetworkManager;
4438
import com.cloud.network.PhysicalNetworkServiceProvider;
4539
import com.cloud.network.Network.Capability;
4640
import com.cloud.network.Network.Provider;
4741
import com.cloud.network.Network.Service;
48-
import com.cloud.network.dao.NetworkDao;
49-
import com.cloud.network.dao.NetworkServiceMapDao;
50-
import com.cloud.network.dao.PhysicalNetworkDao;
42+
import com.cloud.network.dao.CiscoNexusVSMDeviceDao;
5143
import com.cloud.utils.component.Inject;
5244
import com.cloud.vm.NicProfile;
5345
import com.cloud.vm.ReservationContext;
5446
import com.cloud.vm.VirtualMachine;
5547
import com.cloud.vm.VirtualMachineProfile;
5648
import com.cloud.network.element.NetworkElement;
5749
import com.cloud.offering.NetworkOffering;
50+
import com.cloud.org.Cluster;
5851
import com.cloud.utils.component.Manager;
59-
import com.cloud.utils.db.DB;
6052
import com.cloud.exception.ResourceInUseException;
6153
import com.cloud.utils.exception.CloudRuntimeException;
54+
import com.cloud.server.ManagementService;
6255

6356
@Local(value = NetworkElement.class)
6457
public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl implements CiscoNexusVSMElementService, NetworkElement, Manager {
6558

6659
private static final Logger s_logger = Logger.getLogger(CiscoNexusVSMElement.class);
6760

6861
@Inject
69-
NetworkManager _networkManager;
70-
@Inject
71-
ConfigurationManager _configMgr;
72-
@Inject
73-
NetworkServiceMapDao _ntwkSrvcDao;
74-
@Inject
75-
AgentManager _agentMgr;
76-
@Inject
77-
NetworkManager _networkMgr;
78-
@Inject
79-
HostDao _hostDao;
80-
@Inject
81-
DataCenterDao _dcDao;
82-
@Inject
83-
HostDetailsDao _hostDetailDao;
84-
@Inject
85-
PhysicalNetworkDao _physicalNetworkDao;
86-
@Inject
87-
NetworkDao _networkDao;
88-
@Inject
89-
HostDetailsDao _detailsDao;
90-
@Inject
91-
ConfigurationDao _configDao;
92-
62+
CiscoNexusVSMDeviceDao _vsmDao;
9363

9464
@Override
9565
public Map<Service, Map<Capability, String>> getCapabilities() {
@@ -161,7 +131,6 @@ public boolean verifyServicesCombination(List<String> services) {
161131
return true;
162132
}
163133

164-
165134
@Override
166135
@ActionEvent(eventType = EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DELETE, eventDescription = "deleting VSM", async = true)
167136
public boolean deleteCiscoNexusVSM(DeleteCiscoNexusVSMCmd cmd) {
@@ -178,7 +147,7 @@ public boolean deleteCiscoNexusVSM(DeleteCiscoNexusVSMCmd cmd) {
178147

179148
@Override
180149
public boolean enableCiscoNexusVSM(EnableCiscoNexusVSMCmd cmd) {
181-
boolean result;
150+
boolean result;
182151
result = enableCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId());
183152
return result;
184153
}
@@ -191,11 +160,45 @@ public boolean disableCiscoNexusVSM(DisableCiscoNexusVSMCmd cmd) {
191160
}
192161

193162
@Override
194-
public CiscoNexusVSMDeviceVO getCiscoNexusVSMByClusId(ListCiscoVSMDetailsCmd cmd) {
195-
CiscoNexusVSMDeviceVO result = getCiscoVSMbyClusId(cmd.getClusterId());
196-
if (result == null) {
197-
throw new CloudRuntimeException("No Cisco VSM associated with specified Cluster Id");
163+
public List<CiscoNexusVSMDeviceVO> getCiscoNexusVSMs(ListCiscoNexusVSMsCmd cmd) {
164+
// If clusterId is defined, then it takes precedence, and we will return
165+
// the VSM associated with this cluster.
166+
167+
Long clusterId = cmd.getClusterId();
168+
Long zoneId = cmd.getZoneId();
169+
List<CiscoNexusVSMDeviceVO> result = new ArrayList<CiscoNexusVSMDeviceVO>();
170+
if (clusterId != null && clusterId.longValue() != 0) {
171+
// Find the VSM associated with this clusterId and return a list.
172+
CiscoNexusVSMDeviceVO vsm = getCiscoVSMbyClusId(cmd.getClusterId());
173+
if (vsm == null) {
174+
throw new CloudRuntimeException("No Cisco VSM associated with specified Cluster Id");
175+
}
176+
// Else, add it to a list and return the list.
177+
result.add(vsm);
178+
return result;
179+
}
180+
// Else if there is only a zoneId defined, get a list of all vmware clusters
181+
// in the zone, and then for each cluster, pull the VSM and prepare a list.
182+
if (zoneId != null && zoneId.longValue() != 0) {
183+
ManagementService ref = cmd.getMgmtServiceRef();
184+
List<? extends Cluster> clusterList = ref.searchForClusters(zoneId, cmd.getStartIndex(), cmd.getPageSizeVal(), "VMware");
185+
186+
if (clusterList.size() == 0) {
187+
throw new CloudRuntimeException("No VMWare clusters found in the specified zone!");
188+
}
189+
// Else, iterate through each vmware cluster, pull its VSM if it has one, and add to the list.
190+
for (Cluster clus : clusterList) {
191+
CiscoNexusVSMDeviceVO vsm = getCiscoVSMbyClusId(clus.getId());
192+
if (vsm != null)
193+
result.add(vsm);
194+
}
195+
return result;
198196
}
197+
198+
// If neither is defined, we will simply return the entire list of VSMs
199+
// configured in the management server.
200+
// TODO: Is this a safe thing to do? Only ROOT admin can invoke this call.
201+
result = _vsmDao.listAllVSMs();
199202
return result;
200203
}
201204

server/src/com/cloud/network/element/CiscoNexusVSMElementService.java

+7-5
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818

1919
package com.cloud.network.element;
2020

21+
import java.util.List;
22+
2123
import com.cloud.api.commands.DeleteCiscoNexusVSMCmd;
2224
import com.cloud.api.commands.EnableCiscoNexusVSMCmd;
2325
import com.cloud.api.commands.DisableCiscoNexusVSMCmd;
24-
import com.cloud.api.commands.ListCiscoVSMDetailsCmd;
26+
import com.cloud.api.commands.ListCiscoNexusVSMsCmd;
2527
import com.cloud.api.response.CiscoNexusVSMResponse;
2628
import com.cloud.network.CiscoNexusVSMDeviceVO;
2729
import com.cloud.network.CiscoNexusVSMDevice;
@@ -47,11 +49,11 @@ public interface CiscoNexusVSMElementService extends PluggableService {
4749
public boolean disableCiscoNexusVSM(DisableCiscoNexusVSMCmd cmd);
4850

4951
/**
50-
* Returns a VSM associated with a cluster.
51-
* @param GetCiscoVSMByClusterIdCmd
52-
* @return CiscoNexusVSMDeviceVO
52+
* Returns a list of VSMs.
53+
* @param ListCiscoNexusVSMsCmd
54+
* @return List<CiscoNexusVSMDeviceVO>
5355
*/
54-
public CiscoNexusVSMDeviceVO getCiscoNexusVSMByClusId(ListCiscoVSMDetailsCmd cmd);
56+
public List<CiscoNexusVSMDeviceVO> getCiscoNexusVSMs(ListCiscoNexusVSMsCmd cmd);
5557

5658
/**
5759
* creates API response object for Cisco Nexus VSMs

server/src/com/cloud/server/ManagementServerImpl.java

+14
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
import com.cloud.network.dao.IPAddressDao;
161161
import com.cloud.network.dao.LoadBalancerDao;
162162
import com.cloud.network.dao.NetworkDao;
163+
import com.cloud.org.Cluster;
163164
import com.cloud.org.Grouping.AllocationState;
164165
import com.cloud.projects.Project;
165166
import com.cloud.projects.Project.ListProjectResourcesCriteria;
@@ -793,7 +794,20 @@ private List<ServiceOfferingVO> searchServiceOfferingsInternal(Account caller, O
793794

794795
return sol;
795796
}
797+
798+
@Override
799+
public List<? extends Cluster> searchForClusters(long zoneId, Long startIndex, Long pageSizeVal, String hypervisorType) {
800+
Filter searchFilter = new Filter(ClusterVO.class, "id", true, startIndex, pageSizeVal);
801+
SearchCriteria<ClusterVO> sc = _clusterDao.createSearchCriteria();
802+
803+
zoneId = _accountMgr.checkAccessAndSpecifyAuthority(UserContext.current().getCaller(), zoneId);
796804

805+
sc.addAnd("dataCenterId", SearchCriteria.Op.EQ, zoneId);
806+
sc.addAnd("hypervisorType", SearchCriteria.Op.EQ, hypervisorType);
807+
808+
return _clusterDao.search(sc, searchFilter);
809+
}
810+
797811
@Override
798812
public List<ClusterVO> searchForClusters(ListClustersCmd cmd) {
799813
Filter searchFilter = new Filter(ClusterVO.class, "id", true, cmd.getStartIndex(), cmd.getPageSizeVal());

0 commit comments

Comments
 (0)