2 * Copyright (c) 2016, 2017 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.elan.l2gw.ha.commands;
10 import java.util.List;
11 import org.eclipse.jdt.annotation.Nullable;
12 import org.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey;
19 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
20 import org.opendaylight.yangtools.yang.binding.Identifier;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 public class SwitchesCmd extends MergeCommand<Switches, HwvtepGlobalAugmentationBuilder, HwvtepGlobalAugmentation> {
24 public SwitchesCmd() {
29 public List<Switches> getData(HwvtepGlobalAugmentation node) {
31 return node.getSwitches();
37 public void setData(HwvtepGlobalAugmentationBuilder builder, List<Switches> data) {
38 builder.setSwitches(data);
42 public InstanceIdentifier<Switches> generateId(InstanceIdentifier<Node> id, Switches node) {
43 SwitchesKey switchesKey = transform(id, node).key();
44 return id.augmentation(HwvtepGlobalAugmentation.class).child(Switches.class, switchesKey);
48 public Switches transform(InstanceIdentifier<Node> nodePath, Switches src) {
49 SwitchesBuilder builder = new SwitchesBuilder(src);
50 InstanceIdentifier<Node> psNodeIid = (InstanceIdentifier<Node>) src.getSwitchRef().getValue();
51 String psNodeId = psNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
52 String nodeId = nodePath.firstKeyOf(Node.class).getNodeId().getValue();
53 int idx = nodeId.indexOf("/physicalswitch/");
55 nodeId = nodeId.substring(0, idx);
57 idx = psNodeId.indexOf("/physicalswitch/") + "/physicalswitch/".length();
58 String switchName = psNodeId.substring(idx);
59 String dstNodeId = nodeId + "/physicalswitch/" + switchName;
61 InstanceIdentifier<Node> id2 = HwvtepHAUtil.convertToInstanceIdentifier(dstNodeId);
63 builder.setSwitchRef(new HwvtepPhysicalSwitchRef(id2));
64 builder.withKey(new SwitchesKey(new HwvtepPhysicalSwitchRef(id2)));
65 return builder.build();
69 public Identifier getKey(Switches data) {
70 InstanceIdentifier<?> id = data.getSwitchRef().getValue();
71 return id.firstKeyOf(Node.class);
75 public String getDescription() {
80 public boolean areEqual(Switches switchA, Switches switchB) {
85 public Switches withoutUuid(Switches data) {