blob: fd218e03357945d3f6e642cd97f0bd961b2ee167 [file] [log] [blame]
jiangrui8143ad42015-08-12 15:26:20 +08001/*
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 */
16package org.onosproject.vtnrsc.cli.virtualport;
17
18import java.util.Collection;
19import java.util.Map;
20import java.util.Set;
21
22import org.apache.karaf.shell.commands.Argument;
23import org.apache.karaf.shell.commands.Command;
24import org.apache.karaf.shell.commands.Option;
25import 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 */
45@Command(scope = "onos", name = "virtualport-update",
46 description = "Supports for updating a virtualPort.")
47public class VirtualPortUpdateCommand extends AbstractShellCommand {
48
49 @Argument(index = 0, name = "id", description = "virtualPort id.", required = true,
50 multiValued = false)
51 String id = null;
52
53 @Argument(index = 1, name = "networkId", description = "network id.", required = true,
54 multiValued = false)
55 String networkId = null;
56
57 @Argument(index = 2, name = "name", description = "virtualPort name.", required = true,
58 multiValued = false)
59 String name = null;
60
61 @Argument(index = 3, name = "tenantId", description = "tenant id.", required = true,
62 multiValued = false)
63 String tenantId = null;
64
65 @Argument(index = 4, name = "deviceId", description = "device id.", required = true,
66 multiValued = false)
67 String deviceId = null;
68
69 @Option(name = "-a", aliases = "--adminStateUp",
70 description = "administrative status of the virtualPort which is true or false.",
71 required = false, multiValued = false)
72 Boolean adminStateUp = false;
73
74 @Option(name = "-s", aliases = "--state", description = "virtualPort state.", required = false,
75 multiValued = false)
76 String state = null;
77
78 @Option(name = "-m", aliases = "--macAddress", description = "MAC address.", required = false,
79 multiValued = false)
80 String macAddress = "";
81
82 @Option(name = "-d", aliases = "--deviceOwner",
83 description = "ID of the entity that uses this " + "virtualPort.", required = false,
84 multiValued = false)
85 String deviceOwner = null;
86
87 @Option(name = "-f", aliases = "--fixedIp",
88 description = "The IP address for the port,include the IP address "
89 + "and subnet identity.", required = false, multiValued = false)
90 FixedIp fixedIp = null;
91
92 @Option(name = "-i", aliases = "--bindingHostId", description = "virtualPort bindingHostId.",
93 required = false, multiValued = false)
94 String bindingHostId = "";
95
96 @Option(name = "-t", aliases = "--bindingvnicType",
97 description = "virtualPort bindingvnicType.", required = false, multiValued = false)
98 String bindingvnicType = null;
99
100 @Option(name = "-v", aliases = "--bindingvifType", description = "virtualPort bindingvifType.",
101 required = false, multiValued = false)
102 String bindingvifType = null;
103
104 @Option(name = "-b", aliases = "--bindingvnicDetails",
105 description = "virtualPort bindingvnicDetails.", required = false, multiValued = false)
106 String bindingvnicDetails = null;
107
108 @Option(name = "-l", aliases = "--allowedAddress", description = "virtual allowedAddressPair.",
109 required = false, multiValued = false)
110 Collection<AllowedAddressPair> allowedAddressPairs = Sets.newHashSet();
111
112 @Option(name = "-e", aliases = "--securityGroups", description = "virtualPort securityGroups.",
113 required = false, multiValued = false)
114 Collection<SecurityGroup> securityGroups = Sets.newHashSet();
115
116 @Override
117 protected void execute() {
118 VirtualPortService service = get(VirtualPortService.class);
119 Map<String, String> strMap = Maps.newHashMap();
120 strMap.putIfAbsent("name", name);
121 strMap.putIfAbsent("deviceOwner", deviceOwner);
122 strMap.putIfAbsent("bindingvnicType", bindingvnicType);
123 strMap.putIfAbsent("bindingvifType", bindingvifType);
124 strMap.putIfAbsent("bindingvnicDetails", bindingvnicDetails);
125 VirtualPort virtualPort = new DefaultVirtualPort(VirtualPortId.portId(id),
126 TenantNetworkId.networkId(networkId),
127 false, strMap, VirtualPort.State.ACTIVE,
128 MacAddress.valueOf(macAddress),
129 TenantId.tenantId(tenantId),
130 DeviceId.deviceId(deviceId), Sets.newHashSet(fixedIp),
131 BindingHostId.bindingHostId(bindingHostId),
132 allowedAddressPairs, securityGroups);
133 Set<VirtualPort> virtualPorts = Sets.newHashSet(virtualPort);
134 service.updatePorts(virtualPorts);
135 }
136}