blob: eda334d3bf840c0cd104e68b8329ebf7a069a36d [file] [log] [blame]
jskimaa851932016-10-27 17:45:30 +09001/*
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.openstacknetworking.cli;
18
19import org.apache.karaf.shell.commands.Argument;
20import org.apache.karaf.shell.commands.Command;
21import org.apache.karaf.shell.commands.Option;
22
23import org.onosproject.cli.AbstractShellCommand;
24import org.onosproject.net.Host;
25import org.onosproject.net.HostId;
26import org.onosproject.net.host.HostService;
27
Hyunsun Moon05400872017-02-07 17:11:25 +090028import org.onosproject.openstacknetworking.api.OpenstackSwitchingService;
29import org.onosproject.openstacknetworking.api.OpenstackSecurityGroupService;
30import org.onosproject.openstacknetworking.api.OpenstackRoutingService;
31import org.onosproject.openstacknetworking.api.OpenstackFloatingIpService;
jskimaa851932016-10-27 17:45:30 +090032
Hyunsun Moon05400872017-02-07 17:11:25 +090033import static org.onosproject.openstacknetworking.api.Constants.*;
jskimaa851932016-10-27 17:45:30 +090034
35/**
36 * Re-Install Flows of OpenstackInstance Data Plane.
37 */
38
39@Command(scope = "onos", name = "openstack-reinstall-flows",
40 description = "Re-install data plane flows of existing VM.")
41public class OpenstackInstanceReInstallFlowCommand extends AbstractShellCommand {
42
43 @Option(name = "-a", aliases = "--all",
44 description = "HostIDs are all existing VM", required = false, multiValued = false)
45 private Boolean allhost = false;
46
47 @Argument(index = 0, name = "hostId", description = "HostID(s)",
48 required = false, multiValued = true)
49 private String[] hostids = null;
50
51 @Override
52 protected void execute() {
53 HostService hostService = AbstractShellCommand.get(HostService.class);
54
55 OpenstackSwitchingService switchingService = getService(OpenstackSwitchingService.class);
56 OpenstackSecurityGroupService sgService = getService(OpenstackSecurityGroupService.class);
57 OpenstackRoutingService routingService = getService(OpenstackRoutingService.class);
58 OpenstackFloatingIpService floatingIpService = getService(OpenstackFloatingIpService.class);
59
60 if (allhost) {
61 hostService.getHosts().forEach(host -> {
62 switchingService.reinstallVmFlow(host);
63 sgService.reinstallVmFlow(host);
64 routingService.reinstallVmFlow(host);
65 floatingIpService.reinstallVmFlow(host);
66 printHost(host);
67
68 });
69 } else if (hostids != null) {
70 for (String hostid : hostids) {
71 Host host = hostService.getHost(HostId.hostId(hostid));
72 if (host == null) {
73 continue;
74 }
75 switchingService.reinstallVmFlow(host);
76 sgService.reinstallVmFlow(host);
77 routingService.reinstallVmFlow(host);
78 floatingIpService.reinstallVmFlow(host);
79 printHost(host);
80 }
81 }
82 }
83
84 private void printHost(Host host) {
85 print("Re-install data plane flows of VM(hostid=%s, vni=%s, ip=%s, mac=%s).",
86 host.id(), host.annotations().value(VXLAN_ID),
87 host.ipAddresses().stream().findFirst().get().getIp4Address(), host.mac());
88 }
89}