blob: 2156a06c5f3da2ccb9ac8b1ee6c38918c50045b3 [file] [log] [blame]
Andreas Papazoisc93117d2016-01-13 15:19:27 +02001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Andreas Papazoisc93117d2016-01-13 15:19:27 +02003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.cli.net;
17
18import org.apache.karaf.shell.commands.Argument;
19import org.apache.karaf.shell.commands.Command;
20import org.onosproject.cli.AbstractShellCommand;
21import org.onosproject.net.DeviceId;
22import org.onosproject.net.behaviour.ConfigSetter;
23import org.onosproject.net.driver.DriverHandler;
24import org.onosproject.net.driver.DriverService;
25
26import static com.google.common.base.Preconditions.checkNotNull;
27
28/**
29 * Command that sets the configuration included in the specified file to the
30 * specified device. It prints the response of the device.
31 *
32 * This is a temporary development tool for use until yang integration is complete.
33 * This uses a not properly specified behavior. DO NOT USE AS AN EXAMPLE.
34 */
35//Temporary Developer tool, NOT TO BE USED in production or as example for
36// future commands.
37//FIXME this should eventually be removed.
38
39@Command(scope = "onos", name = "device-setconfiguration",
40 description = "Sets the configuration of the specified file to the " +
41 "specified device.")
42public class DeviceConfigSetterCommand extends AbstractShellCommand {
43
44 @Argument(index = 0, name = "uri", description = "Device ID",
45 required = true, multiValued = false)
46 private String uri = null;
47 @Argument(index = 1, name = "cfgFile", description = "Configuration file",
48 required = true, multiValued = false)
49 private String cfgFile = null;
50 private DeviceId deviceId;
51
52 @Override
53 protected void execute() {
54 DriverService service = get(DriverService.class);
55 deviceId = DeviceId.deviceId(uri);
56 DriverHandler h = service.createHandler(deviceId);
57 ConfigSetter config = h.behaviour(ConfigSetter.class);
58 checkNotNull(cfgFile, "Configuration file cannot be null");
59 print(config.setConfiguration(cfgFile));
60 }
61
62}