Bug CS-9919: Support for Nexus Swiches (Cisco Vswitches)

Description:

        1. Put in invocation to the deleteCiscoNexusVSM()
	   function in the deleteCiscoNexusVSM command
	   chain.

        2. Put in additional check for physical servers
	   present in a cluster that still is tied to a
	   VSM. The previous check would query for all
	   hosts in a cluster, causing the check to see
	   if a cluster has any physical servers in it
	   to always fail and thus block the VSM from
	   getting deleted. By putting in a check to see
	   if a host if of type "Routing", we refine this
	   search to only hypervisors.

        3. Other miscallaneous code + cleanup.
This commit is contained in:
Vijayendra Bhamidipati 2012-05-07 18:21:14 -07:00
parent 037ac6592e
commit 38c140b181
5 changed files with 44 additions and 52 deletions

View File

@ -129,16 +129,6 @@ public class AddCiscoNexusVSMCmd extends BaseCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
//@Override
//public String getEventDescription() {
// return "Adding a Cisco Nexus VSM device";
//}
//@Override
//public String getEventType() {
// return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_ADD;
//}
@Override
public String getCommandName() {

View File

@ -51,15 +51,15 @@ public class DeleteCiscoNexusVSMCmd extends BaseCmd {
/////////////////////////////////////////////////////
@IdentityMapper(entityTableName="virtual_supervisor_module")
@Parameter(name=ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_ID, type=CommandType.LONG, required=true, description="Cisco Nexus 1000v VSM device ID")
private Long vsmDeviceId;
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Id of the Cisco Nexus 1000v VSM device to be deleted")
private Long id;
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
public Long getCiscoNexusVSMDeviceId() {
return vsmDeviceId;
return id;
}
/////////////////////////////////////////////////////
@ -84,16 +84,6 @@ public class DeleteCiscoNexusVSMCmd extends BaseCmd {
}
}
@Override
public String getEventDescription() {
return "Deleting a Cisco Nexus 1000v VSM device";
}
@Override
public String getEventType() {
return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DELETE;
}
@Override
public String getCommandName() {
return s_name;

View File

@ -188,12 +188,12 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
// Next, check if this VSM is reachable. Use the XML-RPC VSM API Java bindings to talk to
// the VSM.
//NetconfHelper (String ip, String username, String password)
CiscoNexusVSM vsmObj = new CiscoNexusVSM(ipaddress, username, password);
if (!vsmObj.connectToVSM()) {
throw new CloudRuntimeException("Couldn't login to the specified VSM");
}
// Now, go ahead and associate the cluster with this VSM.
// First, check if VSM already exists in the table "virtual_supervisor_module".
// If it's not there already, create it.
@ -213,8 +213,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
//CiscoNexusVSMDeviceVO VSMObj = _ciscoNexusVSMDeviceDao.getVSMbyDomainId(1);
if (VSMObj == null) {
s_logger.info("no record found.. will create one");
if (VSMObj == null) {
// Create the VSM record. For now, we aren't using the vsmName field.
VSMObj = new CiscoNexusVSMDeviceVO(ipaddress, username, password, vCenterIpaddr, vCenterDcName);
Transaction txn = Transaction.currentTxn();
@ -253,8 +252,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
// into each host's resource. Also, we first configure each resource's
// entries in the database to contain this VSM information before the injection.
for (HostVO host : hosts) {
s_logger.info("inside for loop!");
for (HostVO host : hosts) {
// Create a host details VO object and write it out for this hostid.
long vsmId = _ciscoNexusVSMDeviceDao.getVSMbyIpaddress(ipaddress).getId();
Long hostid = new Long(vsmId);
@ -281,7 +279,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
}
@DB
public boolean deleteCiscoNexusVSM(long vsmId) throws ResourceInUseException {
public boolean deleteCiscoNexusVSM(long vsmId) throws ResourceInUseException {
CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId);
if (cisconexusvsm == null) {
// This entry is already not present. Return success.
@ -290,14 +288,21 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
// First, check whether this VSM is part of any non-empty cluster.
// Search ClusterVSMMap's table for a list of clusters using this vsmId.
List<ClusterVSMMapVO> clusterList = _clusterVSMDao.listByVSMId(vsmId);
for (ClusterVSMMapVO record : clusterList) {
// If this cluster id has any hosts in it, fail this operation.
Long clusterId = record.getClusterId();
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
if (hosts != null && hosts.size() > 0) {
throw new ResourceInUseException("Non-empty cluster with id" + clusterId + "still uses VSM. Please empty the cluster first");
if (clusterList != null) {
for (ClusterVSMMapVO record : clusterList) {
// If this cluster id has any hosts in it, fail this operation.
Long clusterId = record.getClusterId();
List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(clusterId);
if (hosts != null && hosts.size() > 0) {
for (Host host: hosts) {
if (host.getType() == Host.Type.Routing) {
throw new ResourceInUseException("Non-empty cluster with id" + clusterId + "still has a host that uses this VSM. Please empty the cluster first");
}
}
}
}
}
@ -305,19 +310,17 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase {
Transaction txn = Transaction.currentTxn();
try {
txn.start();
for (ClusterVSMMapVO record : clusterList) {
// Remove the VSM entry in CiscoNexusVSMDeviceVO's table.
_ciscoNexusVSMDeviceDao.remove(vsmId);
// Remove the current record as well from ClusterVSMMapVO's table.
_clusterVSMDao.removeByVsmId(vsmId);
// There are no hosts at this stage in the cluster, so we don't need
// to notify any resources or remove host details.
}
txn.commit();
} catch (CloudRuntimeException e) {
throw e;
}
// Remove the VSM entry in CiscoNexusVSMDeviceVO's table.
_ciscoNexusVSMDeviceDao.remove(vsmId);
// Remove the current record as well from ClusterVSMMapVO's table.
_clusterVSMDao.removeByVsmId(vsmId);
// There are no hosts at this stage in the cluster, so we don't need
// to notify any resources or remove host details.
txn.commit();
} catch (Exception e) {
s_logger.info("Caught exception when trying to delete VSM record.." + e.getMessage());
throw new CloudRuntimeException("Failed to delete VSM");
}
return true;
}

View File

@ -63,7 +63,7 @@ public class CiscoNexusVSMDeviceDaoImpl extends GenericDaoBase<CiscoNexusVSMDevi
// We may add more and conditions by specifying more fields, like say, accountId.
}
public CiscoNexusVSMDeviceVO getVSMbyDomainId(long domId) {
SearchCriteria<CiscoNexusVSMDeviceVO> sc = domainIdSearch.create();
sc.setParameters("vsmSwitchDomainId", domId);

View File

@ -45,7 +45,6 @@ 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.resource.ServerResource;
import com.cloud.utils.component.Inject;
import com.cloud.vm.NicProfile;
import com.cloud.vm.ReservationContext;
@ -55,6 +54,8 @@ import com.cloud.network.PortProfile;
import com.cloud.network.element.NetworkElement;
import com.cloud.offering.NetworkOffering;
import com.cloud.utils.component.Manager;
import com.cloud.exception.ResourceInUseException;
import com.cloud.utils.exception.CloudRuntimeException;
@Local(value = NetworkElement.class)
public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl implements CiscoNexusVSMElementService, NetworkElement, Manager {
@ -186,7 +187,15 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme
@Override
public boolean deleteCiscoNexusVSM(DeleteCiscoNexusVSMCmd cmd) {
return true;
boolean result;
try {
result = deleteCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId());
} catch (ResourceInUseException e) {
s_logger.info("VSM could not be deleted");
// TODO: Throw a better exception here.
throw new CloudRuntimeException("Failed to delete specified VSM");
}
return result;
}