[ONOS-5432] Add CLI for refresh/reprogram the data plane for the existing VM.
- Add CLI to purge flow rules installed by openstack apps.
- Add CLI to reinstall flow rules for the existing virtual instances.
- Remove CREATE_TIME from host annotation and revert to use host as a key of security group rule map.
Change-Id: Ie647e5a8c86e86deb8ff050ecf280527ad218eda
diff --git a/apps/openstacknetworking/cli/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackInstanceReInstallFlowCommand.java b/apps/openstacknetworking/cli/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackInstanceReInstallFlowCommand.java
new file mode 100644
index 0000000..8b53f87
--- /dev/null
+++ b/apps/openstacknetworking/cli/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackInstanceReInstallFlowCommand.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2016-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.openstacknetworking.cli;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.commands.Option;
+
+import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.net.Host;
+import org.onosproject.net.HostId;
+import org.onosproject.net.host.HostService;
+
+import org.onosproject.openstacknetworking.OpenstackSwitchingService;
+import org.onosproject.openstacknetworking.OpenstackSecurityGroupService;
+import org.onosproject.openstacknetworking.OpenstackRoutingService;
+import org.onosproject.openstacknetworking.OpenstackFloatingIpService;
+
+import static org.onosproject.openstacknetworking.Constants.*;
+
+/**
+ * Re-Install Flows of OpenstackInstance Data Plane.
+ */
+
+@Command(scope = "onos", name = "openstack-reinstall-flows",
+ description = "Re-install data plane flows of existing VM.")
+public class OpenstackInstanceReInstallFlowCommand extends AbstractShellCommand {
+
+ @Option(name = "-a", aliases = "--all",
+ description = "HostIDs are all existing VM", required = false, multiValued = false)
+ private Boolean allhost = false;
+
+ @Argument(index = 0, name = "hostId", description = "HostID(s)",
+ required = false, multiValued = true)
+ private String[] hostids = null;
+
+ @Override
+ protected void execute() {
+ HostService hostService = AbstractShellCommand.get(HostService.class);
+
+ OpenstackSwitchingService switchingService = getService(OpenstackSwitchingService.class);
+ OpenstackSecurityGroupService sgService = getService(OpenstackSecurityGroupService.class);
+ OpenstackRoutingService routingService = getService(OpenstackRoutingService.class);
+ OpenstackFloatingIpService floatingIpService = getService(OpenstackFloatingIpService.class);
+
+ if (allhost) {
+ hostService.getHosts().forEach(host -> {
+ switchingService.reinstallVmFlow(host);
+ sgService.reinstallVmFlow(host);
+ routingService.reinstallVmFlow(host);
+ floatingIpService.reinstallVmFlow(host);
+ printHost(host);
+
+ });
+ } else if (hostids != null) {
+ for (String hostid : hostids) {
+ Host host = hostService.getHost(HostId.hostId(hostid));
+ if (host == null) {
+ continue;
+ }
+ switchingService.reinstallVmFlow(host);
+ sgService.reinstallVmFlow(host);
+ routingService.reinstallVmFlow(host);
+ floatingIpService.reinstallVmFlow(host);
+ printHost(host);
+ }
+ }
+ }
+
+ private void printHost(Host host) {
+ print("Re-install data plane flows of VM(hostid=%s, vni=%s, ip=%s, mac=%s).",
+ host.id(), host.annotations().value(VXLAN_ID),
+ host.ipAddresses().stream().findFirst().get().getIp4Address(), host.mac());
+ }
+}