blob: da894a3548f7b22882b19ab2a1b3b0a81932e9e7 [file] [log] [blame]
jiangrui800e26f2015-11-28 13:59:51 +08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
jiangrui800e26f2015-11-28 13:59:51 +08003 *
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 */
16package org.onosproject.vtnrsc.cli.floatingip;
17
18import java.util.Set;
19
20import org.apache.karaf.shell.commands.Argument;
21import org.apache.karaf.shell.commands.Command;
22import org.apache.karaf.shell.commands.Option;
23import org.onlab.packet.IpAddress;
24import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.vtnrsc.DefaultFloatingIp;
26import org.onosproject.vtnrsc.FloatingIpId;
27import org.onosproject.vtnrsc.FloatingIp;
28import org.onosproject.vtnrsc.FloatingIp.Status;
29import org.onosproject.vtnrsc.RouterId;
30import org.onosproject.vtnrsc.TenantId;
31import org.onosproject.vtnrsc.TenantNetworkId;
32import org.onosproject.vtnrsc.VirtualPortId;
33import org.onosproject.vtnrsc.floatingip.FloatingIpService;
34
35import 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")
42public 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}