blob: 8f4dbb1ebc6adcda787be8e8af50a788e9e5b86f [file] [log] [blame]
Hyunsun Moon34bbe172016-06-28 19:18:40 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
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
17package org.onosproject.openstacknode.cli;
18
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.onosproject.cli.AbstractShellCommand;
22import org.onosproject.openstacknode.OpenstackNode;
23import org.onosproject.openstacknode.OpenstackNodeService;
24
25import java.util.NoSuchElementException;
26
27/**
28 * Initializes nodes for OpenStack node service.
29 */
30@Command(scope = "onos", name = "openstack-node-init",
31 description = "Initializes nodes for OpenStack node service")
32public class OpenstackNodeInitCommand extends AbstractShellCommand {
33
34 @Argument(index = 0, name = "hostnames", description = "Hostname(s)",
35 required = true, multiValued = true)
36 private String[] hostnames = null;
37
38 @Override
39 protected void execute() {
40 OpenstackNodeService nodeService = AbstractShellCommand.get(OpenstackNodeService.class);
41
42 for (String hostname : hostnames) {
43 OpenstackNode node;
44 try {
45 node = nodeService.nodes()
46 .stream()
47 .filter(n -> n.hostname().equals(hostname))
48 .findFirst().get();
49 } catch (NoSuchElementException e) {
50 print("Unable to find %s", hostname);
51 continue;
52 }
53
54 nodeService.addOrUpdateNode(node);
55 }
56 }
57}