Committed by
Gerrit Code Review
[ONOS-2826] add floatingIp service cli
Change-Id: I5681397f8b0fd28f361517df1349916abb4df0a2
Showing
5 changed files
with
400 additions
and
0 deletions
apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpCreateCommand.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015 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 | +package org.onosproject.vtnrsc.cli.floatingip; | ||
| 17 | + | ||
| 18 | +import java.util.Set; | ||
| 19 | + | ||
| 20 | +import org.apache.karaf.shell.commands.Argument; | ||
| 21 | +import org.apache.karaf.shell.commands.Command; | ||
| 22 | +import org.apache.karaf.shell.commands.Option; | ||
| 23 | +import org.onlab.packet.IpAddress; | ||
| 24 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 25 | +import org.onosproject.vtnrsc.DefaultFloatingIp; | ||
| 26 | +import org.onosproject.vtnrsc.FloatingIpId; | ||
| 27 | +import org.onosproject.vtnrsc.FloatingIp; | ||
| 28 | +import org.onosproject.vtnrsc.FloatingIp.Status; | ||
| 29 | +import org.onosproject.vtnrsc.RouterId; | ||
| 30 | +import org.onosproject.vtnrsc.TenantId; | ||
| 31 | +import org.onosproject.vtnrsc.TenantNetworkId; | ||
| 32 | +import org.onosproject.vtnrsc.VirtualPortId; | ||
| 33 | +import org.onosproject.vtnrsc.floatingip.FloatingIpService; | ||
| 34 | + | ||
| 35 | +import com.google.common.collect.Sets; | ||
| 36 | + | ||
| 37 | +/** | ||
| 38 | + * Supports for create a floating IP. | ||
| 39 | + */ | ||
| 40 | +@Command(scope = "onos", name = "floatingip-create", | ||
| 41 | + description = "Supports for creating a floating IP") | ||
| 42 | +public class FloatingIpCreateCommand extends AbstractShellCommand { | ||
| 43 | + @Argument(index = 0, name = "id", description = "The floating IP identifier", | ||
| 44 | + required = true, multiValued = false) | ||
| 45 | + String id = null; | ||
| 46 | + | ||
| 47 | + @Argument(index = 1, name = "networkId", description = "The network identifier of floating IP", | ||
| 48 | + required = true, multiValued = false) | ||
| 49 | + String networkId = null; | ||
| 50 | + | ||
| 51 | + @Argument(index = 2, name = "tenantId", description = "The tenant identifier of floating IP", | ||
| 52 | + required = true, multiValued = false) | ||
| 53 | + String tenantId = null; | ||
| 54 | + | ||
| 55 | + @Argument(index = 3, name = "routerId", description = "The router identifier of floating IP", | ||
| 56 | + required = true, multiValued = false) | ||
| 57 | + String routerId = null; | ||
| 58 | + | ||
| 59 | + @Argument(index = 4, name = "fixedIp", description = "The fixed IP of floating IP", | ||
| 60 | + required = true, multiValued = false) | ||
| 61 | + String fixedIp = null; | ||
| 62 | + | ||
| 63 | + @Argument(index = 5, name = "floatingIp", description = "The floating IP of floating IP", | ||
| 64 | + required = true, multiValued = false) | ||
| 65 | + String floatingIp = null; | ||
| 66 | + | ||
| 67 | + @Option(name = "-p", aliases = "--portId", description = "The port identifier of floating IP", | ||
| 68 | + required = false, multiValued = false) | ||
| 69 | + String portId = null; | ||
| 70 | + | ||
| 71 | + @Option(name = "-s", aliases = "--status", description = "The status of floating IP", | ||
| 72 | + required = false, multiValued = false) | ||
| 73 | + String status = null; | ||
| 74 | + | ||
| 75 | + @Override | ||
| 76 | + protected void execute() { | ||
| 77 | + FloatingIpService service = get(FloatingIpService.class); | ||
| 78 | + try { | ||
| 79 | + FloatingIp floatingIpObj = new DefaultFloatingIp( | ||
| 80 | + FloatingIpId.of(id), | ||
| 81 | + TenantId.tenantId(tenantId), | ||
| 82 | + TenantNetworkId.networkId(networkId), | ||
| 83 | + VirtualPortId.portId(portId), | ||
| 84 | + RouterId.valueOf(routerId), | ||
| 85 | + floatingIp == null ? null : IpAddress.valueOf(floatingIp), | ||
| 86 | + fixedIp == null ? null : IpAddress.valueOf(fixedIp), | ||
| 87 | + status == null ? Status.ACTIVE | ||
| 88 | + : Status.valueOf(status)); | ||
| 89 | + Set<FloatingIp> floatingIpSet = Sets.newHashSet(floatingIpObj); | ||
| 90 | + service.createFloatingIps(floatingIpSet); | ||
| 91 | + } catch (Exception e) { | ||
| 92 | + print(null, e.getMessage()); | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | +} |
apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpQueryCommand.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015 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 | +package org.onosproject.vtnrsc.cli.floatingip; | ||
| 17 | + | ||
| 18 | +import org.apache.karaf.shell.commands.Command; | ||
| 19 | +import org.apache.karaf.shell.commands.Option; | ||
| 20 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 21 | +import org.onosproject.vtnrsc.FloatingIpId; | ||
| 22 | +import org.onosproject.vtnrsc.FloatingIp; | ||
| 23 | +import org.onosproject.vtnrsc.floatingip.FloatingIpService; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Supports for query a floating IP. | ||
| 27 | + */ | ||
| 28 | +@Command(scope = "onos", name = "floatingips", description = "Supports for querying a floating IP") | ||
| 29 | +public class FloatingIpQueryCommand extends AbstractShellCommand { | ||
| 30 | + @Option(name = "-I", aliases = "--id", description = "The floating IP identifier", | ||
| 31 | + required = false, multiValued = false) | ||
| 32 | + String id = null; | ||
| 33 | + | ||
| 34 | + @Option(name = "-i", aliases = "--fixedIp", description = "The fixed IP of floating IP", | ||
| 35 | + required = false, multiValued = false) | ||
| 36 | + String fixedIp = null; | ||
| 37 | + | ||
| 38 | + @Option(name = "-l", aliases = "--floatingIp", description = "The floating IP of floating IP", | ||
| 39 | + required = false, multiValued = false) | ||
| 40 | + String floatingIp = null; | ||
| 41 | + | ||
| 42 | + private static final String FMT = "floatingIpId=%s, networkId=%s, tenantId=%s, portId=%s," | ||
| 43 | + + "routerId=%s, fixedIp=%s, floatingIp=%s, status=%s"; | ||
| 44 | + | ||
| 45 | + @Override | ||
| 46 | + protected void execute() { | ||
| 47 | + FloatingIpService service = get(FloatingIpService.class); | ||
| 48 | + if (id != null) { | ||
| 49 | + FloatingIp floatingIp = service.getFloatingIp(FloatingIpId | ||
| 50 | + .of(id)); | ||
| 51 | + printFloatingIp(floatingIp); | ||
| 52 | + } else if (fixedIp != null || floatingIp != null) { | ||
| 53 | + Iterable<FloatingIp> floatingIps = service.getFloatingIps(); | ||
| 54 | + if (floatingIps == null) { | ||
| 55 | + return; | ||
| 56 | + } | ||
| 57 | + if (fixedIp != null) { | ||
| 58 | + for (FloatingIp floatingIp : floatingIps) { | ||
| 59 | + if (floatingIp.fixedIp().toString().equals(fixedIp)) { | ||
| 60 | + printFloatingIp(floatingIp); | ||
| 61 | + return; | ||
| 62 | + } | ||
| 63 | + } | ||
| 64 | + print(null, "The fixedIp is not existed"); | ||
| 65 | + } | ||
| 66 | + if (floatingIp != null) { | ||
| 67 | + for (FloatingIp floatingIpObj : floatingIps) { | ||
| 68 | + if (floatingIpObj.fixedIp().toString().equals(floatingIp)) { | ||
| 69 | + printFloatingIp(floatingIpObj); | ||
| 70 | + return; | ||
| 71 | + } | ||
| 72 | + } | ||
| 73 | + print(null, "The floatingIp is not existed"); | ||
| 74 | + } | ||
| 75 | + } else { | ||
| 76 | + Iterable<FloatingIp> floatingIps = service.getFloatingIps(); | ||
| 77 | + if (floatingIps == null) { | ||
| 78 | + return; | ||
| 79 | + } | ||
| 80 | + for (FloatingIp floatingIp : floatingIps) { | ||
| 81 | + printFloatingIp(floatingIp); | ||
| 82 | + } | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + private void printFloatingIp(FloatingIp floatingIp) { | ||
| 87 | + print(FMT, floatingIp.id(), floatingIp.networkId(), | ||
| 88 | + floatingIp.tenantId(), floatingIp.portId(), | ||
| 89 | + floatingIp.routerId(), floatingIp.fixedIp(), | ||
| 90 | + floatingIp.floatingIp(), floatingIp.status()); | ||
| 91 | + } | ||
| 92 | +} |
apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpRemoveCommand.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015 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 | +package org.onosproject.vtnrsc.cli.floatingip; | ||
| 17 | + | ||
| 18 | +import java.util.Set; | ||
| 19 | + | ||
| 20 | +import org.apache.karaf.shell.commands.Command; | ||
| 21 | +import org.apache.karaf.shell.commands.Option; | ||
| 22 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 23 | +import org.onosproject.vtnrsc.FloatingIp; | ||
| 24 | +import org.onosproject.vtnrsc.FloatingIpId; | ||
| 25 | +import org.onosproject.vtnrsc.floatingip.FloatingIpService; | ||
| 26 | + | ||
| 27 | +import com.google.common.collect.Sets; | ||
| 28 | + | ||
| 29 | +/** | ||
| 30 | + * Supports for remove a floating IP. | ||
| 31 | + */ | ||
| 32 | +@Command(scope = "onos", name = "floatingip-remove", description = "Supports for removing a floating IP") | ||
| 33 | +public class FloatingIpRemoveCommand extends AbstractShellCommand { | ||
| 34 | + @Option(name = "-I", aliases = "--id", description = "The floating IP identifier", | ||
| 35 | + required = false, multiValued = false) | ||
| 36 | + String id = null; | ||
| 37 | + | ||
| 38 | + @Option(name = "-i", aliases = "--fixedIp", description = "The fixed IP of floating IP", | ||
| 39 | + required = false, multiValued = false) | ||
| 40 | + String fixedIp = null; | ||
| 41 | + | ||
| 42 | + @Option(name = "-l", aliases = "--floatingIp", description = "The floating IP of floating IP", | ||
| 43 | + required = false, multiValued = false) | ||
| 44 | + String floatingIp = null; | ||
| 45 | + | ||
| 46 | + @Override | ||
| 47 | + protected void execute() { | ||
| 48 | + FloatingIpService service = get(FloatingIpService.class); | ||
| 49 | + if (id == null && fixedIp == null && floatingIp == null) { | ||
| 50 | + print(null, "one of id, fixedIp, floatingIp should not be null"); | ||
| 51 | + } | ||
| 52 | + try { | ||
| 53 | + Set<FloatingIpId> floatingIpSet = Sets.newHashSet(); | ||
| 54 | + if (id != null) { | ||
| 55 | + floatingIpSet.add(FloatingIpId.of(id)); | ||
| 56 | + service.removeFloatingIps(floatingIpSet); | ||
| 57 | + } else { | ||
| 58 | + Iterable<FloatingIp> floatingIps = service.getFloatingIps(); | ||
| 59 | + if (floatingIps == null) { | ||
| 60 | + return; | ||
| 61 | + } | ||
| 62 | + if (fixedIp != null) { | ||
| 63 | + for (FloatingIp floatingIp : floatingIps) { | ||
| 64 | + if (floatingIp.fixedIp().toString().equals(fixedIp)) { | ||
| 65 | + floatingIpSet.add(floatingIp.id()); | ||
| 66 | + service.removeFloatingIps(floatingIpSet); | ||
| 67 | + return; | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + print(null, "The fixedIp is not existed"); | ||
| 71 | + return; | ||
| 72 | + } | ||
| 73 | + if (floatingIp != null) { | ||
| 74 | + for (FloatingIp floatingIpObj : floatingIps) { | ||
| 75 | + if (floatingIpObj.fixedIp().toString() | ||
| 76 | + .equals(floatingIp)) { | ||
| 77 | + floatingIpSet.add(floatingIpObj.id()); | ||
| 78 | + service.removeFloatingIps(floatingIpSet); | ||
| 79 | + return; | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + print(null, "The floatingIp is not existed"); | ||
| 83 | + return; | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + } catch (Exception e) { | ||
| 87 | + print(null, e.getMessage()); | ||
| 88 | + } | ||
| 89 | + } | ||
| 90 | +} |
apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/cli/floatingip/FloatingIpUpdateCommand.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2015 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 | +package org.onosproject.vtnrsc.cli.floatingip; | ||
| 17 | + | ||
| 18 | +import java.util.Set; | ||
| 19 | + | ||
| 20 | +import org.apache.karaf.shell.commands.Argument; | ||
| 21 | +import org.apache.karaf.shell.commands.Command; | ||
| 22 | +import org.apache.karaf.shell.commands.Option; | ||
| 23 | +import org.onlab.packet.IpAddress; | ||
| 24 | +import org.onosproject.cli.AbstractShellCommand; | ||
| 25 | +import org.onosproject.vtnrsc.DefaultFloatingIp; | ||
| 26 | +import org.onosproject.vtnrsc.FloatingIpId; | ||
| 27 | +import org.onosproject.vtnrsc.FloatingIp; | ||
| 28 | +import org.onosproject.vtnrsc.FloatingIp.Status; | ||
| 29 | +import org.onosproject.vtnrsc.RouterId; | ||
| 30 | +import org.onosproject.vtnrsc.TenantId; | ||
| 31 | +import org.onosproject.vtnrsc.TenantNetworkId; | ||
| 32 | +import org.onosproject.vtnrsc.VirtualPortId; | ||
| 33 | +import org.onosproject.vtnrsc.floatingip.FloatingIpService; | ||
| 34 | + | ||
| 35 | +import com.google.common.collect.Sets; | ||
| 36 | + | ||
| 37 | +/** | ||
| 38 | + * Supports for update a floating IP. | ||
| 39 | + */ | ||
| 40 | +@Command(scope = "onos", name = "floatingip-update", | ||
| 41 | + description = "Supports for updating a floating IP") | ||
| 42 | +public class FloatingIpUpdateCommand extends AbstractShellCommand { | ||
| 43 | + @Argument(index = 0, name = "id", description = "The floating IP identifier", | ||
| 44 | + required = true, multiValued = false) | ||
| 45 | + String id = null; | ||
| 46 | + | ||
| 47 | + @Option(name = "-n", aliases = "--networkId", description = "The network identifier of floating IP", | ||
| 48 | + required = false, multiValued = false) | ||
| 49 | + String networkId = null; | ||
| 50 | + | ||
| 51 | + @Option(name = "-t", aliases = "--tenantId", description = "The tenant identifier of floating IP", | ||
| 52 | + required = false, multiValued = false) | ||
| 53 | + String tenantId = null; | ||
| 54 | + | ||
| 55 | + @Option(name = "-r", aliases = "--routerId", description = "The router identifier of floating IP", | ||
| 56 | + required = false, multiValued = false) | ||
| 57 | + String routerId = null; | ||
| 58 | + | ||
| 59 | + @Option(name = "-p", aliases = "--portId", description = "The port identifier of floating IP", | ||
| 60 | + required = false, multiValued = false) | ||
| 61 | + String portId = null; | ||
| 62 | + | ||
| 63 | + @Option(name = "-s", aliases = "--status", description = "The status of floating IP", | ||
| 64 | + required = false, multiValued = false) | ||
| 65 | + String status = null; | ||
| 66 | + | ||
| 67 | + @Option(name = "-i", aliases = "--fixedIp", description = "The fixed IP of floating IP", | ||
| 68 | + required = false, multiValued = false) | ||
| 69 | + String fixedIp = null; | ||
| 70 | + | ||
| 71 | + @Option(name = "-l", aliases = "--floatingIp", description = "The floating IP of floating IP", | ||
| 72 | + required = false, multiValued = false) | ||
| 73 | + String floatingIp = null; | ||
| 74 | + | ||
| 75 | + @Override | ||
| 76 | + protected void execute() { | ||
| 77 | + FloatingIpService service = get(FloatingIpService.class); | ||
| 78 | + FloatingIpId floatingIpId = FloatingIpId.of(id); | ||
| 79 | + FloatingIp floatingIpStore = get(FloatingIpService.class).getFloatingIp(floatingIpId); | ||
| 80 | + try { | ||
| 81 | + FloatingIp floatingIpObj = new DefaultFloatingIp( | ||
| 82 | + floatingIpId, | ||
| 83 | + tenantId == null ? floatingIpStore.tenantId() | ||
| 84 | + : TenantId.tenantId(tenantId), | ||
| 85 | + networkId == null ? floatingIpStore.networkId() | ||
| 86 | + : TenantNetworkId.networkId(networkId), | ||
| 87 | + portId == null ? floatingIpStore.portId() | ||
| 88 | + : VirtualPortId.portId(portId), | ||
| 89 | + routerId == null ? floatingIpStore.routerId() | ||
| 90 | + : RouterId.valueOf(routerId), | ||
| 91 | + floatingIp == null ? floatingIpStore.floatingIp() | ||
| 92 | + : IpAddress.valueOf(floatingIp), | ||
| 93 | + fixedIp == null ? floatingIpStore.fixedIp() | ||
| 94 | + : IpAddress.valueOf(fixedIp), | ||
| 95 | + status == null ? floatingIpStore.status() | ||
| 96 | + : Status.valueOf(status)); | ||
| 97 | + Set<FloatingIp> floatingIpSet = Sets.newHashSet(floatingIpObj); | ||
| 98 | + service.updateFloatingIps(floatingIpSet); | ||
| 99 | + } catch (Exception e) { | ||
| 100 | + print(null, e.getMessage()); | ||
| 101 | + } | ||
| 102 | + } | ||
| 103 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2015 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 | + | ||
| 17 | +/** | ||
| 18 | + * Command line interface for floatingIP. | ||
| 19 | + */ | ||
| 20 | +package org.onosproject.vtnrsc.cli.floatingip; |
-
Please register or login to post a comment