Search in sources :

Example 1 with DeviceKeyAdminService

use of org.onosproject.net.key.DeviceKeyAdminService in project onos by opennetworkinglab.

the class DeviceKeyRemoveCommand method doExecute.

@Override
protected void doExecute() {
    DeviceKeyAdminService service = get(DeviceKeyAdminService.class);
    service.removeKey(DeviceKeyId.deviceKeyId(id));
}
Also used : DeviceKeyAdminService(org.onosproject.net.key.DeviceKeyAdminService)

Example 2 with DeviceKeyAdminService

use of org.onosproject.net.key.DeviceKeyAdminService in project onos by opennetworkinglab.

the class DeviceKeyWebResource method addDeviceKey.

/**
 * Adds a new device key from the JSON input stream.
 *
 * @param stream device key JSON stream
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel Devicekey
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addDeviceKey(InputStream stream) {
    try {
        DeviceKeyAdminService service = get(DeviceKeyAdminService.class);
        ObjectNode root = readTreeFromStream(mapper(), stream);
        DeviceKey deviceKey = codec(DeviceKey.class).decode(root, this);
        service.addKey(deviceKey);
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path("keys").path(deviceKey.deviceKeyId().id());
        return Response.created(locationBuilder.build()).build();
    } catch (IOException ioe) {
        throw new IllegalArgumentException(ioe);
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceKey(org.onosproject.net.key.DeviceKey) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) DeviceKeyAdminService(org.onosproject.net.key.DeviceKeyAdminService) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 3 with DeviceKeyAdminService

use of org.onosproject.net.key.DeviceKeyAdminService in project onos by opennetworkinglab.

the class DeviceKeyAddCommand method doExecute.

@Override
protected void doExecute() {
    DeviceKeyAdminService service = get(DeviceKeyAdminService.class);
    DeviceKey deviceKey = null;
    if (type.equalsIgnoreCase(COMMUNITY_NAME)) {
        deviceKey = DeviceKey.createDeviceKeyUsingCommunityName(DeviceKeyId.deviceKeyId(id), label, communityName);
    } else if (type.equalsIgnoreCase(USERNAME)) {
        deviceKey = DeviceKey.createDeviceKeyUsingUsernamePassword(DeviceKeyId.deviceKeyId(id), label, username, password);
    } else {
        print("Invalid Device key type: {}", type);
        return;
    }
    service.addKey(deviceKey);
    print("Device Key successfully added.");
}
Also used : DeviceKey(org.onosproject.net.key.DeviceKey) DeviceKeyAdminService(org.onosproject.net.key.DeviceKeyAdminService)

Aggregations

DeviceKeyAdminService (org.onosproject.net.key.DeviceKeyAdminService)3 DeviceKey (org.onosproject.net.key.DeviceKey)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 IOException (java.io.IOException)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 UriBuilder (javax.ws.rs.core.UriBuilder)1