3 === How to add new API support
4 OpenStack Neutron is a moving target. It is continuously adding new features
5 as new rest APIs. Here is a basic step to add new API support:
7 In the Neutron Northbound project:
9 * Add new YANG model for it under `neutron/model/src/main/yang` and
11 * Add northbound API for it, and neutron-spi
12 ** Implement `Neutron<New API>Request.java` and `Neutron<New API>Norhtbound.java`
14 `neutron/northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/`
15 ** Implement `INeutron<New API>CRUD.java` and new data structure if any under
16 `neutron/neutron-spi/src/main/java/org/opendaylight/neutron/spi/`
18 `neutron/neutron-spi/src/main/java/org/opendaylight/neutron/spi/NeutronCRUDInterfaces.java`
19 to wire new CRUD interface
20 ** Add unit tests, `Neutron<New structure>JAXBTest.java` under
21 `neutron/neutron-spi/src/test/java/org/opendaylight/neutron/spi/`
23 `neutron/northbound-api/src/main/java/org/opendaylight/neutron/northbound/api/NeutronNorthboundRSApplication.java`
24 to wire new northbound api to `RSApplication`
25 * Add transcriber, `Neutron<New API>Interface.java` under
26 `transcriber/src/main/java/org/opendaylight/neutron/transcriber/`
28 `transcriber/src/main/java/org/opendaylight/neutron/transcriber/NeutronTranscriberProvider.java`
29 to wire a new transcriber
30 ** Add integration tests `Neutron<New API>Tests.java`
31 under `integration/test/src/test/java/org/opendaylight/neutron/e2etest/`
32 ** update `integration/test/src/test/java/org/opendaylight/neutron/e2etest/ITNeutronE2E.java`
33 to run a newly added tests.
35 In OpenStack networking-odl
37 * Add new driver (or plugin) for new API with tests.
39 In a southbound Neutron Provider
41 * implement actual backend to realize those new API by listening related YANG
45 === How to write transcriber
47 For each Neutron data object, there is an `Neutron*Interface` defined within
48 the transcriber artifact that will write that object to the MD-SAL
49 configuration datastore.
51 All `Neutron*Interface` extend `AbstractNeutronInterface`, in which two methods
54 * one takes the Neutron object as input, and will create a data object from it.
55 * one takes an uuid as input, and will create a data object containing the uuid.
58 protected abstract T toMd(S neutronObject);
59 protected abstract T toMd(String uuid);
62 In addition the `AbstractNeutronInterface` class provides several other
63 helper methods (`addMd`, `updateMd`, `removeMd`), which handle the actual
64 writing to the configuration datastore.
66 ==== The semantics of the `toMD()` methods
67 Each of the Neutron YANG models defines structures containing data.
68 Further each YANG-modeled structure has it own builder.
69 A particular `toMD()` method instantiates an instance of the correct
70 builder, fills in the properties of the builder from the corresponding
71 values of the Neutron object and then creates the YANG-modeled structures
72 via the `build()` method.
74 As an example, one of the `toMD` code for Neutron Networks is
78 protected Network toMd(NeutronNetwork network) {
79 NetworkBuilder networkBuilder = new NetworkBuilder();
80 networkBuilder.setAdminStateUp(network.getAdminStateUp());
81 if (network.getNetworkName() != null) {
82 networkBuilder.setName(network.getNetworkName());
84 if (network.getShared() != null) {
85 networkBuilder.setShared(network.getShared());
87 if (network.getStatus() != null) {
88 networkBuilder.setStatus(network.getStatus());
90 if (network.getSubnets() != null) {
91 List<Uuid> subnets = new ArrayList<Uuid>();
92 for( String subnet : network.getSubnets()) {
93 subnets.add(toUuid(subnet));
95 networkBuilder.setSubnets(subnets);
97 if (network.getTenantID() != null) {
98 networkBuilder.setTenantId(toUuid(network.getTenantID()));
100 if (network.getNetworkUUID() != null) {
101 networkBuilder.setUuid(toUuid(network.getNetworkUUID()));
103 logger.warn("Attempting to write neutron network without UUID");
105 return networkBuilder.build();