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.opendaylight.netvirt.elan.l2gw.ha.HwvtepHAUtil;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentation;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepGlobalAugmentationBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.HwvtepPhysicalSwitchRef;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.Switches;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.ovsdb.hwvtep.rev150901.hwvtep.global.attributes.SwitchesKey;
18 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
19 import org.opendaylight.yangtools.yang.binding.Identifier;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 public class SwitchesCmd extends MergeCommand<Switches, HwvtepGlobalAugmentationBuilder, HwvtepGlobalAugmentation> {
23 public SwitchesCmd() {
27 public List<Switches> getData(HwvtepGlobalAugmentation node) {
29 return node.getSwitches();
35 public void setData(HwvtepGlobalAugmentationBuilder builder, List<Switches> data) {
36 builder.setSwitches(data);
40 public InstanceIdentifier<Switches> generateId(InstanceIdentifier<Node> id, Switches node) {
41 SwitchesKey switchesKey = transform(id, node).key();
42 return id.augmentation(HwvtepGlobalAugmentation.class).child(Switches.class, switchesKey);
46 public Switches transform(InstanceIdentifier<Node> nodePath, Switches src) {
47 SwitchesBuilder builder = new SwitchesBuilder(src);
48 InstanceIdentifier<Node> psNodeIid = (InstanceIdentifier<Node>) src.getSwitchRef().getValue();
49 String psNodeId = psNodeIid.firstKeyOf(Node.class).getNodeId().getValue();
50 String nodeId = nodePath.firstKeyOf(Node.class).getNodeId().getValue();
51 int idx = nodeId.indexOf("/physicalswitch/");
53 nodeId = nodeId.substring(0, idx);
55 idx = psNodeId.indexOf("/physicalswitch/") + "/physicalswitch/".length();
56 String switchName = psNodeId.substring(idx);
57 String dstNodeId = nodeId + "/physicalswitch/" + switchName;
59 InstanceIdentifier<Node> id2 = HwvtepHAUtil.convertToInstanceIdentifier(dstNodeId);
61 builder.setSwitchRef(new HwvtepPhysicalSwitchRef(id2));
62 builder.withKey(new SwitchesKey(new HwvtepPhysicalSwitchRef(id2)));
63 return builder.build();
67 public Identifier getKey(Switches data) {
68 InstanceIdentifier<?> id = data.getSwitchRef().getValue();
69 return id.firstKeyOf(Node.class);
73 public String getDescription() {
78 public boolean areEqual(Switches switchA, Switches switchB) {
83 public Switches withoutUuid(Switches data) {