diff --git a/client/tomcatconf/cisconexusvsm_commands.properties.in b/client/tomcatconf/cisconexusvsm_commands.properties.in index 25272b7df32..05939bbebc2 100644 --- a/client/tomcatconf/cisconexusvsm_commands.properties.in +++ b/client/tomcatconf/cisconexusvsm_commands.properties.in @@ -4,3 +4,5 @@ #### Cisco Nexus 1000v Virtual Supervisor Module (VSM) commands addCiscoNexusVSM = com.cloud.api.commands.AddCiscoNexusVSMCmd;7 deleteCiscoNexusVSM = com.cloud.api.commands.DeleteCiscoNexusVSMCmd;7 +enableCiscoNexusVSM = com.cloud.api.commands.EnableCiscoNexusVSMCmd;7 +disableCiscoNexusVSM = com.cloud.api.commands.DisableCiscoNexusVSMCmd;7 \ No newline at end of file diff --git a/server/src/com/cloud/api/commands/AddCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/AddCiscoNexusVSMCmd.java index 412891bf1ed..a7a048d633f 100644 --- a/server/src/com/cloud/api/commands/AddCiscoNexusVSMCmd.java +++ b/server/src/com/cloud/api/commands/AddCiscoNexusVSMCmd.java @@ -28,7 +28,6 @@ import com.cloud.api.Parameter; import com.cloud.api.PlugService; import com.cloud.api.ServerApiException; import com.cloud.api.response.CiscoNexusVSMResponse; -import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; import com.cloud.exception.InvalidParameterValueException; diff --git a/server/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java new file mode 100644 index 00000000000..79de9556f05 --- /dev/null +++ b/server/src/com/cloud/api/commands/DisableCiscoNexusVSMCmd.java @@ -0,0 +1,94 @@ +/** + * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +package com.cloud.api.commands; + +import org.apache.log4j.Logger; + +import com.cloud.api.ApiConstants; +import com.cloud.api.BaseCmd; +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.SuccessResponse; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.element.CiscoNexusVSMElementService; +import com.cloud.user.UserContext; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=SuccessResponse.class, description="disable a Cisco Nexus VSM device") +public class DisableCiscoNexusVSMCmd extends BaseCmd { + + public static final Logger s_logger = Logger.getLogger(DisableCiscoNexusVSMCmd.class.getName()); + private static final String s_name = "disablecisconexusvsmresponse"; + @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="virtual_supervisor_module") + @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 id; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + boolean result = _ciscoNexusVSMService.disableCiscoNexusVSM(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to disable Cisco Nexus VSM device"); + } + } catch (InvalidParameterValueException invalidParamExcp) { + throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + } catch (CloudRuntimeException runtimeExcp) { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + } + } + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return UserContext.current().getCaller().getId(); + } +} diff --git a/server/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java new file mode 100644 index 00000000000..15e06d763a5 --- /dev/null +++ b/server/src/com/cloud/api/commands/EnableCiscoNexusVSMCmd.java @@ -0,0 +1,96 @@ +/** + * Copyright (C) 2011 Citrix Systems, Inc. All rights reserved. + * + * This software is licensed under the GNU General Public License v3 or later. + * + * It is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +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; +import com.cloud.api.Parameter; +import com.cloud.api.PlugService; +import com.cloud.api.ServerApiException; +import com.cloud.api.response.SuccessResponse; +import com.cloud.event.EventTypes; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.element.CiscoNexusVSMElementService; +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 static final Logger s_logger = Logger.getLogger(EnableCiscoNexusVSMCmd.class.getName()); + private static final String s_name = "enablecisconexusvsmresponse"; + @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="virtual_supervisor_module") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="Id of the Cisco Nexus 1000v VSM device to be enabled") + private Long id; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getCiscoNexusVSMDeviceId() { + return id; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + boolean result = _ciscoNexusVSMService.enableCiscoNexusVSM(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to enable Cisco Nexus VSM device"); + } + } catch (InvalidParameterValueException invalidParamExcp) { + throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage()); + } catch (CloudRuntimeException runtimeExcp) { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage()); + } + } + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + return UserContext.current().getCaller().getId(); + } +} diff --git a/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java b/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java index 52a368994a7..53331c788fc 100644 --- a/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java +++ b/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java @@ -324,6 +324,56 @@ public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase { return true; } + @DB + public boolean enableCiscoNexusVSM(long vsmId) { + CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId); + if (cisconexusvsm == null) { + // This entry is already not present. Return success. + throw new InvalidParameterValueException("Invalid vsm Id specified"); + } + // Else, check if this db record shows that this VSM is enabled or not. + if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled) { + // it's currently disabled. So change it to enabled and write it out to the db. + cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled); + Transaction txn = Transaction.currentTxn(); + try { + txn.start(); + _ciscoNexusVSMDeviceDao.persist(cisconexusvsm); + txn.commit(); + } catch (Exception e) { + txn.rollback(); + throw new CloudRuntimeException(e.getMessage()); + } + } + + return true; + } + + @DB + public boolean disableCiscoNexusVSM(long vsmId) { + CiscoNexusVSMDeviceVO cisconexusvsm = _ciscoNexusVSMDeviceDao.findById(vsmId); + if (cisconexusvsm == null) { + // This entry is already not present. Return success. + throw new InvalidParameterValueException("Invalid vsm Id specified"); + } + // Else, check if this db record shows that this VSM is enabled or not. + if (cisconexusvsm.getvsmDeviceState() == CiscoNexusVSMDeviceVO.VSMDeviceState.Enabled) { + // it's currently disabled. So change it to enabled and write it out to the db. + cisconexusvsm.setVsmDeviceState(CiscoNexusVSMDeviceVO.VSMDeviceState.Disabled); + Transaction txn = Transaction.currentTxn(); + try { + txn.start(); + _ciscoNexusVSMDeviceDao.persist(cisconexusvsm); + txn.commit(); + } catch (Exception e) { + txn.rollback(); + throw new CloudRuntimeException(e.getMessage()); + } + } + + return true; + } + public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) { // TODO Auto-generated method stub return null; diff --git a/server/src/com/cloud/network/CiscoNexusVSMDeviceVO.java b/server/src/com/cloud/network/CiscoNexusVSMDeviceVO.java index a69f2eff355..047f08c85e6 100644 --- a/server/src/com/cloud/network/CiscoNexusVSMDeviceVO.java +++ b/server/src/com/cloud/network/CiscoNexusVSMDeviceVO.java @@ -258,15 +258,18 @@ public class CiscoNexusVSMDeviceVO { this.setVsmPassword(password); this.setvCenterIPAddr(vCenterIpaddr); this.setvCenterDCName(vCenterDcName); + // By default, enable a VSM. + this.setVsmDeviceState(VSMDeviceState.Enabled); } public CiscoNexusVSMDeviceVO(String vsmIpAddr, String username, String password, long dummy) { // Set all the VSM's properties here. this.uuid = UUID.randomUUID().toString(); - this.ipaddr = vsmIpAddr; - this.vsmUserName = username; - this.vsmPassword = password; - this.vsmName = vsmName; + this.setMgmtIpAddr(vsmIpAddr); + this.setVsmUserName(username); + this.setVsmPassword(password); + this.setVsmName(vsmName); + this.setVsmDeviceState(VSMDeviceState.Enabled); } public CiscoNexusVSMDeviceVO() { diff --git a/server/src/com/cloud/network/element/CiscoNexusVSMElement.java b/server/src/com/cloud/network/element/CiscoNexusVSMElement.java index 653a10502d2..cb4966eb23a 100644 --- a/server/src/com/cloud/network/element/CiscoNexusVSMElement.java +++ b/server/src/com/cloud/network/element/CiscoNexusVSMElement.java @@ -23,6 +23,8 @@ import com.cloud.agent.AgentManager; import com.cloud.api.commands.AddCiscoNexusVSMCmd; import com.cloud.api.commands.DeleteCiscoNexusVSMCmd; import com.cloud.api.commands.ListCiscoNexusVSMCmd; +import com.cloud.api.commands.EnableCiscoNexusVSMCmd; +import com.cloud.api.commands.DisableCiscoNexusVSMCmd; import com.cloud.api.commands.ListCiscoNexusVSMNetworksCmd; import com.cloud.api.response.CiscoNexusVSMResponse; import com.cloud.configuration.ConfigurationManager; @@ -199,6 +201,20 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme } + @Override + public boolean enableCiscoNexusVSM(EnableCiscoNexusVSMCmd cmd) { + boolean result; + result = enableCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId()); + return result; + } + + @Override + public boolean disableCiscoNexusVSM(DisableCiscoNexusVSMCmd cmd) { + boolean result; + result = disableCiscoNexusVSM(cmd.getCiscoNexusVSMDeviceId()); + return result; + } + @Override public List listNetworks(ListCiscoNexusVSMNetworksCmd cmd) { @@ -227,6 +243,7 @@ public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl impleme return null; } + @Override public CiscoNexusVSMResponse createCiscoNexusVSMResponse(CiscoNexusVSMDeviceVO vsmDeviceVO) { diff --git a/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java b/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java index bf1cdf2324b..a9b0a06e461 100644 --- a/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java +++ b/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java @@ -22,6 +22,8 @@ import java.util.List; import com.cloud.api.commands.AddCiscoNexusVSMCmd; import com.cloud.api.commands.ConfigureCiscoNexusVSMCmd; import com.cloud.api.commands.DeleteCiscoNexusVSMCmd; +import com.cloud.api.commands.EnableCiscoNexusVSMCmd; +import com.cloud.api.commands.DisableCiscoNexusVSMCmd; import com.cloud.api.commands.ListCiscoNexusVSMNetworksCmd; import com.cloud.api.commands.ListCiscoNexusVSMCmd; import com.cloud.api.response.CiscoNexusVSMResponse; @@ -61,9 +63,21 @@ public interface CiscoNexusVSMElementService extends PluggableService { public List listNetworks(ListCiscoNexusVSMNetworksCmd cmd); /** - * creates API response object for netscaler load balancers - * @param lbDeviceVO external load balancer VO object - * @return NetscalerLoadBalancerResponse + * Enables a Cisco Nexus VSM. */ - public CiscoNexusVSMResponse createCiscoNexusVSMResponse(CiscoNexusVSMDeviceVO lbDeviceVO); + public boolean enableCiscoNexusVSM(EnableCiscoNexusVSMCmd cmd); + + + /** + * Disables a Cisco Nexus VSM. + */ + public boolean disableCiscoNexusVSM(DisableCiscoNexusVSMCmd cmd); + + /** + * creates API response object for Cisco Nexus VSMs + * @param vsmDeviceVO VSM VO object + * @return CiscoNexusVSMResponse + */ + + public CiscoNexusVSMResponse createCiscoNexusVSMResponse(CiscoNexusVSMDeviceVO vsmDeviceVO); } diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql index 274a32bc804..08e5c949dea 100755 --- a/setup/db/create-schema.sql +++ b/setup/db/create-schema.sql @@ -2105,7 +2105,7 @@ CREATE TABLE `cloud`.`virtual_supervisor_module` ( `vsmDomainId` bigint unsigned, `config_mode` varchar(20), `ConfigState` varchar(20), - `vsmDeviceState` varchar(20), + `vsmDeviceState` varchar(20) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;