From b28568a2215a9b35792f1633554cc0240d0d7717 Mon Sep 17 00:00:00 2001 From: Vijayendra Bhamidipati Date: Fri, 18 May 2012 17:32:17 -0700 Subject: [PATCH] CS-9919 Support for Nexus Swiches (Cisco Vswitches) Description: Modified the following commands to be Async: a. EnableCiscoNexusVSM b. DisableCiscoNexusVSM c. DeleteCiscoNexusVSM Cleaned up miscellaneous code. --- api/src/com/cloud/event/EventTypes.java | 5 ++++- .../api/commands/DeleteCiscoNexusVSMCmd.java | 19 ++++++++++++----- .../api/commands/DisableCiscoNexusVSMCmd.java | 21 ++++++++++++++----- .../api/commands/EnableCiscoNexusVSMCmd.java | 19 ++++++++++++----- .../api/commands/GetCiscoVSMDetailsCmd.java | 3 +-- .../CiscoNexusVSMDeviceManagerImpl.java | 6 +++--- .../cloud/network/PortProfileManagerImpl.java | 4 +--- 7 files changed, 53 insertions(+), 24 deletions(-) diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index ea3cb3e0d0e..eedf5462400 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -247,7 +247,10 @@ public class EventTypes { // external switch management device events (E.g.: Cisco Nexus 1000v Virtual Supervisor Module. public static final String EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_ADD = "SWITCH.MGMT.ADD"; public static final String EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DELETE = "SWITCH.MGMT.DELETE"; - public static final String EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_CONFIGURE = "SWITCH.MGMT.CONFIGURE"; + public static final String EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_CONFIGURE = "SWITCH.MGMT.CONFIGURE"; + public static final String EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_ENABLE = "SWITCH.MGMT.ENABLE"; + public static final String EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DISABLE = "SWITCH.MGMT.DISABLE"; + public static final String EVENT_EXTERNAL_FIREWALL_DEVICE_ADD = "PHYSICAL.FIREWALL.ADD"; public static final String EVENT_EXTERNAL_FIREWALL_DEVICE_DELETE = "PHYSICAL.FIREWALL.DELETE"; diff --git a/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java index aca0dc89425..886ef1b22d6 100644 --- a/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java +++ b/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java @@ -22,7 +22,6 @@ import org.apache.log4j.Logger; import com.cloud.api.ApiConstants; import com.cloud.api.BaseAsyncCmd; -import com.cloud.api.BaseCmd; import com.cloud.api.IdentityMapper; import com.cloud.api.Implementation; import com.cloud.api.Parameter; @@ -40,7 +39,7 @@ import com.cloud.user.UserContext; import com.cloud.utils.exception.CloudRuntimeException; @Implementation(responseObject=SuccessResponse.class, description=" delete a Cisco Nexus VSM device") -public class DeleteCiscoNexusVSMCmd extends BaseCmd { +public class DeleteCiscoNexusVSMCmd extends BaseAsyncCmd { public static final Logger s_logger = Logger.getLogger(DeleteCiscoNexusVSMCmd.class.getName()); private static final String s_name = "deletecisconexusvsmresponse"; @@ -75,12 +74,12 @@ public class DeleteCiscoNexusVSMCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete Cisco Nexus VSM device"); + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to delete Cisco Nexus VSM device"); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(BaseAsyncCmd.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); } } @@ -93,4 +92,14 @@ public class DeleteCiscoNexusVSMCmd extends BaseCmd { public long getEntityOwnerId() { return UserContext.current().getCaller().getId(); } + + @Override + public String getEventType() { + return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DELETE; + } + + @Override + public String getEventDescription() { + return "Deleting a Cisco Nexus VSM device"; + } } diff --git a/server/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java index 79de9556f05..bef7ef4391f 100644 --- a/server/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java +++ b/server/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java @@ -21,7 +21,7 @@ package com.cloud.api.commands; import org.apache.log4j.Logger; import com.cloud.api.ApiConstants; -import com.cloud.api.BaseCmd; +import com.cloud.api.BaseAsyncCmd; import com.cloud.api.IdentityMapper; import com.cloud.api.Implementation; import com.cloud.api.Parameter; @@ -36,9 +36,10 @@ import com.cloud.exception.ResourceUnavailableException; import com.cloud.network.element.CiscoNexusVSMElementService; import com.cloud.user.UserContext; import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.event.EventTypes; @Implementation(responseObject=SuccessResponse.class, description="disable a Cisco Nexus VSM device") -public class DisableCiscoNexusVSMCmd extends BaseCmd { +public class DisableCiscoNexusVSMCmd extends BaseAsyncCmd { public static final Logger s_logger = Logger.getLogger(DisableCiscoNexusVSMCmd.class.getName()); private static final String s_name = "disablecisconexusvsmresponse"; @@ -73,12 +74,12 @@ public class DisableCiscoNexusVSMCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disable Cisco Nexus VSM device"); + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to disable Cisco Nexus VSM device"); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(BaseAsyncCmd.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); } } @@ -91,4 +92,14 @@ public class DisableCiscoNexusVSMCmd extends BaseCmd { public long getEntityOwnerId() { return UserContext.current().getCaller().getId(); } + + @Override + public String getEventDescription() { + return "Disabling a Cisco Nexus VSM device"; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_DISABLE; + } } diff --git a/server/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java index 15e06d763a5..0f216d67af9 100644 --- a/server/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java +++ b/server/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java @@ -22,7 +22,6 @@ import org.apache.log4j.Logger; import com.cloud.api.ApiConstants; import com.cloud.api.BaseAsyncCmd; -import com.cloud.api.BaseCmd; import com.cloud.api.IdentityMapper; import com.cloud.api.Implementation; import com.cloud.api.Parameter; @@ -40,7 +39,7 @@ import com.cloud.user.UserContext; import com.cloud.utils.exception.CloudRuntimeException; @Implementation(responseObject=SuccessResponse.class, description="Enable a Cisco Nexus VSM device") -public class EnableCiscoNexusVSMCmd extends BaseCmd { +public class EnableCiscoNexusVSMCmd extends BaseAsyncCmd { public static final Logger s_logger = Logger.getLogger(EnableCiscoNexusVSMCmd.class.getName()); private static final String s_name = "enablecisconexusvsmresponse"; @@ -75,12 +74,12 @@ public class EnableCiscoNexusVSMCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to enable Cisco Nexus VSM device"); + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to enable Cisco Nexus VSM device"); } } catch (InvalidParameterValueException invalidParamExcp) { - throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + throw new ServerApiException(BaseAsyncCmd.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); } } @@ -93,4 +92,14 @@ public class EnableCiscoNexusVSMCmd extends BaseCmd { public long getEntityOwnerId() { return UserContext.current().getCaller().getId(); } + + @Override + public String getEventDescription() { + return "Enabling a Cisco Nexus VSM device"; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_ENABLE; + } } diff --git a/server/src/com/cloud/api/commands/GetCiscoVSMDetailsCmd.java b/server/src/com/cloud/api/commands/GetCiscoVSMDetailsCmd.java index d36b9ff5306..37a8892f994 100755 --- a/server/src/com/cloud/api/commands/GetCiscoVSMDetailsCmd.java +++ b/server/src/com/cloud/api/commands/GetCiscoVSMDetailsCmd.java @@ -20,7 +20,6 @@ package com.cloud.api.commands; import org.apache.log4j.Logger; import com.cloud.api.ApiConstants; -import com.cloud.api.BaseAsyncCmd; import com.cloud.api.BaseCmd; import com.cloud.api.IdentityMapper; import com.cloud.api.Implementation; @@ -75,7 +74,7 @@ public class GetCiscoVSMDetailsCmd extends BaseCmd { response.setResponseName(getCommandName()); this.setResponseObject(response); } else { - throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to retrieve Cisco Nexus Virtual Switch Manager for the specified cluster due to an internal error."); + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to retrieve Cisco Nexus Virtual Switch Manager for the specified cluster due to an internal error."); } } catch (InvalidParameterValueException invalidParamExcp) { throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); diff --git a/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java b/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java index 64d8dc32f84..2d7ef7663bf 100644 --- a/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java +++ b/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java @@ -109,6 +109,8 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase { throw new CloudRuntimeException(msg); } + // Disconnect from the VSM. A VSM has a default of 8 maximum parallel connections that it allows. + netconfClient.disconnect(); // Now, go ahead and associate the cluster with this VSM. // First, check if VSM already exists in the table "virtual_supervisor_module". @@ -126,9 +128,7 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase { } catch (Exception e) { throw new CloudRuntimeException(e.getMessage()); } - - //CiscoNexusVSMDeviceVO VSMObj = _ciscoNexusVSMDeviceDao.getVSMbyDomainId(1); - + if (VSMObj == null) { // Create the VSM record. For now, we aren't using the vsmName field. VSMObj = new CiscoNexusVSMDeviceVO(ipaddress, username, password, vCenterIpaddr, vCenterDcName); diff --git a/server/src/com/cloud/network/PortProfileManagerImpl.java b/server/src/com/cloud/network/PortProfileManagerImpl.java index 4771865e654..e7c6b36f8e8 100644 --- a/server/src/com/cloud/network/PortProfileManagerImpl.java +++ b/server/src/com/cloud/network/PortProfileManagerImpl.java @@ -35,15 +35,13 @@ public class PortProfileManagerImpl { @DB public PortProfileVO addPortProfile(String portProfName, long vsmId, int vlanId, PortType pType, BindingType bType) { - // In this function, we create a port profile record in the port_profile table. - s_logger.info("Inside addPortProfile.. name --> " + portProfName + " vsmId --> " + vsmId + " vlan id --> " + vlanId + " pType --> " + pType + "btype --> " + bType); + // In this function, we create a port profile record in the port_profile table. // First, check if a port profile with the given name already exists. If it does, throw an exception. if (_portProfileDao.findByName(portProfName) != null) { s_logger.info("Port Profile with specified name: " + portProfName + " already exists"); throw new InvalidParameterValueException("Port Profile with specified name: " + portProfName + " already exists"); } - s_logger.info("Ok didn't find a portprofile by name " + portProfName); // Check if the VSM id is a valid one. // TODO: Should we also check whether a port profile for the specified vlanId already exists, and if so,