Charles Chan | 12a8a84 | 2020-02-14 13:23:57 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020-present Open Networking Foundation |
| 3 | * |
| 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 | */ |
| 16 | package org.onosproject.segmentrouting.cli; |
| 17 | |
| 18 | import org.apache.karaf.shell.api.action.Argument; |
| 19 | import org.apache.karaf.shell.api.action.Command; |
| 20 | import org.apache.karaf.shell.api.action.Completion; |
| 21 | import org.apache.karaf.shell.api.action.lifecycle.Service; |
| 22 | import org.onosproject.cli.AbstractShellCommand; |
| 23 | import org.onosproject.cli.net.DeviceIdCompleter; |
| 24 | import org.onosproject.net.DeviceId; |
| 25 | import org.onosproject.segmentrouting.phasedrecovery.api.Phase; |
| 26 | import org.onosproject.segmentrouting.phasedrecovery.api.PhasedRecoveryService; |
| 27 | |
| 28 | @Service |
| 29 | @Command(scope = "onos", name = "sr-pr-set", description = "Set recovery phase of given device") |
| 30 | |
| 31 | public class PhasedRecoverySetCommand extends AbstractShellCommand { |
| 32 | @Argument(index = 0, name = "deviceId", |
| 33 | description = "Device ID", |
| 34 | required = true, multiValued = false) |
| 35 | @Completion(DeviceIdCompleter.class) |
| 36 | private String deviceIdStr; |
| 37 | |
| 38 | @Argument(index = 1, name = "phase", |
| 39 | description = "Recovery phase", |
| 40 | required = true, multiValued = false) |
| 41 | @Completion(PhaseCompleter.class) |
| 42 | private String phaseStr; |
| 43 | |
| 44 | @Override |
| 45 | protected void doExecute() { |
| 46 | DeviceId deviceId = DeviceId.deviceId(deviceIdStr); |
| 47 | Phase newPhase = Phase.valueOf(phaseStr); |
| 48 | |
| 49 | PhasedRecoveryService prService = get(PhasedRecoveryService.class); |
| 50 | prService.setPhase(deviceId, newPhase); |
| 51 | } |
| 52 | } |