blob: e21cbc320648daf56f5c74040a345dffd2059ba0 [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;
Ray Milkey7a2dee52018-09-28 10:58:28 -070023import org.apache.karaf.shell.api.action.lifecycle.Service;
jiangrui800e26f2015-11-28 13:59:51 +080024import org.onlab.packet.IpAddress;
25import org.onosproject.cli.AbstractShellCommand;
26import org.onosproject.vtnrsc.DefaultFloatingIp;
27import org.onosproject.vtnrsc.FloatingIpId;
28import org.onosproject.vtnrsc.FloatingIp;
29import org.onosproject.vtnrsc.FloatingIp.Status;
30import org.onosproject.vtnrsc.RouterId;
31import org.onosproject.vtnrsc.TenantId;
32import org.onosproject.vtnrsc.TenantNetworkId;
33import org.onosproject.vtnrsc.VirtualPortId;
34import org.onosproject.vtnrsc.floatingip.FloatingIpService;
35
36import com.google.common.collect.Sets;
37
38/**
39 * Supports for create a floating IP.
40 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070041@Service
jiangrui800e26f2015-11-28 13:59:51 +080042@Command(scope = "onos", name = "floatingip-create",
43 description = "Supports for creating a floating IP")
44public class FloatingIpCreateCommand extends AbstractShellCommand {
45 @Argument(index = 0, name = "id", description = "The floating IP identifier",
46 required = true, multiValued = false)
47 String id = null;
48
49 @Argument(index = 1, name = "networkId", description = "The network identifier of floating IP",
50 required = true, multiValued = false)
51 String networkId = null;
52
53 @Argument(index = 2, name = "tenantId", description = "The tenant identifier of floating IP",
54 required = true, multiValued = false)
55 String tenantId = null;
56
57 @Argument(index = 3, name = "routerId", description = "The router identifier of floating IP",
58 required = true, multiValued = false)
59 String routerId = null;
60
61 @Argument(index = 4, name = "fixedIp", description = "The fixed IP of floating IP",
62 required = true, multiValued = false)
63 String fixedIp = null;
64
65 @Argument(index = 5, name = "floatingIp", description = "The floating IP of floating IP",
66 required = true, multiValued = false)
67 String floatingIp = null;
68
69 @Option(name = "-p", aliases = "--portId", description = "The port identifier of floating IP",
70 required = false, multiValued = false)
71 String portId = null;
72
73 @Option(name = "-s", aliases = "--status", description = "The status of floating IP",
74 required = false, multiValued = false)
75 String status = null;
76
77 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070078 protected void doExecute() {
jiangrui800e26f2015-11-28 13:59:51 +080079 FloatingIpService service = get(FloatingIpService.class);
80 try {
81 FloatingIp floatingIpObj = new DefaultFloatingIp(
82 FloatingIpId.of(id),
83 TenantId.tenantId(tenantId),
84 TenantNetworkId.networkId(networkId),
85 VirtualPortId.portId(portId),
86 RouterId.valueOf(routerId),
87 floatingIp == null ? null : IpAddress.valueOf(floatingIp),
88 fixedIp == null ? null : IpAddress.valueOf(fixedIp),
89 status == null ? Status.ACTIVE
90 : Status.valueOf(status));
91 Set<FloatingIp> floatingIpSet = Sets.newHashSet(floatingIpObj);
92 service.createFloatingIps(floatingIpSet);
93 } catch (Exception e) {
94 print(null, e.getMessage());
95 }
96 }
97}