jiangrui | 7d2d7fb | 2015-08-11 18:43:57 +0800 | [diff] [blame^] | 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 | } |