blob: 85da391a6e29a195d36683b4a94cde747e9e8bf5 [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;
Hyunsun Moon0d457362017-06-27 17:19:41 +090022import org.onosproject.openstacknode.api.NodeState;
23import org.onosproject.openstacknode.api.OpenstackNode;
24import org.onosproject.openstacknode.api.OpenstackNodeAdminService;
25import org.onosproject.openstacknode.api.OpenstackNodeService;
Hyunsun Moon34bbe172016-06-28 19:18:40 -070026
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() {
Hyunsun Moon0d457362017-06-27 17:19:41 +090040 OpenstackNodeService osNodeService =
41 AbstractShellCommand.get(OpenstackNodeService.class);
42 OpenstackNodeAdminService osNodeAdminService =
43 AbstractShellCommand.get(OpenstackNodeAdminService.class);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070044
45 for (String hostname : hostnames) {
Hyunsun Moon0d457362017-06-27 17:19:41 +090046 OpenstackNode osNode = osNodeService.node(hostname);
47 if (osNode == null) {
Hyunsun Moon34bbe172016-06-28 19:18:40 -070048 print("Unable to find %s", hostname);
49 continue;
50 }
Hyunsun Moon0d457362017-06-27 17:19:41 +090051 OpenstackNode updated = osNode.updateState(NodeState.INIT);
52 osNodeAdminService.updateNode(updated);
Hyunsun Moon34bbe172016-06-28 19:18:40 -070053 }
54 }
55}