Jian Li | 7b8c368 | 2019-05-12 13:57:15 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019-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.openstacknetworking.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.lifecycle.Service; |
| 21 | import org.onosproject.cli.AbstractShellCommand; |
| 22 | import org.onosproject.openstacknetworking.api.OpenstackHaService; |
| 23 | |
| 24 | /** |
| 25 | * Configures openstack HA. |
| 26 | */ |
| 27 | @Service |
| 28 | @Command(scope = "onos", name = "openstack-ha-config", |
| 29 | description = "Configure openstack active-standby HA status.") |
| 30 | public class OpenstackHaConfigCommand extends AbstractShellCommand { |
| 31 | |
| 32 | private static final String FLAG_TRUE = "true"; |
| 33 | private static final String FLAG_FALSE = "false"; |
| 34 | |
| 35 | @Argument(index = 0, name = "active node", description = "active node", |
| 36 | required = true, multiValued = false) |
| 37 | private String active = null; |
| 38 | |
| 39 | @Override |
| 40 | protected void doExecute() { |
| 41 | OpenstackHaService service = get(OpenstackHaService.class); |
| 42 | |
| 43 | if (FLAG_TRUE.equalsIgnoreCase(active)) { |
| 44 | service.setActive(true); |
| 45 | } else if (FLAG_FALSE.equalsIgnoreCase(active)) { |
| 46 | service.setActive(false); |
| 47 | } else { |
| 48 | error("The input value is not correct"); |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | String role = service.isActive() ? "ACTIVE" : "STANDBY"; |
| 53 | |
| 54 | print("Node is configured as " + role); |
| 55 | } |
| 56 | } |