jiangrui
Committed by Gerrit Code Review

[ONOS-2252] The CLIs of network resource.

Change-Id: Ib1f8aef7251ac74e8eafabb2ae5d413fc0b4fa67
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.network;
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.onosproject.cli.AbstractShellCommand;
24 +import org.onosproject.vtnrsc.DefaultTenantNetwork;
25 +import org.onosproject.vtnrsc.PhysicalNetwork;
26 +import org.onosproject.vtnrsc.SegmentationId;
27 +import org.onosproject.vtnrsc.TenantId;
28 +import org.onosproject.vtnrsc.TenantNetwork;
29 +import org.onosproject.vtnrsc.TenantNetworkId;
30 +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
31 +
32 +import com.google.common.collect.Sets;
33 +
34 +/**
35 + * Supports for creating a TenantNetwork.
36 + */
37 +@Command(scope = "onos", name = "tenantnetwork-create",
38 + description = "Supports for creating a TenantNetwork")
39 +public class TenantNetworkCreateCommand extends AbstractShellCommand {
40 +
41 + @Argument(index = 0, name = "id", description = "TenantNetwork network id", required = true,
42 + multiValued = false)
43 + String id = null;
44 +
45 + @Argument(index = 1, name = "tenantID", description = "The tenant id of TenantNetwork",
46 + required = true, multiValued = false)
47 + String tenantID = null;
48 +
49 + @Argument(index = 2, name = "type", description = "The type of TenantNetwork", required = true,
50 + multiValued = false)
51 + String type = null;
52 +
53 + @Argument(index = 3, name = "segmentationID", description = "The segmentation id of TenantNetwork",
54 + required = true, multiValued = false)
55 + String segmentationID = "";
56 +
57 + @Option(name = "-n", aliases = "--name", description = "TenantNetwork name", required = false,
58 + multiValued = false)
59 + String name = null;
60 +
61 + @Option(name = "-a", aliases = "--adminStateUp", description = "TenantNetwork adminStateUp is true or false",
62 + required = false, multiValued = false)
63 + boolean adminStateUp = false;
64 +
65 + @Option(name = "-s", aliases = "--state", description = "The state of TenantNetwork",
66 + required = false, multiValued = false)
67 + String state = null;
68 +
69 + @Option(name = "-d", aliases = "--shared", description = "TenantNetwork is shared or not",
70 + required = false, multiValued = false)
71 + boolean shared = false;
72 +
73 + @Option(name = "-r", aliases = "--routerExternal",
74 + description = "TenantNetwork is routerExternal or not", required = false,
75 + multiValued = false)
76 + boolean routerExternal = false;
77 +
78 + @Option(name = "-p", aliases = "--physicalNetwork", description = "The physical network of Tenant",
79 + required = false, multiValued = false)
80 + String physicalNetwork = "";
81 +
82 + @Override
83 + protected void execute() {
84 + TenantNetworkService service = get(TenantNetworkService.class);
85 + TenantNetwork network = new DefaultTenantNetwork(TenantNetworkId.networkId(id), name,
86 + adminStateUp,
87 + TenantNetwork.State.valueOf(state),
88 + shared, TenantId.tenantId(tenantID),
89 + routerExternal,
90 + TenantNetwork.Type.valueOf(type),
91 + PhysicalNetwork.physicalNetwork(physicalNetwork),
92 + SegmentationId.segmentationId(segmentationID));
93 +
94 + Set<TenantNetwork> networksSet = Sets.newHashSet(network);
95 + service.createNetworks(networksSet);
96 + }
97 +}
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.network;
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.TenantNetwork;
22 +import org.onosproject.vtnrsc.TenantNetworkId;
23 +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
24 +
25 +/**
26 + * Supports for querying TenantNetworks by network id.
27 + */
28 +@Command(scope = "onos", name = "tenantnetworks", description = "Supports for querying"
29 + + "tenantNetworks by networkid")
30 +public class TenantNetworkQueryCommand extends AbstractShellCommand {
31 +
32 + @Option(name = "-i", aliases = "--id", description = "TenantNetwork id", required = false,
33 + multiValued = false)
34 + String id = null;
35 +
36 + private static final String FMT = "networkId=%s, networkName=%s, segmentationId=%s,"
37 + + "tenantId=%s, type=%s, adminStateUp=%s";
38 +
39 + @Override
40 + protected void execute() {
41 + TenantNetworkService service = get(TenantNetworkService.class);
42 + if (id != null) {
43 + TenantNetwork network = service.getNetwork(TenantNetworkId.networkId(id));
44 + printNetwork(network);
45 + } else {
46 + Iterable<TenantNetwork> networks = service.getNetworks();
47 + for (TenantNetwork network : networks) {
48 + printNetwork(network);
49 + }
50 + }
51 + }
52 +
53 + private void printNetwork(TenantNetwork network) {
54 + if (network == null) {
55 + return;
56 + }
57 + print(FMT, network.id(), network.name(), network.segmentationId(),
58 + network.tenantId(), network.type(), network.adminStateUp());
59 + }
60 +}
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.network;
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.onosproject.cli.AbstractShellCommand;
23 +import org.onosproject.vtnrsc.TenantNetworkId;
24 +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
25 +
26 +import com.google.common.collect.Sets;
27 +
28 +/**
29 + * Supports for removing a TenantNetwork by network id.
30 + */
31 +@Command(scope = "onos", name = "tenantnetwork-remove", description = "Supports for removing"
32 + + " a tenantNetwork by tenantNetworkid")
33 +public class TenantNetworkRemoveCommand extends AbstractShellCommand {
34 +
35 + @Argument(index = 0, name = "id", description = "TenantNetwork neutronNetwork Id",
36 + required = true, multiValued = false)
37 + String id = null;
38 +
39 + @Override
40 + protected void execute() {
41 + TenantNetworkService service = get(TenantNetworkService.class);
42 + Set<TenantNetworkId> networkIds = Sets.newHashSet(TenantNetworkId.networkId(id));
43 + service.removeNetworks(networkIds);
44 + }
45 +}
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.network;
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.onosproject.cli.AbstractShellCommand;
24 +import org.onosproject.vtnrsc.DefaultTenantNetwork;
25 +import org.onosproject.vtnrsc.PhysicalNetwork;
26 +import org.onosproject.vtnrsc.SegmentationId;
27 +import org.onosproject.vtnrsc.TenantId;
28 +import org.onosproject.vtnrsc.TenantNetwork;
29 +import org.onosproject.vtnrsc.TenantNetworkId;
30 +import org.onosproject.vtnrsc.tenantnetwork.TenantNetworkService;
31 +
32 +import com.google.common.collect.Sets;
33 +
34 +/**
35 + * Supports for updating a TenantNetwork.
36 + */
37 +@Command(scope = "onos", name = "tenantnetwork-update",
38 + description = "Supports for updating a TenantNetwork")
39 +public class TenantNetworkUpdateCommand extends AbstractShellCommand {
40 +
41 + @Argument(index = 0, name = "id", description = "TenantNetwork network id", required = true,
42 + multiValued = false)
43 + String id = null;
44 +
45 + @Argument(index = 1, name = "tenantID", description = "The tenant id of TenantNetwork",
46 + required = true, multiValued = false)
47 + String tenantID = null;
48 +
49 + @Argument(index = 2, name = "type", description = "The type of TenantNetwork", required = true,
50 + multiValued = false)
51 + String type = null;
52 +
53 + @Argument(index = 3, name = "segmentationID", description = "The segmentation id of TenantNetwork",
54 + required = true, multiValued = false)
55 + String segmentationID = "";
56 +
57 + @Option(name = "-n", aliases = "--name", description = "TenantNetwork name", required = false,
58 + multiValued = false)
59 + String name = null;
60 +
61 + @Option(name = "-a", aliases = "--adminStateUp", description = "TenantNetwork adminStateUp is true or false",
62 + required = false, multiValued = false)
63 + boolean adminStateUp = false;
64 +
65 + @Option(name = "-s", aliases = "--state", description = "The state of TenantNetwork",
66 + required = false, multiValued = false)
67 + String state = null;
68 +
69 + @Option(name = "-d", aliases = "--shared", description = "TenantNetwork is shared or not",
70 + required = false, multiValued = false)
71 + boolean shared = false;
72 +
73 + @Option(name = "-r", aliases = "--routerExternal",
74 + description = "TenantNetwork is routerExternal or not", required = false,
75 + multiValued = false)
76 + boolean routerExternal = false;
77 +
78 + @Option(name = "-p", aliases = "--physicalNetwork", description = "The physical network of Tenant",
79 + required = false, multiValued = false)
80 + String physicalNetwork = "";
81 +
82 + @Override
83 + protected void execute() {
84 + TenantNetworkService service = get(TenantNetworkService.class);
85 + TenantNetwork network = new DefaultTenantNetwork(TenantNetworkId.networkId(id), name,
86 + adminStateUp,
87 + TenantNetwork.State.valueOf(state),
88 + shared, TenantId.tenantId(tenantID),
89 + routerExternal,
90 + TenantNetwork.Type.valueOf(type),
91 + PhysicalNetwork.physicalNetwork(physicalNetwork),
92 + SegmentationId.segmentationId(segmentationID));
93 +
94 + Set<TenantNetwork> networksSet = Sets.newHashSet();
95 + networksSet.add(network);
96 + service.updateNetworks(networksSet);
97 + }
98 +
99 +}