Specify the openstack endpoint using hostname when mgmtIp is empty
Change-Id: I82143d368f5902d8e142c5a450b23ad30bf9c4f4
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSyncStateCommand.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSyncStateCommand.java
index b1e57be..29823ae 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSyncStateCommand.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSyncStateCommand.java
@@ -243,7 +243,13 @@
StringBuilder endpointSb = new StringBuilder();
endpointSb.append(auth.protocol().name().toLowerCase());
endpointSb.append("://");
- endpointSb.append(node.managementIp());
+
+ if (node.managementIp() == null) {
+ endpointSb.append(node.hostname());
+ } else {
+ endpointSb.append(node.managementIp());
+ }
+
endpointSb.append(":");
endpointSb.append(auth.port());
endpointSb.append("/");
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackNodeCodec.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackNodeCodec.java
index 1d30bf6..cf7a150 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackNodeCodec.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/codec/OpenstackNodeCodec.java
@@ -66,7 +66,6 @@
ObjectNode result = context.mapper().createObjectNode()
.put(HOST_NAME, node.hostname())
.put(TYPE, node.type().name())
- .put(MANAGEMENT_IP, node.managementIp().toString())
.put(STATE, node.state().name());
OpenstackNode.NodeType type = node.type();
@@ -76,7 +75,12 @@
}
if (type != OpenstackNode.NodeType.CONTROLLER) {
+ result.put(MANAGEMENT_IP, node.managementIp().toString());
result.put(INTEGRATION_BRIDGE, node.intgBridge().toString());
+ } else {
+ if (node.managementIp() != null) {
+ result.put(MANAGEMENT_IP, node.managementIp().toString());
+ }
}
if (node.vlanIntf() != null) {
@@ -116,13 +120,10 @@
HOST_NAME + MISSING_MESSAGE);
String type = nullIsIllegal(json.get(TYPE).asText(),
TYPE + MISSING_MESSAGE);
- String mIp = nullIsIllegal(json.get(MANAGEMENT_IP).asText(),
- MANAGEMENT_IP + MISSING_MESSAGE);
DefaultOpenstackNode.Builder nodeBuilder = DefaultOpenstackNode.builder()
.hostname(hostname)
.type(OpenstackNode.NodeType.valueOf(type))
- .managementIp(IpAddress.valueOf(mIp))
.state(NodeState.INIT);
if (type.equals(GATEWAY)) {
@@ -133,6 +134,14 @@
String iBridge = nullIsIllegal(json.get(INTEGRATION_BRIDGE).asText(),
INTEGRATION_BRIDGE + MISSING_MESSAGE);
nodeBuilder.intgBridge(DeviceId.deviceId(iBridge));
+
+ String mIp = nullIsIllegal(json.get(MANAGEMENT_IP).asText(),
+ MANAGEMENT_IP + MISSING_MESSAGE);
+ nodeBuilder.managementIp(IpAddress.valueOf(mIp));
+ } else {
+ if (json.get(MANAGEMENT_IP) != null) {
+ nodeBuilder.managementIp(IpAddress.valueOf(json.get(MANAGEMENT_IP).asText()));
+ }
}
if (json.get(VLAN_INTF_NAME) != null) {
nodeBuilder.vlanIntf(json.get(VLAN_INTF_NAME).asText());
diff --git a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNode.java b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNode.java
index f05d58b..aad1fbb 100644
--- a/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNode.java
+++ b/apps/openstacknode/app/src/main/java/org/onosproject/openstacknode/impl/DefaultOpenstackNode.java
@@ -372,11 +372,11 @@
public DefaultOpenstackNode build() {
checkArgument(hostname != null, NOT_NULL_MSG, "hostname");
checkArgument(type != null, NOT_NULL_MSG, "type");
-
- checkArgument(managementIp != null, NOT_NULL_MSG, "management IP");
checkArgument(state != null, NOT_NULL_MSG, "state");
if (type != NodeType.CONTROLLER) {
+ checkArgument(managementIp != null, NOT_NULL_MSG, "management IP");
+
checkArgument(intgBridge != null, NOT_NULL_MSG, "integration bridge");
if (dataIp == null && Strings.isNullOrEmpty(vlanIntf)) {