import java.util.HashMap;
import java.util.Map;
+import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.codehaus.enunciate.jaxrs.ResponseCode;
import org.codehaus.enunciate.jaxrs.StatusCodes;
-import org.codehaus.enunciate.jaxrs.TypeHint;
import org.opendaylight.controller.connectionmanager.IConnectionManager;
import org.opendaylight.controller.northbound.commons.exception.NotAcceptableException;
import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
-import org.opendaylight.controller.sal.connection.ConnectionConstants;
import org.opendaylight.controller.sal.core.Node;
import org.opendaylight.controller.sal.networkconfig.bridgedomain.ConfigConstants;
import org.opendaylight.controller.sal.networkconfig.bridgedomain.IBridgeDomainConfigService;
-import org.opendaylight.controller.sal.utils.NetUtils;
import org.opendaylight.controller.sal.utils.ServiceHelper;
import org.opendaylight.controller.sal.utils.Status;
import org.opendaylight.controller.sal.utils.StatusCode;
* @param nodeType Node Type of the node with the management session.
* @param nodeId Node Identifier of the node with the management session.
* @param bridgeName Name / Identifier for a bridge to be created.
+ * @param bridgeConfigs Additional Bridge Configurations.
*/
@Path("/bridge/{nodeType}/{nodeId}/{bridgeName}")
public Response createBridge(
@PathParam(value = "nodeType") String nodeType,
@PathParam(value = "nodeId") String nodeId,
- @PathParam(value = "bridgeName") String name) {
+ @PathParam(value = "bridgeName") String name,
+ Map<String, Object> bridgeConfigs) {
IBridgeDomainConfigService configurationService = getConfigurationService();
if (configurationService == null) {
Node node = Node.fromString(nodeType, nodeId);
Status status = null;
try {
- status = configurationService.createBridgeDomain(node, name, null);
+ Map<ConfigConstants, Object> configs = this.buildConfig(bridgeConfigs);
+ status = configurationService.createBridgeDomain(node, name, configs);
if (status.getCode().equals(StatusCode.SUCCESS)) {
return Response.status(Response.Status.CREATED).build();
}
* @param nodeId Node Identifier of the node with the management session.
* @param bridgeName Name / Identifier of the bridge to which a Port is being added.
* @param portName Name / Identifier of a Port that is being added to a bridge.
+ * @param portConfigs Additional Port Configurations.
*/
@Path("/port/{nodeType}/{nodeId}/{bridgeName}/{portName}")
@POST
+ @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@StatusCodes( { @ResponseCode(code = 201, condition = "Port added successfully"),
@ResponseCode(code = 404, condition = "Could not add Port to the Bridge"),
@ResponseCode(code = 412, condition = "Failed to add Port due to an exception"),
@PathParam(value = "nodeType") String nodeType,
@PathParam(value = "nodeId") String nodeId,
@PathParam(value = "bridgeName") String bridge,
- @PathParam(value = "portName") String port) {
+ @PathParam(value = "portName") String port,
+ Map<String, Object> portConfigs) {
IBridgeDomainConfigService configurationService = getConfigurationService();
if (configurationService == null) {
Node node = Node.fromString(nodeType, nodeId);
Status status = null;
try {
- status = configurationService.addPort(node, bridge, port, null);
+ Map<ConfigConstants, Object> configs = this.buildConfig(portConfigs);
+ status = configurationService.addPort(node, bridge, port, configs);
if (status.getCode().equals(StatusCode.SUCCESS)) {
return Response.status(Response.Status.CREATED).build();
}
throw new ResourceNotFoundException(status.getDescription());
}
- /**
+ private Map<ConfigConstants, Object> buildConfig(Map<String, Object> rawConfigs) {
+ if (rawConfigs == null) return null;
+ Map<ConfigConstants, Object> configs = new HashMap<ConfigConstants, Object>();
+ for (String key : rawConfigs.keySet()) {
+ ConfigConstants cc = ConfigConstants.valueOf(key.toUpperCase());
+ configs.put(cc, rawConfigs.get(key));
+ }
+ return configs;
+ }
+/**
* Add a Port,Vlan to a Bridge
* <pre>
*