diff --git a/api/src/com/cloud/api/ApiConstants.java b/api/src/com/cloud/api/ApiConstants.java index 4f73250456f..0da06302c20 100755 --- a/api/src/com/cloud/api/ApiConstants.java +++ b/api/src/com/cloud/api/ApiConstants.java @@ -332,8 +332,14 @@ public class ApiConstants { public static final String START_VM = "startvm"; public static final String HA_HOST = "hahost"; public static final String CUSTOM_DISK_OFF_MAX_SIZE = "customdiskofferingmaxsize"; - public static final String DEFAULT_ZONE_ID = "defaultzoneid"; + public static final String GUID = "guid"; + + public static final String EXTERNAL_SWITCH_MGMT_DEVICE_ID = "vsmdeviceid"; + public static final String EXTERNAL_SWITCH_MGMT_DEVICE_NAME = "vsmdevicename"; + public static final String EXTERNAL_SWITCH_MGMT_DEVICE_STATE = "vsmdevicestate"; + // Would we need to have a capacity field for Cisco N1KV VSM? Max hosts managed by it perhaps? May remove this later. + public static final String EXTERNAL_SWITCH_MGMT_DEVICE_CAPACITY = "vsmdevicecapacity"; public enum HostDetails { all, capacity, events, stats, min; diff --git a/api/src/com/cloud/api/response/CiscoNexusVSMResponse.java b/api/src/com/cloud/api/response/CiscoNexusVSMResponse.java new file mode 100644 index 00000000000..bca49c291a4 --- /dev/null +++ b/api/src/com/cloud/api/response/CiscoNexusVSMResponse.java @@ -0,0 +1,63 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/02/2012 +package com.cloud.api.response; + +import com.cloud.api.ApiConstants; +import com.cloud.api.IdentityProxy; +import com.cloud.serializer.Param; +import com.google.gson.annotations.SerializedName; + +public class CiscoNexusVSMResponse extends BaseResponse { + + @SerializedName(ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_ID) @Param(description="device id of the Cisco N1KV VSM device") + // Do we need a new table name for this? During discussion with Frank, we thought we could just use the host table. + private IdentityProxy id = new IdentityProxy("external_virtual_switch_management_devices"); + + // A Cisco n1kv vsm could be plumbed in multiple VLANs.. not sure what a physical network id is, so commenting it + // out for now. + //@SerializedName(ApiConstants.PHYSICAL_NETWORK_ID) @Param(description="the physical network to which this netscaler device belongs to") + //private IdentityProxy physicalNetworkId = new IdentityProxy("physical_network"); + + // What's a provider for netscaler? Not sure if we need this for n1kv vsm, so commenting it out. + //@SerializedName(ApiConstants.PROVIDER) @Param(description="name of the provider") + //private String providerName; + + @SerializedName(ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_NAME) @Param(description="device name") + private String deviceName; + + // Not sure if we need this but we'll keep it for now.. obviously we would want to know when an N1KV VSM is disabled or something. + @SerializedName(ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_STATE) @Param(description="device state") + private String deviceState; + + // Don't think we need to track the public interface/private interface of a VSM. We'd just need the ip addr. + //@SerializedName(ApiConstants.PUBLIC_INTERFACE) @Param(description="the public interface of the load balancer") + //private String publicInterface; + + //@SerializedName(ApiConstants.PRIVATE_INTERFACE) @Param(description="the private interface of the load balancer") + //private String privateInterface; + + @SerializedName(ApiConstants.IP_ADDRESS) @Param(description="the management IP address of the external Cisco Nexus 1000v Virtual Supervisor Module") + private String mgmtIpAddress; + + public void setId(long vsmDeviceId) { + this.id.setValue(vsmDeviceId); + } + + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; + } + + public void setMgmtIpAddress(String ipAddress) { + this.mgmtIpAddress = ipAddress; + } +} diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java index a13ff2c2cd7..ea3cb3e0d0e 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -240,11 +240,16 @@ public class EventTypes { public static final String EVENT_TRAFFIC_TYPE_UPDATE = "TRAFFIC.TYPE.UPDATE"; // external network device events - public static final String EVENT_EXTERAL_LB_DEVICE_ADD = "PHYSICAL.LOADBALANCER.ADD"; - public static final String EVENT_EXTERAL_LB_DEVICE_DELETE = "PHYSICAL.LOADBALANCER.DELETE"; - public static final String EVENT_EXTERAL_LB_DEVICE_CONFIGURE = "PHYSICAL.LOADBALANCER.CONFIGURE"; + public static final String EVENT_EXTERNAL_LB_DEVICE_ADD = "PHYSICAL.LOADBALANCER.ADD"; + public static final String EVENT_EXTERNAL_LB_DEVICE_DELETE = "PHYSICAL.LOADBALANCER.DELETE"; + public static final String EVENT_EXTERNAL_LB_DEVICE_CONFIGURE = "PHYSICAL.LOADBALANCER.CONFIGURE"; - public static final String EVENT_EXTERAL_FIREWALL_DEVICE_ADD = "PHYSICAL.FIREWALL.ADD"; - public static final String EVENT_EXTERAL_FIREWALL_DEVICE_DELETE = "PHYSICAL.FIREWALL.DELETE"; - public static final String EVENT_EXTERAL_FIREWALL_DEVICE_CONFIGURE = "PHYSICAL.FIREWALL.CONFIGURE"; + // 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_FIREWALL_DEVICE_ADD = "PHYSICAL.FIREWALL.ADD"; + public static final String EVENT_EXTERNAL_FIREWALL_DEVICE_DELETE = "PHYSICAL.FIREWALL.DELETE"; + public static final String EVENT_EXTERNAL_FIREWALL_DEVICE_CONFIGURE = "PHYSICAL.FIREWALL.CONFIGURE"; } diff --git a/api/src/com/cloud/host/Host.java b/api/src/com/cloud/host/Host.java index f570504d61d..c283b204749 100755 --- a/api/src/com/cloud/host/Host.java +++ b/api/src/com/cloud/host/Host.java @@ -31,6 +31,7 @@ public interface Host extends StateObject { ConsoleProxy(true), ExternalFirewall(false), ExternalLoadBalancer(false), + ExternalVirtualSwitchSupervisor(false), PxeServer(false), TrafficMonitor(false), diff --git a/api/src/com/cloud/network/PortProfile.java b/api/src/com/cloud/network/PortProfile.java new file mode 100644 index 00000000000..aa712a71efb --- /dev/null +++ b/api/src/com/cloud/network/PortProfile.java @@ -0,0 +1,90 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network; + +import java.util.ArrayList; +import java.util.List; + + +/** + * + * - Allocated = null + * - AccountId = null + * - DomainId = null + * + * - State = Allocated + * - AccountId = account owner. + * - DomainId = domain of the account owner. + * - Allocated = time it was allocated. + */ +// Do we need to make PortProfile an interface?!! +// And do we need to make this implement/extend +// ControlledEntity? +public class PortProfile { + + String ACL; // String is only a placeholder type, we need to make it a proper Cisco N1KV ACL type. + + List port_channel = new ArrayList(); + + int vlanId; + + int pVlanId; + + String NetFlow; // String is a placeholder!!! Replace with correct netflow type. + + String QoS; // placeholder type!! + + String RateLimiting; // placeholder type!! + + String PortSecurity; // placeholder type!! + + long portProfileId; + + long accountId; + + long domainId; + + String portProfileName; + + portProfileType portProfileType; + + public enum portProfileType { + System, + Normal + } + + + /** + * @return database id. + */ + public long getId() { + return portProfileId; + } + + public long getAllocatedToAccountId() { + return accountId; + } + + public long getAllocatedInDomainId() { + return domainId; + } + + // We'll put in other getter/setter methods for all the other fields too. + + PortProfile() { + // Do nothing for now. + // We probably need to generate a UUID for this portprofile. + return; + } + +} diff --git a/core/src/com/cloud/network/resource/CiscoNexusVSMResource.java b/core/src/com/cloud/network/resource/CiscoNexusVSMResource.java new file mode 100644 index 00000000000..09111d059b1 --- /dev/null +++ b/core/src/com/cloud/network/resource/CiscoNexusVSMResource.java @@ -0,0 +1,173 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package com.cloud.network.resource; + +import java.util.Map; +import javax.naming.ConfigurationException; +import com.cloud.agent.IAgentControl; +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.Command; +import com.cloud.agent.api.PingCommand; +import com.cloud.agent.api.StartupCommand; +import com.cloud.agent.api.StartupExternalLoadBalancerCommand; +import com.cloud.api.ApiConstants; +import com.cloud.host.Host; +import com.cloud.host.Host.Type; +import com.cloud.resource.ServerResource; +import com.cloud.serializer.GsonHelper; +import com.cloud.utils.NumbersUtil; +import com.google.gson.Gson; + +import com.cloud.utils.cisco.n1kv.vsm.CiscoNexusVSMService; + +import org.apache.log4j.Logger; + +class VSMError { + static final int VSM_RESOURCE_EXISTS = 89901; + static final int VSM_RESOURCE_NOT_EXISTS= 89902; + static final int VSM_NO_SERIVCE = 89903; + static final int VSM_OPERATION_NOT_PERMITTED = 89904; +} + +public class CiscoNexusVSMResource implements ServerResource { + + // deployment configuration + private String _name; + //private String _zoneId; + private String _ip; + private String _username; + private String _password; + private Integer _numRetries; + private static final Logger s_logger = Logger.getLogger(CiscoNexusVSMResource.class); + protected Gson _gson; + + // interface to interact with Cisco Nexus VSM devices + CiscoNexusVSMService _vsmService; + + Long _timeout = new Long(100000); + //base_response apiCallResult; + + // We need to store the result of the XML-RPC command sent to + // the VSM. For now it's a string. We should make this the appropriate XSD object. + String xml_rpc_response; + + public CiscoNexusVSMResource() { + _gson = GsonHelper.getGsonLogger(); + } + + + public boolean configure(String name, Map params) throws ConfigurationException { + try { + // What is this name?! Is it a name for the VSM device? What do we set this to?? + // Can't understand why the "Manager" interface needs a String name parameter for + // configure(). + + // Do we need this zone id???? We may need to add other info also, like a/c id etc. + /** + _zoneId = (String) params.get("zoneId"); + if (_zoneId == null) { + throw new ConfigurationException("Unable to find zone Id in the configuration parameters"); + } **/ + + _ip = (String) params.get(ApiConstants.IP_ADDRESS); + if (_ip == null) { + throw new ConfigurationException("Unable to find IP address in the configuration parameters"); + } + + _username = (String) params.get(ApiConstants.USERNAME); + if (_username == null) { + throw new ConfigurationException("Unable to find username in the configuration parameters"); + } + + _password = (String) params.get(ApiConstants.PASSWORD); + if (_password == null) { + throw new ConfigurationException("Unable to find password in the configuration parameters"); + } + + _numRetries = NumbersUtil.parseInt((String) params.get("numretries"), 2); + + // we may want to validate whether the username/password is right.. so we may want to + // issue a login to the VSM. However note that the VSM has a max limit of 8 concurrent + // sessions. We don't want a situation where we are opening concurrent sessions at all. + + return true; + } catch (Exception e) { + throw new ConfigurationException(e.getMessage()); + } + } + + @Override + public IAgentControl getAgentControl() { + return null; + } + + @Override + public void setAgentControl(IAgentControl agentControl) { + return; + } + + + @Override + public void disconnected() { + return; + } + + @Override + public Type getType() { + return Host.Type.ExternalVirtualSwitchSupervisor; + } + + @Override + public PingCommand getCurrentStatus(long id) { + return new PingCommand(Host.Type.ExternalVirtualSwitchSupervisor, id); + } + + @Override + public StartupCommand[] initialize() { + StartupExternalLoadBalancerCommand cmd = new StartupExternalLoadBalancerCommand(); + cmd.setName(_name); + //cmd.setDataCenter(_zoneId); + cmd.setPod(""); + cmd.setPrivateIpAddress(_ip); + cmd.setStorageIpAddress(""); + cmd.setVersion(""); + return new StartupCommand[]{cmd}; + } + + @Override + public Answer executeRequest(Command cmd) { + return executeRequest(cmd, _numRetries); + } + + // We will need to change this executeRequest() function. + + private Answer executeRequest(Command cmd, int numRetries) { + return Answer.createUnsupportedCommandAnswer(cmd); + } + + @Override + public String getName() { + return _name; + } + + @Override + public boolean start() { + return true; + } + + @Override + public boolean stop() { + return true; + } + +} \ 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 new file mode 100644 index 00000000000..c136dccc5a5 --- /dev/null +++ b/server/src/com/cloud/api/commands/AddCiscoNexusVSMCmd.java @@ -0,0 +1,135 @@ +/** + * 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.CiscoNexusVSMResponse; +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.CiscoNexusVSMDeviceVO; +import com.cloud.network.element.CiscoNexusVSMElementService; +import com.cloud.user.UserContext; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=CiscoNexusVSMResponse.class, description="Adds a Cisco Nexus 1000v Virtual Switch Manager device") +public class AddCiscoNexusVSMCmd extends BaseAsyncCmd { + + public static final Logger s_logger = Logger.getLogger(AddCiscoNexusVSMCmd.class.getName()); + private static final String s_name = "addciscon1kvvsmresponse"; + @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="external_virtual_switch_management_devices") + @Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, required = true, description="IP Address of the Cisco Nexus 1000v VSM appliance.") + private String ipaddr; + + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.STRING, required = true, description="Id of the zone in which the Cisco Nexus 1000v VSM appliance.") + private long zoneId; + + @Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="username to reach the Cisco Nexus 1000v VSM device") + private String username; + + @Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="password to reach the Cisco Nexus 1000v VSM device") + private String password; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required = false, description="name of Cisco Nexus 1000v VSM device") + private String vsmName; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getIpAddr() { + return ipaddr; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getVSMName() { + return vsmName; + } + + public long getZoneId() { + return zoneId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + CiscoNexusVSMDeviceVO vsmDeviceVO = _ciscoNexusVSMService.addCiscoNexusVSM(this); + if (vsmDeviceVO != null) { + CiscoNexusVSMResponse response = _ciscoNexusVSMService.createCiscoNexusVSMResponse(vsmDeviceVO); + response.setObjectName("cisconexusvsm"); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to add Cisco Nexus Virtual Switch Manager due to internal error."); + } + } 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 getEventDescription() { + return "Adding a Cisco Nexus VSM device"; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_ADD; + } + + @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/AddF5LoadBalancerCmd.java b/server/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java index d73f15f019d..bec09989abd 100644 --- a/server/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java +++ b/server/src/com/cloud/api/commands/AddF5LoadBalancerCmd.java @@ -115,7 +115,7 @@ public class AddF5LoadBalancerCmd extends BaseAsyncCmd { @Override public String getEventType() { - return EventTypes.EVENT_EXTERAL_LB_DEVICE_ADD; + return EventTypes.EVENT_EXTERNAL_LB_DEVICE_ADD; } @Override diff --git a/server/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java b/server/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java index dc1950c9f26..283293f4db5 100644 --- a/server/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java +++ b/server/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java @@ -114,7 +114,7 @@ public class AddNetscalerLoadBalancerCmd extends BaseAsyncCmd { @Override public String getEventType() { - return EventTypes.EVENT_EXTERAL_LB_DEVICE_ADD; + return EventTypes.EVENT_EXTERNAL_LB_DEVICE_ADD; } @Override diff --git a/server/src/com/cloud/api/commands/AddSrxFirewallCmd.java b/server/src/com/cloud/api/commands/AddSrxFirewallCmd.java index eb0010d1ff8..6a6bfaffd9c 100644 --- a/server/src/com/cloud/api/commands/AddSrxFirewallCmd.java +++ b/server/src/com/cloud/api/commands/AddSrxFirewallCmd.java @@ -114,7 +114,7 @@ public class AddSrxFirewallCmd extends BaseAsyncCmd { @Override public String getEventType() { - return EventTypes.EVENT_EXTERAL_FIREWALL_DEVICE_ADD; + return EventTypes.EVENT_EXTERNAL_FIREWALL_DEVICE_ADD; } @Override diff --git a/server/src/com/cloud/api/commands/ConfigureCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/ConfigureCiscoNexusVSMCmd.java new file mode 100644 index 00000000000..208f0b4b2ea --- /dev/null +++ b/server/src/com/cloud/api/commands/ConfigureCiscoNexusVSMCmd.java @@ -0,0 +1,117 @@ +/** + * 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.NetscalerLoadBalancerResponse; +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; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +//import com.cloud.network.ExternalLoadBalancerDeviceVO; +import com.cloud.network.CiscoNexusVSMDeviceVO; +//import com.cloud.network.element.NetscalerLoadBalancerElementService; +import com.cloud.network.element.CiscoNexusVSMElementService; +import com.cloud.user.UserContext; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=CiscoNexusVSMResponse.class, description="configures a netscaler load balancer device") +public class ConfigureCiscoNexusVSMCmd extends BaseAsyncCmd { + + public static final Logger s_logger = Logger.getLogger(ConfigureCiscoNexusVSMCmd.class.getName()); + private static final String s_name = "configurecisconexusvsmresponse"; + @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="external_virtual_switch_management_devices") + @Parameter(name=ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_ID, type=CommandType.LONG, required=true, description="Cisco Nexus 1000v VSM device ID") + private Long vsmDeviceId; + + // As of now, not sure what to configure the n1kv VSM device with! So we'll just place a note here to pass in the parameters we'd like to + // configure. + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getCiscoNexusVSMDeviceId() { + return vsmDeviceId; + } + + // We'll define more accessor methods in case we add more parameters above. + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + /** + try { + CiscoNexusVSMDeviceVO ciscoNexusVSMDeviceVO = _ciscoNexusVSMService.configureCiscoNexusVSM(this); + if (ciscoNexusVSMDeviceVO != null) { + CiscoNexusVSMResponse response = _ciscoNexusVSMService.createCiscoNexusVSMResponse(ciscoNexusVSMDeviceVO); + response.setObjectName("cisconexusvsm"); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to configure netscaler load balancer due to internal error."); + } + } 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 getEventDescription() { + return "Configuring a Cisco Nexus VSM device"; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_EXTERNAL_SWITCH_MGMT_DEVICE_CONFIGURE; + } + + @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/ConfigureF5LoadBalancerCmd.java b/server/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java index 75ab38264e1..20b2e5a3b8c 100644 --- a/server/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java +++ b/server/src/com/cloud/api/commands/ConfigureF5LoadBalancerCmd.java @@ -94,7 +94,7 @@ public class ConfigureF5LoadBalancerCmd extends BaseAsyncCmd { @Override public String getEventType() { - return EventTypes.EVENT_EXTERAL_LB_DEVICE_CONFIGURE; + return EventTypes.EVENT_EXTERNAL_LB_DEVICE_CONFIGURE; } @Override diff --git a/server/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java b/server/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java index 9044079a66a..f5633a34c5d 100644 --- a/server/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java +++ b/server/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java @@ -121,7 +121,7 @@ public class ConfigureNetscalerLoadBalancerCmd extends BaseAsyncCmd { @Override public String getEventType() { - return EventTypes.EVENT_EXTERAL_LB_DEVICE_CONFIGURE; + return EventTypes.EVENT_EXTERNAL_LB_DEVICE_CONFIGURE; } @Override diff --git a/server/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java b/server/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java index ff95c1c5758..62a5746a982 100644 --- a/server/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java +++ b/server/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java @@ -94,7 +94,7 @@ public class ConfigureSrxFirewallCmd extends BaseAsyncCmd { @Override public String getEventType() { - return EventTypes.EVENT_EXTERAL_FIREWALL_DEVICE_CONFIGURE; + return EventTypes.EVENT_EXTERNAL_FIREWALL_DEVICE_CONFIGURE; } @Override diff --git a/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java new file mode 100644 index 00000000000..6bf0f1b8a04 --- /dev/null +++ b/server/src/com/cloud/api/commands/DeleteCiscoNexusVSMCmd.java @@ -0,0 +1,106 @@ +/** + * 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=" delete a Cisco Nexus VSM device") +public class DeleteCiscoNexusVSMCmd extends BaseAsyncCmd { + + public static final Logger s_logger = Logger.getLogger(DeleteCiscoNexusVSMCmd.class.getName()); + private static final String s_name = "deletecisconexusvsmresponse"; + @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="external_virtual_switch_management_devices") + @Parameter(name=ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_ID, type=CommandType.LONG, required=true, description="Cisco Nexus 1000v VSM device ID") + private Long vsmDeviceId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getCiscoNexusVSMDeviceId() { + return vsmDeviceId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + boolean result = _ciscoNexusVSMService.deleteCiscoNexusVSM(this); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete 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 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; + } + + @Override + public long getEntityOwnerId() { + return UserContext.current().getCaller().getId(); + } +} diff --git a/server/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java b/server/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java index 25c8f32af36..18ec2301d80 100644 --- a/server/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java +++ b/server/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java @@ -84,7 +84,7 @@ public class DeleteSrxFirewallCmd extends BaseAsyncCmd { @Override public String getEventType() { - return EventTypes.EVENT_EXTERAL_FIREWALL_DEVICE_DELETE; + return EventTypes.EVENT_EXTERNAL_FIREWALL_DEVICE_DELETE; } @Override diff --git a/server/src/com/cloud/api/commands/ListCiscoNexusVSMCmd.java b/server/src/com/cloud/api/commands/ListCiscoNexusVSMCmd.java new file mode 100644 index 00000000000..2f45e96c630 --- /dev/null +++ b/server/src/com/cloud/api/commands/ListCiscoNexusVSMCmd.java @@ -0,0 +1,99 @@ +/** + * 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 java.util.ArrayList; +import java.util.List; + +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.ListResponse; +import com.cloud.api.response.CiscoNexusVSMResponse; +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.CiscoNexusVSMDeviceVO; +import com.cloud.network.element.CiscoNexusVSMElementService; +import com.cloud.utils.exception.CloudRuntimeException; + +@Implementation(responseObject=CiscoNexusVSMResponse.class, description="lists Cisco Nexus 1000v VSM devices") +public class ListCiscoNexusVSMCmd extends BaseListCmd { + + public static final Logger s_logger = Logger.getLogger(ListCiscoNexusVSMCmd.class.getName()); + private static final String s_name = "listcisconexusvsmresponse"; + @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="external_switch_management_devices") + @Parameter(name=ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_ID, type=CommandType.LONG, description="Cisco Nexus 1000v VSM device ID") + private Long vsmDeviceId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getCiscoNexusVSMDeviceId() { + return vsmDeviceId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + try { + List vsmDevices = _ciscoNexusVSMService.listCiscoNexusVSMs(this); + ListResponse response = new ListResponse(); + List vsmDevicesResponse = new ArrayList(); + + if (vsmDevices != null && !vsmDevices.isEmpty()) { + for (CiscoNexusVSMDeviceVO vsmDeviceVO : vsmDevices) { + CiscoNexusVSMResponse vsmdeviceResponse = _ciscoNexusVSMService.createCiscoNexusVSMResponse(vsmDeviceVO); + vsmDevicesResponse.add(vsmdeviceResponse); + } + } + response.setResponses(vsmDevicesResponse); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } 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; + } +} diff --git a/server/src/com/cloud/api/commands/ListCiscoNexusVSMNetworksCmd.java b/server/src/com/cloud/api/commands/ListCiscoNexusVSMNetworksCmd.java new file mode 100644 index 00000000000..77edebdc35c --- /dev/null +++ b/server/src/com/cloud/api/commands/ListCiscoNexusVSMNetworksCmd.java @@ -0,0 +1,103 @@ +/** + * 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 java.util.ArrayList; +import java.util.List; + +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.ListResponse; +import com.cloud.api.response.NetworkResponse; +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.Network; +import com.cloud.network.element.CiscoNexusVSMElementService; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.network.PortProfile; + +@Implementation(responseObject=NetworkResponse.class, description="lists network that are configured on a Cisco 1000v VSM device") +public class ListCiscoNexusVSMNetworksCmd extends BaseListCmd { + + public static final Logger s_logger = Logger.getLogger(ListCiscoNexusVSMNetworksCmd.class.getName()); + private static final String s_name = "listcisconexusvsmnetworkscmdresponse"; + @PlugService CiscoNexusVSMElementService _ciscoNexusVSMService; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="external_switch_management_devices") + @Parameter(name=ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_ID, type=CommandType.LONG, required = true, description="Cisco Nexus 1000v VSM device ID") + private Long vsmDeviceId; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getvsmDeviceId() { + return vsmDeviceId; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { + /** + try { + // may need to change Network to something else. + List networks = _ciscoNexusVSMService.listNetworks(this); + ListResponse response = new ListResponse(); + List networkResponses = new ArrayList(); + + if (networks != null && !networks.isEmpty()) { + for (Network network : networks) { + NetworkResponse networkResponse = _responseGenerator.createNetworkResponse(network); + networkResponses.add(networkResponse); + } + } + + response.setResponses(networkResponses); + response.setResponseName(getCommandName()); + this.setResponseObject(response); + } 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; + } +} diff --git a/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java b/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java new file mode 100644 index 00000000000..71b08a58ad8 --- /dev/null +++ b/server/src/com/cloud/network/CiscoNexusVSMDeviceManagerImpl.java @@ -0,0 +1,266 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network; + +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import javax.naming.ConfigurationException; + +import org.apache.log4j.Logger; + +import com.cloud.agent.AgentManager; +import com.cloud.agent.api.Answer; +import com.cloud.agent.api.StartupCommand; +import com.cloud.agent.api.StartupExternalLoadBalancerCommand; +import com.cloud.agent.api.routing.CreateLoadBalancerApplianceCommand; +import com.cloud.agent.api.routing.DestroyLoadBalancerApplianceCommand; +import com.cloud.agent.api.routing.IpAssocCommand; +import com.cloud.agent.api.routing.LoadBalancerConfigCommand; +import com.cloud.agent.api.routing.NetworkElementCommand; +import com.cloud.agent.api.routing.SetStaticNatRulesCommand; +import com.cloud.agent.api.to.IpAddressTO; +import com.cloud.agent.api.to.LoadBalancerTO; +import com.cloud.agent.api.to.StaticNatRuleTO; +import com.cloud.api.ApiConstants; +import com.cloud.configuration.Config; +import com.cloud.configuration.dao.ConfigurationDao; +import com.cloud.dc.DataCenter; +import com.cloud.dc.DataCenterIpAddressVO; +import com.cloud.dc.DataCenterVO; +import com.cloud.dc.Pod; +import com.cloud.dc.Vlan.VlanType; +import com.cloud.dc.VlanVO; +import com.cloud.dc.dao.DataCenterDao; +import com.cloud.dc.dao.HostPodDao; +import com.cloud.dc.dao.VlanDao; +import com.cloud.exception.InsufficientCapacityException; +import com.cloud.exception.InsufficientNetworkCapacityException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.host.DetailVO; +import com.cloud.host.Host; +import com.cloud.host.HostVO; +import com.cloud.host.dao.HostDao; +import com.cloud.host.dao.HostDetailsDao; +import com.cloud.network.ExternalLoadBalancerDeviceVO.LBDeviceAllocationState; +import com.cloud.network.ExternalLoadBalancerDeviceVO.LBDeviceState; +import com.cloud.network.ExternalNetworkDeviceManager.NetworkDevice; +import com.cloud.network.Network.Service; +import com.cloud.network.Networks.TrafficType; +import com.cloud.network.addr.PublicIp; +import com.cloud.network.dao.ExternalFirewallDeviceDao; +import com.cloud.network.dao.ExternalLoadBalancerDeviceDao; +import com.cloud.network.dao.IPAddressDao; +import com.cloud.network.dao.InlineLoadBalancerNicMapDao; +import com.cloud.network.dao.LoadBalancerDao; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkExternalFirewallDao; +import com.cloud.network.dao.NetworkExternalLoadBalancerDao; +import com.cloud.network.dao.NetworkServiceMapDao; +import com.cloud.network.dao.PhysicalNetworkDao; +import com.cloud.network.dao.PhysicalNetworkServiceProviderDao; +import com.cloud.network.dao.PhysicalNetworkServiceProviderVO; +import com.cloud.network.lb.LoadBalancingRule; +import com.cloud.network.lb.LoadBalancingRule.LbDestination; +import com.cloud.network.resource.CreateLoadBalancerApplianceAnswer; +import com.cloud.network.resource.DestroyLoadBalancerApplianceAnswer; +import com.cloud.network.rules.FirewallRule; +import com.cloud.network.rules.FirewallRule.Purpose; +import com.cloud.network.rules.FirewallRuleVO; +import com.cloud.network.rules.StaticNatRule; +import com.cloud.network.rules.StaticNatRuleImpl; +import com.cloud.network.rules.dao.PortForwardingRulesDao; +import com.cloud.offerings.NetworkOfferingVO; +import com.cloud.offerings.dao.NetworkOfferingDao; +import com.cloud.resource.ResourceManager; +import com.cloud.resource.ResourceState; +import com.cloud.resource.ResourceStateAdapter; +import com.cloud.resource.ServerResource; +import com.cloud.resource.UnableDeleteHostException; +import com.cloud.server.api.response.ExternalLoadBalancerResponse; +import com.cloud.user.Account; +import com.cloud.user.AccountManager; +import com.cloud.user.dao.AccountDao; +import com.cloud.user.dao.UserStatisticsDao; +import com.cloud.utils.NumbersUtil; +import com.cloud.utils.component.AdapterBase; +import com.cloud.utils.component.Inject; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.GlobalLock; +import com.cloud.utils.db.Transaction; +import com.cloud.utils.exception.CloudRuntimeException; +import com.cloud.utils.net.NetUtils; +import com.cloud.utils.net.UrlUtil; +import com.cloud.vm.Nic.ReservationStrategy; +import com.cloud.vm.Nic.State; +import com.cloud.vm.NicVO; +import com.cloud.vm.dao.DomainRouterDao; +import com.cloud.vm.dao.NicDao; +import com.cloud.network.dao.CiscoNexusVSMDeviceDao; + +//public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase implements CiscoNexusVSMDeviceManager, ResourceStateAdapter { +public abstract class CiscoNexusVSMDeviceManagerImpl extends AdapterBase { + + @Inject + CiscoNexusVSMDeviceDao _ciscoNexusVSMDeviceDao; + @Inject + HostDao _hostDao; + @Inject + DataCenterDao _dcDao; + @Inject + NetworkManager _networkMgr; + @Inject + InlineLoadBalancerNicMapDao _inlineLoadBalancerNicMapDao; + @Inject + NicDao _nicDao; + @Inject + AgentManager _agentMgr; + @Inject + ResourceManager _resourceMgr; + @Inject + IPAddressDao _ipAddressDao; + @Inject + VlanDao _vlanDao; + @Inject + NetworkOfferingDao _networkOfferingDao; + @Inject + AccountDao _accountDao; + @Inject + PhysicalNetworkDao _physicalNetworkDao; + @Inject + PhysicalNetworkServiceProviderDao _physicalNetworkServiceProviderDao; + @Inject + AccountManager _accountMgr; + @Inject + UserStatisticsDao _userStatsDao; + @Inject + NetworkDao _networkDao; + @Inject + DomainRouterDao _routerDao; + @Inject + LoadBalancerDao _loadBalancerDao; + @Inject + PortForwardingRulesDao _portForwardingRulesDao; + @Inject + ConfigurationDao _configDao; + @Inject + HostDetailsDao _hostDetailDao; + @Inject + NetworkExternalLoadBalancerDao _networkLBDao; + @Inject + NetworkServiceMapDao _ntwkSrvcProviderDao; + @Inject + NetworkExternalFirewallDao _networkExternalFirewallDao; + @Inject + ExternalFirewallDeviceDao _externalFirewallDeviceDao; + @Inject + protected HostPodDao _podDao = null; + + private long _defaultLbCapacity; + private static final org.apache.log4j.Logger s_logger = Logger.getLogger(ExternalLoadBalancerDeviceManagerImpl.class); + + @DB + public CiscoNexusVSMDeviceVO addCiscoNexusVSM(long zoneId, String ipaddress, String username, String password, ServerResource resource, String vsmName) { + + // In this function, we create a record for this Cisco Nexus VSM, in the database. + // We also hand off interaction with the actual Cisco Nexus VSM via XML-RPC, to the + // Resource Manager. The resource manager invokes the CiscoNexusVSMResource class's + // functionality to talk to the VSM via Java bindings for the VSM's XML-RPC commands. + + Map hostDetails = new HashMap(); + // Do we need guid, zone id, account id, etc??? + hostDetails.put(ApiConstants.IP_ADDRESS, ipaddress); + hostDetails.put(ApiConstants.USERNAME, username); + hostDetails.put(ApiConstants.PASSWORD, password); + // Q1) Do we need a zoneUuid to dbzoneId translation? How will the user send in the zoneId? + // We get the zoneId as a uuid, so we need to look up the db zoneId. + // Ask Frank how to do this lookup. + long dbZoneId = zoneId; + + // Q2) Do we need to have the user send in a "DedicatedUse" parameter? What is it's use + // for Netscaler? + + hostDetails.put(ApiConstants.ZONE_ID, dbZoneId); + hostDetails.put(ApiConstants.GUID, UUID.randomUUID().toString()); + + // leave parameter validation to be part of server resource configure + Map configParams = new HashMap(); + hostDetails.putAll(configParams); + + Transaction txn = Transaction.currentTxn(); + try { + resource.configure(vsmName, hostDetails); + //resource.discover(vsmName, hostDetails); + + // we get a hostVO object. + Host host = _resourceMgr.addHost(dbZoneId, resource, Host.Type.ExternalVirtualSwitchSupervisor, hostDetails); + if (host != null) { + txn.start(); + // host.getId() is the zoneId + // Create a VO object from the info that came in from the command. + CiscoNexusVSMDeviceVO vsmDeviceVO = new CiscoNexusVSMDeviceVO(host.getId(), ipaddress, username, password); + // Write the VO record to the table for our Cisco N1KV VSM (external_virtual_switch_management_devices). + _ciscoNexusVSMDeviceDao.persist(vsmDeviceVO); + + // Write out another standard VO to another table host_details. We always do this when adding a host. + DetailVO hostDetail = new DetailVO(host.getId(), ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_ID, String.valueOf(vsmDeviceVO.getId())); + _hostDetailDao.persist(hostDetail); + + txn.commit(); + return vsmDeviceVO; + } else { + throw new CloudRuntimeException("Failed to add load balancer device due to internal error."); + } + } catch (ConfigurationException e) { + txn.rollback(); + throw new CloudRuntimeException(e.getMessage()); + } + } + + + public boolean deleteCiscoNexusVSM(long hostId) { + HostVO cisconexusvsm = _hostDao.findById(hostId); + if (cisconexusvsm == null) { + throw new InvalidParameterValueException("Could not find a Cisco Nexus 1000v VSM with specified ID" + hostId); + } + + DetailVO vsmHostDetails = _hostDetailDao.findDetail(hostId, ApiConstants.EXTERNAL_SWITCH_MGMT_DEVICE_ID); + long vsmDeviceId = Long.parseLong(vsmHostDetails.getValue()); + + //CiscoNexusVSMDeviceVO vsmDeviceVO = _ciscoNexusVSMDeviceDao.findById(vsmDeviceId); + + try { + _hostDao.update(hostId, cisconexusvsm); + _resourceMgr.deleteHost(hostId, false, false); + + // delete the db entry + _ciscoNexusVSMDeviceDao.remove(vsmDeviceId); + + return true; + } catch (Exception e) { + s_logger.debug(e); + return false; + } + } + + 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 new file mode 100644 index 00000000000..51f7fbf50ad --- /dev/null +++ b/server/src/com/cloud/network/CiscoNexusVSMDeviceVO.java @@ -0,0 +1,286 @@ +/** + * 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.network; + +import java.util.UUID; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +/** + * CiscoNexusVSMDeviceVO contains information on external Cisco Nexus 1000v VSM devices added into a deployment. + * This should be probably made as a more generic class so that we can handle multiple versions of Nexus VSMs + * in future. + */ + +@Entity +@Table(name="external_virtual_switch_management_devices") +public class CiscoNexusVSMDeviceVO { + + // We need to know what properties a VSM has. Put them here. + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + @Column(name="uuid") + private String uuid; + + @Column(name = "host_id") + private long hostId; + + @Column(name = "vsm_name") + private String vsmName; + + @Column(name = "username") + private String vsmUserName; + + @Column(name = "password") + private String vsmPassword; + + @Column(name = "vmsmgmtipaddr") + private String vsmMgmtIPAddr; + + @Column(name = "vcenteripaddr") + private String vCenterIPAddr; + + // Name of the DataCenter (as seen in vCenter) that this VSM manages. + @Column(name = "vcenterdcname") + private String vCenterDCName; + + @Column(name = "management_vlan") + private int managementVlan; + + @Column(name = "control_vlan") + private int controlVlan; + + @Column(name = "packet_vlan") + private int packetVlan; + + @Column(name = "storage_vlan") + private int storageVlan; + + @Column(name = "vsmDomainId") + private long vsmDomainId; + + @Column(name = "config_mode") + private VSMConfigMode vsmConfigMode; + + @Column(name = "ConfigState") + private VSMConfigState vsmConfigState; + + @Column(name = "vsmDeviceState") + private VSMDeviceState vsmDeviceState; + + // ********** The ones below could be removed... + + // Id of the DataCenter (as seen in vCenter) that this VSM manages. + // We can probably remove this. + @Column(name = "vcenteredcid") + private long vCenterDCId; + + // Name of the DVS that gets created on vCenter to represent this VSM. + // Can be queried and hence can be most probably removed. + @Column(name = "dvsname") + private String dvsName; + + // Number of VEMs being currently managed by this VSM. + // Again, queriable/removable. + @Column(name = "num_of_vems") + private int numVEMS; + + // ******** End of removable candidates. + + + + // This tells us whether the VSM is currently enabled or disabled. We may + // need this if we would like to carry out any sort of maintenance on the + // VSM or CS. + public enum VSMDeviceState { + Enabled, + Disabled + } + + // This tells us whether the VSM is currently configured with a standby (HA) + // or does not have any standby (Standalone). + public enum VSMConfigMode { + Standalone, + HA + } + + // This tells us whether the VSM is currently a primary or a standby VSM. + public enum VSMConfigState { + Primary, + Standby + } + + // Accessor methods + public long getId() { + return id; + } + + public String getvsmName() { + return vsmName; + } + + public long getHostId() { + return hostId; + } + + public String getUserName() { + return vsmUserName; + } + + public String getPassword() { + return vsmPassword; + } + + public String getMgmtIpAddr() { + return vsmMgmtIPAddr; + } + + public String getvCenterIPAddr() { + return vCenterIPAddr; + } + + public String getvCenterDCName() { + return vCenterDCName; + } + + public int getManagementVlan() { + return managementVlan; + } + + public int getControlVlan() { + return controlVlan; + } + + public int getPacketVlan() { + return packetVlan; + } + + public int getStorageVlan() { + return storageVlan; + } + + public long getvsmDomainId() { + return vsmDomainId; + } + + public VSMConfigMode getvsmConfigMode() { + return vsmConfigMode; + } + + public VSMConfigState getvsmConfigState() { + return vsmConfigState; + } + + public VSMDeviceState getvsmDeviceState() { + return vsmDeviceState; + } + + public String getUuid() { + return uuid; + } + + // Setter methods + + public void setHostId(long hostid) { + this.hostId = hostid; + } + + public void getUserName(String username) { + this.vsmUserName = username; + } + + public void setvsmName(String vsmName) { + this.vsmName = vsmName; + } + + public void setPassword(String password) { + this.vsmPassword = password; + } + + public void setMgmtIpAddr(String ipaddr) { + this.vsmMgmtIPAddr = ipaddr; + } + + public void setvCenterIPAddr(String ipaddr) { + this.vCenterIPAddr = ipaddr; + } + + public void setvCenterDCName(String dcname) { + this.vCenterDCName = dcname; + } + + public void setManagementVlan(int vlan) { + this.managementVlan = vlan; + } + + public void setControlVlan(int vlan) { + this.controlVlan = vlan; + } + + public void setPacketVlan(int vlan) { + this.packetVlan = vlan; + } + + public void setStorageVlan(int vlan) { + this.storageVlan = vlan; + } + + public void setvsmDomainId(long id) { + this.vsmDomainId = id; + } + + public void setvsmConfigMode(VSMConfigMode mode) { + this.vsmConfigMode = mode; + } + + public void setvsmConfigState(VSMConfigState state) { + this.vsmConfigState = state; + } + + public void setvsmDeviceState(VSMDeviceState devState) { + this.vsmDeviceState = devState; + } + + + // Constructor methods. + + public CiscoNexusVSMDeviceVO(long id, String vsmIpAddr, String username, String password) { + // Set all the VSM's properties here. + this.id = id; + this.uuid = UUID.randomUUID().toString(); + this.vsmMgmtIPAddr = vsmIpAddr; + this.vsmUserName = username; + this.vsmPassword = password; + } + + public CiscoNexusVSMDeviceVO() { + this.uuid = UUID.randomUUID().toString(); + } +} diff --git a/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDao.java b/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDao.java new file mode 100644 index 00000000000..e348db39b66 --- /dev/null +++ b/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDao.java @@ -0,0 +1,95 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.dao; + +import java.util.List; +import com.cloud.network.CiscoNexusVSMDeviceVO; +import com.cloud.network.CiscoNexusVSMDeviceVO.VSMDeviceState; +import com.cloud.utils.db.GenericDao; + +public interface CiscoNexusVSMDeviceDao extends GenericDao { + + /** + * Return a Cisco Nexus VSM record given its switch domain Id. + * @param Cisco Nexus VSM Switch Domain Id + * @return CiscoNexusVSMDeviceVO for the VSM having the specified switch domain Id. + */ + CiscoNexusVSMDeviceVO getVSMbyDomainId(long domId); + + /** + * Return a Cisco Nexus VSM VO (db record) given its name. + * @param vsmName + */ + CiscoNexusVSMDeviceVO getVSMbyName(String vsmName); + + /** + * Return a list of VSM devices that use the same VLAN for no matter what interface. Unlikely, but oh well. + * @param vlanId + * - Needs to filter results by the invoker's account Id. So we may end up adding another param + * or may query it in the function. + * @return + */ + List listByVlanId(int vlanId); + + /** + * Return a list of VSM devices that use the same VLAN for their mgmt interface. Again, unlikely, but we'll just keep it around. + * @param vlanId + * @return + */ + List listByMgmtVlan(int vlanId); + + /** + * 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. + * + * ListbyZoneId() + - Lists all VSMs in the specified zone. + + ListbyAccountId() + - Lists all VSMs owned by the specified Account. + + ListbyStorageVLAN(vlanId) + - Lists all VSMs whose storage VLAN matches the specified VLAN. + - Filters results by the invoker's account Id. + + ListbyControlVLAN(vlanId) + - Lists all VSMs whose control VLAN matches the specified VLAN. + - Filters results by the invoker's account Id. + + ListbyPacketVLAN(vlanId) + - Lists all VSMs whose Packet VLAN matches the specified VLAN. + - Filters results by the invoker's account Id. + + ListbyConfigMode(mode) + - Lists all VSMs which are currently configured in the specified mode (standalone/HA). + - Filters results by the invoker's account Id. + + ListbyConfigState(configState) + - Lists all VSMs which are currently configured in the specified state (primary/standby). + - Filters results by the invoker's account Id. + + ListbyDeviceState(deviceState) + - Lists all VSMs which are currently in the specified device state (enabled/disabled). + - Filters results by the invoker's account Id. + + + getBySwitchDomainId(domId) + - Retrieves the VSM with the specified switch domain Id. Each VSM has a unique switch domain Id, just like a real physical switch would. + - Filters results by invoker's account id. + + + getbySwitchName(vsmName) + - Retrieves the VSM's VO object by the specified vsmName. + + */ +} diff --git a/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java b/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java new file mode 100644 index 00000000000..af499d07e40 --- /dev/null +++ b/server/src/com/cloud/network/dao/CiscoNexusVSMDeviceDaoImpl.java @@ -0,0 +1,86 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.dao; + +import java.util.List; +import javax.ejb.Local; + +import com.cloud.network.CiscoNexusVSMDeviceVO; +import com.cloud.utils.db.DB; +import com.cloud.utils.db.GenericDaoBase; +import com.cloud.utils.db.SearchBuilder; +import com.cloud.utils.db.SearchCriteria; +import com.cloud.utils.db.SearchCriteria.Op; + +@Local(value=CiscoNexusVSMDeviceDao.class) @DB(txn=false) +public class CiscoNexusVSMDeviceDaoImpl extends GenericDaoBase implements CiscoNexusVSMDeviceDao { + final SearchBuilder mgmtVlanIdSearch; + final SearchBuilder domainIdSearch; + final SearchBuilder nameSearch; + final SearchBuilder genericVlanIdSearch; + // We will add more searchbuilder objects. + + + public CiscoNexusVSMDeviceDaoImpl() { + super(); + + mgmtVlanIdSearch = createSearchBuilder(); + mgmtVlanIdSearch.and("management_vlan", mgmtVlanIdSearch.entity().getManagementVlan(), Op.EQ); + mgmtVlanIdSearch.done(); + + genericVlanIdSearch = createSearchBuilder(); + genericVlanIdSearch.and("management_vlan", genericVlanIdSearch.entity().getManagementVlan(), Op.EQ); + genericVlanIdSearch.or("control_vlan", genericVlanIdSearch.entity().getControlVlan(), Op.EQ); + genericVlanIdSearch.or("packet_vlan", genericVlanIdSearch.entity().getPacketVlan(), Op.EQ); + genericVlanIdSearch.or("storage_vlan", genericVlanIdSearch.entity().getStorageVlan(), Op.EQ); + genericVlanIdSearch.done(); + + domainIdSearch = createSearchBuilder(); + domainIdSearch.and("vsmSwitchDomainId", domainIdSearch.entity().getvsmDomainId(), Op.EQ); + domainIdSearch.done(); + + nameSearch = createSearchBuilder(); + nameSearch.and("vsmName", nameSearch.entity().getvsmName(), Op.EQ); + nameSearch.done(); + + + // We may add more and conditions by specifying more fields, like say, accountId. + } + + public CiscoNexusVSMDeviceVO getVSMbyDomainId(long domId) { + SearchCriteria sc = domainIdSearch.create(); + sc.setParameters("vsmSwitchDomainId", domId); + return findOneBy(sc); + } + + public CiscoNexusVSMDeviceVO getVSMbyName(String vsmName) { + SearchCriteria sc = nameSearch.create(); + sc.setParameters("vsmName", vsmName); + return findOneBy(sc); + } + + public List listByMgmtVlan(int vlanId) { + SearchCriteria sc = mgmtVlanIdSearch.create(); + sc.setParameters("management_vlan", vlanId); + return search(sc, null); + } + + public List listByVlanId(int vlanId) { + SearchCriteria sc = genericVlanIdSearch.create(); + sc.setParameters("management_vlan", vlanId); + sc.setParameters("storage_vlan", vlanId); + sc.setParameters("packet_vlan", vlanId); + sc.setParameters("control_vlan", vlanId); + return search(sc, null); + } +} \ No newline at end of file diff --git a/server/src/com/cloud/network/element/CiscoNexusVSMElement.java b/server/src/com/cloud/network/element/CiscoNexusVSMElement.java new file mode 100644 index 00000000000..91884ebf4f0 --- /dev/null +++ b/server/src/com/cloud/network/element/CiscoNexusVSMElement.java @@ -0,0 +1,141 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// Automatically generated by addcopyright.py at 04/03/2012 +package com.cloud.network.element; + +import java.util.List; + +import javax.ejb.Local; + +import org.apache.log4j.Logger; + +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.ListCiscoNexusVSMNetworksCmd; +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.host.dao.HostDao; +import com.cloud.host.dao.HostDetailsDao; +import com.cloud.network.CiscoNexusVSMDeviceVO; +import com.cloud.network.CiscoNexusVSMDeviceManagerImpl; +import com.cloud.network.NetworkManager; +import com.cloud.network.dao.NetworkDao; +import com.cloud.network.dao.NetworkServiceMapDao; +import com.cloud.network.dao.PhysicalNetworkDao; +import com.cloud.network.resource.CiscoNexusVSMResource; +import com.cloud.resource.ServerResource; +import com.cloud.utils.component.Inject; +import com.cloud.network.PortProfile; + +@Local(value = NetworkElement.class) +public class CiscoNexusVSMElement extends CiscoNexusVSMDeviceManagerImpl implements CiscoNexusVSMElementService { + + 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; + + + public CiscoNexusVSMDeviceVO addCiscoNexusVSM(AddCiscoNexusVSMCmd cmd) { + + // This function essentially prepares all the parameters we need to send + // to the addCiscoNexusVSM() function defined in CiscoNexusVSMDeviceManagerImpl.java. + + // We have this separation of functionality between CiscoNexusVSMElement.java + // to address multiple versions of Cisco Nexus Switches in future. This is the + // function/layer that will parse multiple versions and accordingly prepare + // different parameters to pass to to the CiscoNexusVSMDeviceManagerImpl functions + // which will in turn talk to the right resource via the appropriate manager. + + String vsmipaddress = cmd.getIpAddr(); + String vsmusername = cmd.getUsername(); + String vsmpassword = cmd.getPassword(); + String vsmName = cmd.getVSMName(); + long zoneId = cmd.getZoneId(); + + // Invoke the addCiscoNexusVSM() function defined in the upper layer (DeviceMgrImpl). + // The upper layer function will create a resource of type "host" to represent this VSM. + // It will add this VSM to the db. + CiscoNexusVSMDeviceVO vsmDeviceVO = addCiscoNexusVSM(zoneId, vsmipaddress, vsmusername, vsmpassword, (ServerResource) new CiscoNexusVSMResource(), vsmName); + return vsmDeviceVO; + } + + public boolean deleteCiscoNexusVSM(DeleteCiscoNexusVSMCmd cmd) { + return true; + } + + + public List listNetworks(ListCiscoNexusVSMNetworksCmd cmd) { + + /*** + // Get the device id of the VSM from the database. + Long vsmDeviceId = cmd.getvsmDeviceId(); + + // Get all details of the VSM by firing a dao find (querying the db). + CiscoNexusVSMDeviceVO vsmDeviceVo = _lbDeviceDao.findById(vsmDeviceId); + + List portProfileMap = _networkLBDao.listByLoadBalancerDeviceId(lbDeviceId); + if (networkLbMaps != null && !networkLbMaps.isEmpty()) { + for (NetworkExternalLoadBalancerVO networkLbMap : networkLbMaps) { + NetworkVO network = _networkDao.findById(networkLbMap.getNetworkId()); + networks.add(network); + } + } + + return networks; + ***/ + return null; + } + + public List listCiscoNexusVSMs(ListCiscoNexusVSMCmd cmd) { + return null; + + } + + public CiscoNexusVSMResponse createCiscoNexusVSMResponse(CiscoNexusVSMDeviceVO vsmDeviceVO) { + CiscoNexusVSMResponse response = new CiscoNexusVSMResponse(); + response.setId(vsmDeviceVO.getId()); + response.setMgmtIpAddress(vsmDeviceVO.getMgmtIpAddr()); + return response; + } + + + public String getPropertiesFile() { + return null; + } +} \ No newline at end of file diff --git a/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java b/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java new file mode 100644 index 00000000000..bf1cdf2324b --- /dev/null +++ b/server/src/com/cloud/network/element/CiscoNexusVSMElementService.java @@ -0,0 +1,69 @@ +/** + * 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.network.element; + +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.ListCiscoNexusVSMNetworksCmd; +import com.cloud.api.commands.ListCiscoNexusVSMCmd; +import com.cloud.api.response.CiscoNexusVSMResponse; +import com.cloud.network.CiscoNexusVSMDeviceVO; +import com.cloud.network.Network; +import com.cloud.network.PortProfile; +import com.cloud.utils.component.PluggableService; + +public interface CiscoNexusVSMElementService extends PluggableService { + + /** + * adds a Cisco Nexus VSM + * @param AddCiscoNexusVSMCmd + * @return CiscoNexusVSMDeviceVO object for the device added + */ + public CiscoNexusVSMDeviceVO addCiscoNexusVSM(AddCiscoNexusVSMCmd cmd); + + /** + * removes a Cisco Nexus VSM + * @param DeleteCiscoNexusVSMCmd + * @return true if VSM is deleted successfully + */ + public boolean deleteCiscoNexusVSM(DeleteCiscoNexusVSMCmd cmd); + + /** + * lists all the VSMs the Mgmt Server knows of. + * @param ListCiscoNexusVSMCmd + * @return list of CiscoNexusVSMDeviceVO for the VSMs the mgmt server knows of. + */ + public List listCiscoNexusVSMs(ListCiscoNexusVSMCmd cmd); + + /** + * lists all the networks (port profiles) configured on the VSM. + * @param ListCiscoNexusVSMCmd + * @return list of the guest networks that are using this Netscaler load balancer + */ + public List listNetworks(ListCiscoNexusVSMNetworksCmd cmd); + + /** + * creates API response object for netscaler load balancers + * @param lbDeviceVO external load balancer VO object + * @return NetscalerLoadBalancerResponse + */ + public CiscoNexusVSMResponse createCiscoNexusVSMResponse(CiscoNexusVSMDeviceVO lbDeviceVO); +} diff --git a/utils/src/com/cloud/utils/cisco/n1kv/vsm/CiscoNexusVSMService.java b/utils/src/com/cloud/utils/cisco/n1kv/vsm/CiscoNexusVSMService.java new file mode 100644 index 00000000000..0316bf7eae0 --- /dev/null +++ b/utils/src/com/cloud/utils/cisco/n1kv/vsm/CiscoNexusVSMService.java @@ -0,0 +1,54 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package com.cloud.utils.cisco.n1kv.vsm; + +import com.cloud.utils.cisco.n1kv.vsm.VSMCommand; +import com.cloud.utils.cisco.n1kv.vsm.VSMResponse; + +import org.apache.log4j.Logger; + +// import all the packages we need here. +// We'll need the Nexus vsm xsd files for one.. +// We'll need some netconf libraries probably.. +// Definitely some XML parser libraries. + + +public class CiscoNexusVSMService extends Object { + // This class contains static routines to interact with Cisco N1KV VSM devices. + + public static final Logger s_logger = Logger.getLogger(CiscoNexusVSMService.class.getName()); + + public static int connectToVSM(String ipAddr, String userName, String password) { + return 0; // for now.. we'll return some kind of session id, which will probably be + // a thread ID. Not sure how this will shape up but these are just placeholder + // comments. + } + + public static void disconnectFromVSM(int sessionId) { + return; // Always return success for this one. Layers calling this will simply clean up + // any state info regarding this session. + } + + public static VSMResponse executeVSMCommand(VSMCommand cmd) { + VSMResponse resp = new VSMResponse(); + return resp; // for now we just return a dummy response. We define these new + // VSMCommand and VSMResponse classes in this same package. The + // input params to this function may change as we put in more + // concrete functionality. + } + +} + + + + diff --git a/utils/src/com/cloud/utils/cisco/n1kv/vsm/VSMCommand.java b/utils/src/com/cloud/utils/cisco/n1kv/vsm/VSMCommand.java new file mode 100644 index 00000000000..c4eb9c42045 --- /dev/null +++ b/utils/src/com/cloud/utils/cisco/n1kv/vsm/VSMCommand.java @@ -0,0 +1,31 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package com.cloud.utils.cisco.n1kv.vsm; + +public class VSMCommand { + String XML_command; + + public void setXMLCommand(String xmlCmd) { + this.XML_command = xmlCmd; + return; + } + + public String getXMLCommand() { + return this.XML_command; + } + + // we probably should put in other functions here + // that help construct the XML command. Or probably + // we're better off putting them in the layers that + // create an object of this class. +} \ No newline at end of file diff --git a/utils/src/com/cloud/utils/cisco/n1kv/vsm/VSMResponse.java b/utils/src/com/cloud/utils/cisco/n1kv/vsm/VSMResponse.java new file mode 100644 index 00000000000..2168152bac7 --- /dev/null +++ b/utils/src/com/cloud/utils/cisco/n1kv/vsm/VSMResponse.java @@ -0,0 +1,31 @@ +// Copyright 2012 Citrix Systems, Inc. Licensed under the +// Apache License, Version 2.0 (the "License"); you may not use this +// file except in compliance with the License. Citrix Systems, Inc. +// reserves all rights not expressly granted by the License. +// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +package com.cloud.utils.cisco.n1kv.vsm; + +public class VSMResponse { + String XML_response; + + public void setXMLresponse(String xmlResp) { + this.XML_response = xmlResp; + return; + } + + public String getXMLResponse() { + return this.XML_response; + } + + // we probably should put in other functions here + // that help parse the XML command. Or probably + // we're better off putting them in the layers that + // create an object of this class. +} \ No newline at end of file