+ private static final Logger LOG = LoggerFactory.getLogger(NeutronUtils.class);
+
+ public static final String VNIC_TYPE_NORMAL = "normal";
+ public static final String PORT_STATUS_ACTIVE = "ACTIVE";
+ public static final String PORT_STATUS_BUILD = "BUILD";
+ public static final String PORT_STATUS_DOWN = "DOWN";
+ public static final String PORT_STATUS_ERROR = "ERROR";
+ public static final String PORT_STATUS_NOTAPPLICABLE = "N/A";
+
+ /**
+ * Create a Neutron Port status entry in the operational data store.
+ * @param uuid The uuid of the Neutron port
+ * @param portStatus value to set the status (see constants above)
+ * @param dataBroker DataBroker instance
+ * @return true if transaction submitted successfully
+ */
+ public static boolean createPortStatus(String uuid, String portStatus, DataBroker dataBroker) {
+ return writePortStatus(uuid, portStatus, dataBroker, true);
+ }
+
+ /**
+ * Update a Neutron Port status entry in the operational data store.
+ * @param uuid The uuid of the Neutron port
+ * @param portStatus value to set the status (see constants above)
+ * @param dataBroker DataBroker instance
+ * @return true if transaction submitted successfully
+ */
+ public static boolean updatePortStatus(String uuid, String portStatus, DataBroker dataBroker) {
+ return writePortStatus(uuid, portStatus, dataBroker, false);
+ }
+
+ private static boolean writePortStatus(String uuid, String portStatus, DataBroker dataBroker, boolean create) {
+ Uuid uuidObj = new Uuid(uuid);
+ PortBuilder portBuilder = new PortBuilder();
+ portBuilder.setUuid(uuidObj);
+ portBuilder.setStatus(portStatus);
+
+ InstanceIdentifier iid = InstanceIdentifier.create(Neutron.class).child(Ports.class).child(
+ Port.class, new PortKey(uuidObj));
+ SingleTransactionDataBroker tx = new SingleTransactionDataBroker(dataBroker);
+ try {
+ if (create) {
+ tx.syncWrite(LogicalDatastoreType.OPERATIONAL, iid, portBuilder.build());
+ } else {
+ tx.syncUpdate(LogicalDatastoreType.OPERATIONAL, iid, portBuilder.build());
+ }
+ } catch (TransactionCommitFailedException e) {
+ LOG.error("writePortStatus: failed neutron port status write. isCreate ? " + create, e);
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Delete a Neutron Port status entry from the operational data store.
+ * @param uuid The uuid of the Neutron port
+ * @param dataBroker DataBroker instance
+ * @return true if transaction submitted successfully
+ */
+ public static boolean deletePortStatus(String uuid, DataBroker dataBroker) {
+ Uuid uuidObj = new Uuid(uuid);
+
+ InstanceIdentifier iid = InstanceIdentifier.create(Neutron.class).child(Ports.class).child(
+ Port.class, new PortKey(uuidObj));
+ SingleTransactionDataBroker tx = new SingleTransactionDataBroker(dataBroker);
+ try {
+ tx.syncDelete(LogicalDatastoreType.OPERATIONAL, iid);
+ } catch (TransactionCommitFailedException e) {
+ LOG.error("deletePortStatus: failed neutron port status delete", e);
+ return false;
+ }
+
+ return true;
+ }