blob: 1eb1372192a4d2d9946d8b2dc38c52d001f3cefd [file] [log] [blame]
jiangrui8143ad42015-08-12 15:26:20 +08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
jiangrui8143ad42015-08-12 15:26:20 +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.virtualport;
17
jiangrui8143ad42015-08-12 15:26:20 +080018import java.util.Map;
19import java.util.Set;
20
Ray Milkey86ad7bb2018-09-27 12:32:28 -070021import org.apache.karaf.shell.api.action.Argument;
22import org.apache.karaf.shell.api.action.Command;
23import org.apache.karaf.shell.api.action.Option;
jiangrui8143ad42015-08-12 15:26:20 +080024import org.onlab.packet.MacAddress;
25import org.onosproject.cli.AbstractShellCommand;
26import org.onosproject.net.DeviceId;
27import org.onosproject.vtnrsc.AllowedAddressPair;
28import org.onosproject.vtnrsc.BindingHostId;
29import org.onosproject.vtnrsc.DefaultVirtualPort;
30import org.onosproject.vtnrsc.FixedIp;
31import org.onosproject.vtnrsc.SecurityGroup;
32import org.onosproject.vtnrsc.TenantId;
33import org.onosproject.vtnrsc.TenantNetworkId;
34import org.onosproject.vtnrsc.VirtualPort;
35import org.onosproject.vtnrsc.VirtualPortId;
36import org.onosproject.vtnrsc.virtualport.VirtualPortService;
37
38import com.google.common.collect.Maps;
39import com.google.common.collect.Sets;
40
41/**
42 * Supports for updating a virtualPort.
43 */
44@Command(scope = "onos", name = "virtualport-update",
45 description = "Supports for updating a virtualPort.")
46public class VirtualPortUpdateCommand extends AbstractShellCommand {
47
48 @Argument(index = 0, name = "id", description = "virtualPort id.", required = true,
49 multiValued = false)
50 String id = null;
51
52 @Argument(index = 1, name = "networkId", description = "network id.", required = true,
53 multiValued = false)
54 String networkId = null;
55
56 @Argument(index = 2, name = "name", description = "virtualPort name.", required = true,
57 multiValued = false)
58 String name = null;
59
60 @Argument(index = 3, name = "tenantId", description = "tenant id.", required = true,
61 multiValued = false)
62 String tenantId = null;
63
64 @Argument(index = 4, name = "deviceId", description = "device id.", required = true,
65 multiValued = false)
66 String deviceId = null;
67
68 @Option(name = "-a", aliases = "--adminStateUp",
69 description = "administrative status of the virtualPort which is true or false.",
70 required = false, multiValued = false)
71 Boolean adminStateUp = false;
72
73 @Option(name = "-s", aliases = "--state", description = "virtualPort state.", required = false,
74 multiValued = false)
75 String state = null;
76
77 @Option(name = "-m", aliases = "--macAddress", description = "MAC address.", required = false,
78 multiValued = false)
79 String macAddress = "";
80
81 @Option(name = "-d", aliases = "--deviceOwner",
82 description = "ID of the entity that uses this " + "virtualPort.", required = false,
83 multiValued = false)
84 String deviceOwner = null;
85
86 @Option(name = "-f", aliases = "--fixedIp",
87 description = "The IP address for the port,include the IP address "
88 + "and subnet identity.", required = false, multiValued = false)
89 FixedIp fixedIp = null;
90
91 @Option(name = "-i", aliases = "--bindingHostId", description = "virtualPort bindingHostId.",
92 required = false, multiValued = false)
93 String bindingHostId = "";
94
95 @Option(name = "-t", aliases = "--bindingvnicType",
96 description = "virtualPort bindingvnicType.", required = false, multiValued = false)
97 String bindingvnicType = null;
98
99 @Option(name = "-v", aliases = "--bindingvifType", description = "virtualPort bindingvifType.",
100 required = false, multiValued = false)
101 String bindingvifType = null;
102
103 @Option(name = "-b", aliases = "--bindingvnicDetails",
104 description = "virtualPort bindingvnicDetails.", required = false, multiValued = false)
105 String bindingvnicDetails = null;
106
107 @Option(name = "-l", aliases = "--allowedAddress", description = "virtual allowedAddressPair.",
108 required = false, multiValued = false)
jiangruiac0879a2015-09-08 16:58:49 +0800109 Set<AllowedAddressPair> allowedAddressPairs = Sets.newHashSet();
jiangrui8143ad42015-08-12 15:26:20 +0800110
111 @Option(name = "-e", aliases = "--securityGroups", description = "virtualPort securityGroups.",
112 required = false, multiValued = false)
jiangruiac0879a2015-09-08 16:58:49 +0800113 Set<SecurityGroup> securityGroups = Sets.newHashSet();
jiangrui8143ad42015-08-12 15:26:20 +0800114
115 @Override
Ray Milkey86ad7bb2018-09-27 12:32:28 -0700116 protected void doExecute() {
jiangrui8143ad42015-08-12 15:26:20 +0800117 VirtualPortService service = get(VirtualPortService.class);
118 Map<String, String> strMap = Maps.newHashMap();
119 strMap.putIfAbsent("name", name);
120 strMap.putIfAbsent("deviceOwner", deviceOwner);
121 strMap.putIfAbsent("bindingvnicType", bindingvnicType);
122 strMap.putIfAbsent("bindingvifType", bindingvifType);
123 strMap.putIfAbsent("bindingvnicDetails", bindingvnicDetails);
124 VirtualPort virtualPort = new DefaultVirtualPort(VirtualPortId.portId(id),
125 TenantNetworkId.networkId(networkId),
126 false, strMap, VirtualPort.State.ACTIVE,
127 MacAddress.valueOf(macAddress),
128 TenantId.tenantId(tenantId),
129 DeviceId.deviceId(deviceId), Sets.newHashSet(fixedIp),
130 BindingHostId.bindingHostId(bindingHostId),
131 allowedAddressPairs, securityGroups);
132 Set<VirtualPort> virtualPorts = Sets.newHashSet(virtualPort);
133 service.updatePorts(virtualPorts);
134 }
135}