use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710._interface.name.mac.addresses.InterfaceNameMacAddressKey in project netvirt by opendaylight.
the class DhcpServiceUtils method getAndUpdateVmMacAddress.
@Nullable
public static String getAndUpdateVmMacAddress(ReadWriteTransaction tx, String interfaceName, DhcpManager dhcpManager) throws ReadFailedException {
InstanceIdentifier<InterfaceNameMacAddress> instanceIdentifier = InstanceIdentifier.builder(InterfaceNameMacAddresses.class).child(InterfaceNameMacAddress.class, new InterfaceNameMacAddressKey(interfaceName)).build();
Optional<InterfaceNameMacAddress> existingEntry = tx.read(LogicalDatastoreType.OPERATIONAL, instanceIdentifier).checkedGet();
if (!existingEntry.isPresent()) {
LOG.trace("Entry for interface {} missing in InterfaceNameVmMacAddress map", interfaceName);
String vmMacAddress = getNeutronMacAddress(interfaceName, dhcpManager);
if (vmMacAddress == null || vmMacAddress.isEmpty()) {
return null;
}
LOG.trace("Updating InterfaceNameVmMacAddress map with {}, {}", interfaceName, vmMacAddress);
InterfaceNameMacAddress interfaceNameMacAddress = new InterfaceNameMacAddressBuilder().setKey(new InterfaceNameMacAddressKey(interfaceName)).setInterfaceName(interfaceName).setMacAddress(vmMacAddress).build();
tx.merge(LogicalDatastoreType.OPERATIONAL, instanceIdentifier, interfaceNameMacAddress, WriteTransaction.CREATE_MISSING_PARENTS);
return vmMacAddress;
}
return existingEntry.get().getMacAddress();
}
Aggregations