blob: 4ec2040c4f42f10d838318340bc78b7fa5d52cf0 [file] [log] [blame]
Hyunsun Moon838b19b2015-10-18 18:23:15 -07001/*
Brian O'Connor8e57fd52016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Hyunsun Moon838b19b2015-10-18 18:23:15 -07003 *
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
alshabibb4d31712016-06-01 18:51:03 -070017package org.opencord.cordvtn.cli;
Hyunsun Moon838b19b2015-10-18 18:23:15 -070018
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onosproject.cli.AbstractShellCommand;
alshabibb4d31712016-06-01 18:51:03 -070022import org.opencord.cordvtn.impl.CordVtnNodeManager;
23import org.opencord.cordvtn.api.CordVtnNode;
Hyunsun Moon838b19b2015-10-18 18:23:15 -070024
25import java.util.NoSuchElementException;
26
27/**
Hyunsun Moon4edb0172015-11-07 22:08:43 -080028 * Initializes nodes for CordVtn service.
Hyunsun Moon838b19b2015-10-18 18:23:15 -070029 */
Hyunsun Moon4edb0172015-11-07 22:08:43 -080030@Command(scope = "onos", name = "cordvtn-node-init",
31 description = "Initializes nodes for CORD VTN service")
32public class CordVtnNodeInitCommand extends AbstractShellCommand {
Hyunsun Moon838b19b2015-10-18 18:23:15 -070033
Hyunsun Moon4edb0172015-11-07 22:08:43 -080034 @Argument(index = 0, name = "hostnames", description = "Hostname(s)",
Hyunsun Moon838b19b2015-10-18 18:23:15 -070035 required = true, multiValued = true)
Hyunsun Moon4edb0172015-11-07 22:08:43 -080036 private String[] hostnames = null;
Hyunsun Moon838b19b2015-10-18 18:23:15 -070037
38 @Override
39 protected void execute() {
Hyunsun Mooncb799442016-01-15 20:03:18 -080040 CordVtnNodeManager nodeManager = AbstractShellCommand.get(CordVtnNodeManager.class);
Hyunsun Moon838b19b2015-10-18 18:23:15 -070041
Hyunsun Moon4edb0172015-11-07 22:08:43 -080042 for (String hostname : hostnames) {
43 CordVtnNode node;
Hyunsun Moon838b19b2015-10-18 18:23:15 -070044 try {
Hyunsun Mooncb799442016-01-15 20:03:18 -080045 node = nodeManager.getNodes()
Hyunsun Moon4edb0172015-11-07 22:08:43 -080046 .stream()
47 .filter(n -> n.hostname().equals(hostname))
Hyunsun Moon838b19b2015-10-18 18:23:15 -070048 .findFirst().get();
Hyunsun Moon838b19b2015-10-18 18:23:15 -070049 } catch (NoSuchElementException e) {
Hyunsun Moon4edb0172015-11-07 22:08:43 -080050 print("Unable to find %s", hostname);
Hyunsun Moon838b19b2015-10-18 18:23:15 -070051 continue;
52 }
53
Hyunsun Moonff55e812016-03-10 12:40:16 -080054 nodeManager.addOrUpdateNode(node);
Hyunsun Moon838b19b2015-10-18 18:23:15 -070055 }
56 }
57}