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