8ce6717373fa55ce5bec4da84d29a4002c39e032
[groupbasedpolicy.git] / neutron-mapper / src / main / java / org / opendaylight / groupbasedpolicy / neutron / mapper / infrastructure / NetworkClient.java
1 package org.opendaylight.groupbasedpolicy.neutron.mapper.infrastructure;
2
3 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
4 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
5 import org.opendaylight.groupbasedpolicy.util.IidFactory;
6 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Description;
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.EndpointGroupId;
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.Name;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.TenantId;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.EndpointGroup;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.EndpointGroup.IntraGroupPolicy;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.EndpointGroupBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.endpoint.group.ConsumerNamedSelector;
14
15 import com.google.common.base.Preconditions;
16
17 public class NetworkClient {
18
19     private static final Name NETWORK_CLIENT_EPG_NAME = new Name("NETWORK_CLIENT");
20     private static final Description NETWORK_CLIENT_EPG_DESC = new Description("Represents DHCP and DNS clients.");
21     /**
22      * ID of {@link #EPG}
23      */
24     public static final EndpointGroupId EPG_ID = new EndpointGroupId("ccc5e444-573c-11e5-885d-feff819cdc9f");
25     /**
26      * Network-client endpoint-group consuming no contract
27      */
28     public static final EndpointGroup EPG;
29
30     static {
31         EPG = createNetworkClientEpg();
32     }
33
34     private static EndpointGroup createNetworkClientEpg() {
35         return new EndpointGroupBuilder().setId(EPG_ID)
36             .setName(NETWORK_CLIENT_EPG_NAME)
37             .setIntraGroupPolicy(IntraGroupPolicy.RequireContract)
38             .setDescription(NETWORK_CLIENT_EPG_DESC)
39             .build();
40     }
41
42     /**
43      * Puts {@link #EPG} to {@link LogicalDatastoreType#CONFIGURATION}
44      * 
45      * @param tenantId location of {@link #EPG}
46      * @param wTx transaction where {@link #EPG} is written
47      */
48     public static void writeNetworkClientEntitiesToTenant(TenantId tenantId, WriteTransaction wTx) {
49         wTx.put(LogicalDatastoreType.CONFIGURATION, IidFactory.endpointGroupIid(tenantId, EPG_ID), EPG, true);
50     }
51
52     /**
53      * Puts consumer-named-selector to {@link #EPG} in {@link LogicalDatastoreType#CONFIGURATION}
54      * 
55      * @param tenantId tenantId location of {@link #EPG}
56      * @param consumerNamedSelector is added to {@link #EPG}
57      * @param wTx transaction where the given consumer-named-selector is written
58      */
59     public static void writeConsumerNamedSelector(TenantId tenantId, ConsumerNamedSelector consumerNamedSelector,
60             WriteTransaction wTx) {
61         Preconditions.checkNotNull(consumerNamedSelector);
62         wTx.put(LogicalDatastoreType.CONFIGURATION,
63                 IidFactory.consumerNamedSelectorIid(tenantId, EPG_ID, consumerNamedSelector.getName()),
64                 consumerNamedSelector, true);
65     }
66
67 }