2 * Copyright (c) 2014, 2015 Red Hat, Inc. 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.neutron.transcriber;
10 import java.util.List;
11 import javax.inject.Inject;
12 import javax.inject.Singleton;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.neutron.spi.INeutronLoadBalancerCRUD;
15 import org.opendaylight.neutron.spi.NeutronLoadBalancer;
16 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddressBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.Loadbalancers;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.loadbalancers.Loadbalancer;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.loadbalancers.LoadbalancerBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.lbaasv2.rev150712.lbaas.attributes.loadbalancers.LoadbalancerKey;
21 import org.ops4j.pax.cdi.api.OsgiServiceProvider;
24 @OsgiServiceProvider(classes = INeutronLoadBalancerCRUD.class)
25 public final class NeutronLoadBalancerInterface
26 extends AbstractNeutronInterface<Loadbalancer, Loadbalancers, LoadbalancerKey, NeutronLoadBalancer>
27 implements INeutronLoadBalancerCRUD {
30 public NeutronLoadBalancerInterface(DataBroker db) {
31 super(LoadbalancerBuilder.class, db);
35 protected List<Loadbalancer> getDataObjectList(Loadbalancers lbs) {
36 return lbs.getLoadbalancer();
40 protected NeutronLoadBalancer fromMd(Loadbalancer loadBalancer) {
41 final NeutronLoadBalancer answer = new NeutronLoadBalancer();
42 fromMdAdminAttributes(loadBalancer, answer);
43 if (loadBalancer.getVipAddress() != null) {
44 answer.setLoadBalancerVipAddress(String.valueOf(loadBalancer.getVipAddress().stringValue()));
46 if (loadBalancer.getVipSubnetId() != null) {
47 answer.setLoadBalancerVipSubnetID(loadBalancer.getVipSubnetId().getValue());
53 protected Loadbalancer toMd(NeutronLoadBalancer loadBalancer) {
54 final LoadbalancerBuilder loadBalancerBuilder = new LoadbalancerBuilder();
55 toMdAdminAttributes(loadBalancer, loadBalancerBuilder);
56 if (loadBalancer.getLoadBalancerVipAddress() != null) {
57 loadBalancerBuilder.setVipAddress(IpAddressBuilder.getDefaultInstance(
58 loadBalancer.getLoadBalancerVipAddress()));
60 if (loadBalancer.getLoadBalancerVipSubnetID() != null) {
61 loadBalancerBuilder.setVipSubnetId(toUuid(loadBalancer.getLoadBalancerVipSubnetID()));
63 return loadBalancerBuilder.build();