Search in sources :

Example 1 with InterfaceNameMacAddressKey

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();
}
Also used : InterfaceNameMacAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710._interface.name.mac.addresses.InterfaceNameMacAddress) InterfaceNameMacAddressKey(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710._interface.name.mac.addresses.InterfaceNameMacAddressKey) InterfaceNameMacAddressBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710._interface.name.mac.addresses.InterfaceNameMacAddressBuilder) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)1 InterfaceNameMacAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710._interface.name.mac.addresses.InterfaceNameMacAddress)1 InterfaceNameMacAddressBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710._interface.name.mac.addresses.InterfaceNameMacAddressBuilder)1 InterfaceNameMacAddressKey (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dhcpservice.api.rev150710._interface.name.mac.addresses.InterfaceNameMacAddressKey)1