blob: 45c6297668a04a3d02e6aa31281b94ead890680a [file] [log] [blame]
jiangrui800e26f2015-11-28 13:59:51 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
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
Ray Milkey86ad7bb2018-09-27 12:32:28 -070020import org.apache.karaf.shell.api.action.Argument;
21import org.apache.karaf.shell.api.action.Command;
22import org.apache.karaf.shell.api.action.Option;
jiangrui800e26f2015-11-28 13:59:51 +080023import 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 create a floating IP.
39 */
40@Command(scope = "onos", name = "floatingip-create",
41 description = "Supports for creating a floating IP")
42public 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
Ray Milkey86ad7bb2018-09-27 12:32:28 -070076 protected void doExecute() {
jiangrui800e26f2015-11-28 13:59:51 +080077 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}