blob: 40669cb34b6e3d1fc4b1fa96e55db356a2e73a6c [file] [log] [blame]
jiangrui7d2d7fb2015-08-11 18:43:57 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
jiangrui7d2d7fb2015-08-11 18:43:57 +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.network;
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;
jiangrui7d2d7fb2015-08-11 18:43:57 +080024import org.onosproject.cli.AbstractShellCommand;
25import org.onosproject.vtnrsc.DefaultTenantNetwork;
26import org.onosproject.vtnrsc.PhysicalNetwork;
27import org.onosproject.vtnrsc.SegmentationId;
28import org.onosproject.vtnrsc.TenantId;
29import org.onosproject.vtnrsc.TenantNetwork;
30import org.onosproject.vtnrsc.TenantNetworkId;
31import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
32
33import com.google.common.collect.Sets;
34
35/**
36 * Supports for creating a TenantNetwork.
37 */
Ray Milkey7a2dee52018-09-28 10:58:28 -070038@Service
jiangrui7d2d7fb2015-08-11 18:43:57 +080039@Command(scope = "onos", name = "tenantnetwork-create",
40 description = "Supports for creating a TenantNetwork")
41public class TenantNetworkCreateCommand extends AbstractShellCommand {
42
43 @Argument(index = 0, name = "id", description = "TenantNetwork network id", required = true,
44 multiValued = false)
45 String id = null;
46
47 @Argument(index = 1, name = "tenantID", description = "The tenant id of TenantNetwork",
48 required = true, multiValued = false)
49 String tenantID = null;
50
51 @Argument(index = 2, name = "type", description = "The type of TenantNetwork", required = true,
52 multiValued = false)
53 String type = null;
54
55 @Argument(index = 3, name = "segmentationID", description = "The segmentation id of TenantNetwork",
56 required = true, multiValued = false)
57 String segmentationID = "";
58
59 @Option(name = "-n", aliases = "--name", description = "TenantNetwork name", required = false,
60 multiValued = false)
61 String name = null;
62
63 @Option(name = "-a", aliases = "--adminStateUp", description = "TenantNetwork adminStateUp is true or false",
64 required = false, multiValued = false)
65 boolean adminStateUp = false;
66
67 @Option(name = "-s", aliases = "--state", description = "The state of TenantNetwork",
68 required = false, multiValued = false)
69 String state = null;
70
71 @Option(name = "-d", aliases = "--shared", description = "TenantNetwork is shared or not",
72 required = false, multiValued = false)
73 boolean shared = false;
74
75 @Option(name = "-r", aliases = "--routerExternal",
76 description = "TenantNetwork is routerExternal or not", required = false,
77 multiValued = false)
78 boolean routerExternal = false;
79
80 @Option(name = "-p", aliases = "--physicalNetwork", description = "The physical network of Tenant",
81 required = false, multiValued = false)
82 String physicalNetwork = "";
83
84 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -070085 protected void doExecute() {
jiangrui7d2d7fb2015-08-11 18:43:57 +080086 TenantNetworkService service = get(TenantNetworkService.class);
87 TenantNetwork network = new DefaultTenantNetwork(TenantNetworkId.networkId(id), name,
88 adminStateUp,
89 TenantNetwork.State.valueOf(state),
90 shared, TenantId.tenantId(tenantID),
91 routerExternal,
92 TenantNetwork.Type.valueOf(type),
93 PhysicalNetwork.physicalNetwork(physicalNetwork),
94 SegmentationId.segmentationId(segmentationID));
95
96 Set<TenantNetwork> networksSet = Sets.newHashSet(network);
97 service.createNetworks(networksSet);
98 }
99}