Fix: make all openstack resource name optional
Change-Id: I6f4fd34ab691701ea0d6a15eb77428c9e8f4e700
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackDirectPortListCommand.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackDirectPortListCommand.java
index 6b6d129..2ffdb83 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackDirectPortListCommand.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackDirectPortListCommand.java
@@ -29,6 +29,7 @@
import static org.onosproject.cli.AbstractShellCommand.get;
import static org.onosproject.openstacknetworking.api.Constants.DIRECT;
import static org.onosproject.openstacknetworking.api.Constants.PCISLOT;
+import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getIntfNameFromPciAddress;
/**
@@ -59,13 +60,13 @@
Network osNet = service.network(port.getNetworkId());
if (port.getVifType().equals(UNBOUND)) {
print(FORMAT, port.getId(),
- osNet.getName(),
+ deriveResourceName(osNet),
port.getMacAddress(),
fixedIps.isEmpty() ? "" : fixedIps,
UNBOUND, UNBOUND);
} else {
print(FORMAT, port.getId(),
- osNet.getName(),
+ deriveResourceName(osNet),
port.getMacAddress(),
fixedIps.isEmpty() ? "" : fixedIps,
port.getProfile().containsKey(PCISLOT) ?
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackNetworkListCommand.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackNetworkListCommand.java
index 456019a..d3e9af7 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackNetworkListCommand.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackNetworkListCommand.java
@@ -30,6 +30,7 @@
import java.util.List;
import java.util.stream.Collectors;
+import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.modelEntityToJson;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.prettyJson;
@@ -47,7 +48,7 @@
protected void doExecute() {
OpenstackNetworkService service = get(OpenstackNetworkService.class);
List<Network> networks = Lists.newArrayList(service.networks());
- networks.sort(Comparator.comparing(Network::getName));
+ networks.sort(Comparator.comparing(Network::getId));
if (outputJson()) {
print("%s", json(networks));
@@ -69,7 +70,7 @@
});
print(FORMAT, net.getId(),
- net.getName(),
+ deriveResourceName(net),
service.networkType(net.getId()).toString(),
net.getProviderSegID(),
subnets.isEmpty() ? "" : subnetsString,
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackPortListCommand.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackPortListCommand.java
index 131c809..f557a1c 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackPortListCommand.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackPortListCommand.java
@@ -33,6 +33,7 @@
import java.util.List;
import java.util.stream.Collectors;
+import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.modelEntityToJson;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.prettyJson;
@@ -70,7 +71,7 @@
.map(IP::getIpAddress)
.collect(Collectors.toList());
Network osNet = service.network(port.getNetworkId());
- String netName = osNet == null ? "N/A" : osNet.getName();
+ String netName = osNet == null ? "N/A" : deriveResourceName(osNet);
print(FORMAT, port.getId(),
netName,
port.getMacAddress(),
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackRouterListCommand.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackRouterListCommand.java
index f635131..d73f4e9 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackRouterListCommand.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackRouterListCommand.java
@@ -34,6 +34,7 @@
import java.util.Objects;
import java.util.stream.Collectors;
+import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.modelEntityToJson;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.prettyJson;
@@ -55,7 +56,7 @@
@Override
protected void doExecute() {
List<Router> routers = Lists.newArrayList(routerService.routers());
- routers.sort(Comparator.comparing(Router::getName));
+ routers.sort(Comparator.comparing(Router::getId));
if (outputJson()) {
print("%s", json(routers));
@@ -80,7 +81,7 @@
routerService.routerInterfaces(router.getId()).forEach(iface -> {
internals.add(getRouterIfaceIp(iface));
});
- print(FORMAT, router.getId(), router.getName(), externals, internals);
+ print(FORMAT, router.getId(), deriveResourceName(router), externals, internals);
}
}
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSecurityGroupListCommand.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSecurityGroupListCommand.java
index de92ca3..493c485 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSecurityGroupListCommand.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSecurityGroupListCommand.java
@@ -29,7 +29,7 @@
import java.util.Comparator;
import java.util.List;
-import static org.onosproject.cli.AbstractShellCommand.get;
+import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.modelEntityToJson;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.prettyJson;
@@ -59,7 +59,7 @@
print("Hint: use --json option to see security group rules as well\n");
print(FORMAT, "ID", "Name");
for (SecurityGroup sg: service.securityGroups()) {
- print(FORMAT, sg.getId(), sg.getName());
+ print(FORMAT, sg.getId(), deriveResourceName(sg));
}
}
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSubnetListCommand.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSubnetListCommand.java
index 4a4a3c5..6fbfd5b 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSubnetListCommand.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/cli/OpenstackSubnetListCommand.java
@@ -29,6 +29,7 @@
import java.util.Comparator;
import java.util.List;
+import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.modelEntityToJson;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.prettyJson;
@@ -46,7 +47,7 @@
protected void doExecute() {
OpenstackNetworkService service = get(OpenstackNetworkService.class);
List<Subnet> subnets = Lists.newArrayList(service.subnets());
- subnets.sort(Comparator.comparing(Subnet::getName));
+ subnets.sort(Comparator.comparing(Subnet::getId));
if (outputJson()) {
print("%s", json(subnets));
@@ -56,10 +57,10 @@
for (Subnet subnet: subnets) {
Network osNet = service.network(subnet.getNetworkId());
- String netName = osNet == null ? "N/A" : osNet.getName();
+ String netName = osNet == null ? "N/A" : deriveResourceName(osNet);
print(FORMAT,
subnet.getId(),
- subnet.getName(),
+ deriveResourceName(subnet),
subnet.getCidr(),
subnet.getGateway(),
subnet.getNetworkId(),
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackNetworkStore.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackNetworkStore.java
index 474e6d1..cbae272 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackNetworkStore.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackNetworkStore.java
@@ -204,7 +204,7 @@
@Override
public void createNetwork(Network osNet) {
osNetworkStore.compute(osNet.getId(), (id, existing) -> {
- final String error = osNet.getName() + ERR_DUPLICATE;
+ final String error = osNet.getId() + ERR_DUPLICATE;
checkArgument(existing == null, error);
return osNet;
});
@@ -213,7 +213,7 @@
@Override
public void updateNetwork(Network osNet) {
osNetworkStore.compute(osNet.getId(), (id, existing) -> {
- final String error = osNet.getName() + ERR_NOT_FOUND;
+ final String error = osNet.getId() + ERR_NOT_FOUND;
checkArgument(existing != null, error);
return osNet;
});
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackRouterStore.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackRouterStore.java
index f541dfc..94ddc49 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackRouterStore.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedOpenstackRouterStore.java
@@ -161,7 +161,7 @@
@Override
public void createRouter(Router osRouter) {
osRouterStore.compute(osRouter.getId(), (id, existing) -> {
- final String error = osRouter.getName() + ERR_DUPLICATE;
+ final String error = osRouter.getId() + ERR_DUPLICATE;
checkArgument(existing == null, error);
return osRouter;
});
@@ -170,7 +170,7 @@
@Override
public void updateRouter(Router osRouter) {
osRouterStore.compute(osRouter.getId(), (id, existing) -> {
- final String error = osRouter.getName() + ERR_NOT_FOUND;
+ final String error = osRouter.getId() + ERR_NOT_FOUND;
checkArgument(existing != null, error);
return osRouter;
});
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedSecurityGroupStore.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedSecurityGroupStore.java
index 78e0e4c..ca97bb2 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedSecurityGroupStore.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/DistributedSecurityGroupStore.java
@@ -115,7 +115,7 @@
@Override
public void createSecurityGroup(SecurityGroup sg) {
osSecurityGroupStore.compute(sg.getId(), (id, existing) -> {
- final String error = sg.getName() + ERR_DUPLICATE;
+ final String error = sg.getId() + ERR_DUPLICATE;
checkArgument(existing == null, error);
return sg;
});
@@ -124,7 +124,7 @@
@Override
public void updateSecurityGroup(SecurityGroup sg) {
osSecurityGroupStore.compute(sg.getId(), (id, existing) -> {
- final String error = sg.getName() + ERR_NOT_FOUND;
+ final String error = sg.getId() + ERR_NOT_FOUND;
checkArgument(existing != null, error);
return sg;
});
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkManager.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkManager.java
index c79f12c..9aefe12 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkManager.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackNetworkManager.java
@@ -83,6 +83,7 @@
import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.LOCAL;
import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN;
import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VXLAN;
+import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getIntfNameFromPciAddress;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.vnicType;
import static org.onosproject.openstacknode.api.OpenstackNode.NodeType.GATEWAY;
@@ -211,7 +212,7 @@
return finalAugmentedNetwork;
});
- log.info(String.format(MSG_NETWORK, osNet.getName(), MSG_CREATED));
+ log.info(String.format(MSG_NETWORK, deriveResourceName(osNet), MSG_CREATED));
}
@Override
@@ -241,7 +242,7 @@
}
Network osNet = osNetworkStore.removeNetwork(netId);
if (osNet != null) {
- log.info(String.format(MSG_NETWORK, osNet.getName(), MSG_REMOVED));
+ log.info(String.format(MSG_NETWORK, deriveResourceName(osNet), MSG_REMOVED));
}
Versioned<OpenstackNetwork> augmentedNetwork = augmentedNetworkMap.remove(netId);
@@ -751,7 +752,7 @@
.filter(port -> Objects.equals(port.getDeviceId(), router.getId()))
.findAny().orElse(null);
if (exGatewayPort == null) {
- log.warn("no external gateway port for router({})", router.getName());
+ log.warn("no external gateway port for router({})", deriveResourceName(router));
return null;
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRouterManager.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRouterManager.java
index 19a831c..8280b1f 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRouterManager.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRouterManager.java
@@ -42,6 +42,7 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -110,17 +111,15 @@
public void createRouter(Router osRouter) {
checkNotNull(osRouter, ERR_NULL_ROUTER);
checkArgument(!Strings.isNullOrEmpty(osRouter.getId()), ERR_NULL_ROUTER_ID);
- checkArgument(!Strings.isNullOrEmpty(osRouter.getName()), ERR_NULL_ROUTER_NAME);
osRouterStore.createRouter(osRouter);
- log.info(String.format(MSG_ROUTER, osRouter.getName(), MSG_CREATED));
+ log.info(String.format(MSG_ROUTER, deriveResourceName(osRouter), MSG_CREATED));
}
@Override
public void updateRouter(Router osRouter) {
checkNotNull(osRouter, ERR_NULL_ROUTER);
checkArgument(!Strings.isNullOrEmpty(osRouter.getId()), ERR_NULL_ROUTER_ID);
- checkArgument(!Strings.isNullOrEmpty(osRouter.getName()), ERR_NULL_ROUTER_NAME);
osRouterStore.updateRouter(osRouter);
log.info(String.format(MSG_ROUTER, osRouter.getId(), MSG_UPDATED));
@@ -136,7 +135,7 @@
}
Router osRouter = osRouterStore.removeRouter(routerId);
if (osRouter != null) {
- log.info(String.format(MSG_ROUTER, osRouter.getName(), MSG_REMOVED));
+ log.info(String.format(MSG_ROUTER, deriveResourceName(osRouter), MSG_REMOVED));
}
}
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
index d7fa91b..b825fc6 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingHandler.java
@@ -79,6 +79,7 @@
import static org.onosproject.openstacknetworking.api.Constants.STAT_OUTBOUND_TABLE;
import static org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.ARP_MODE;
import static org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.USE_STATEFUL_SNAT;
+import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValueAsBoolean;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.tunnelPortNumByNetType;
@@ -200,7 +201,7 @@
setInternalRoutes(osRouter, osSubnet, true);
setGatewayRules(osSubnet, osRouter, true);
- log.info("Connected subnet({}) to {}", osSubnet.getCidr(), osRouter.getName());
+ log.info("Connected subnet({}) to {}", osSubnet.getCidr(), deriveResourceName(osRouter));
}
private void routerIfaceRemoved(Router osRouter, RouterInterface osRouterIface) {
@@ -221,7 +222,7 @@
setInternalRoutes(osRouter, osSubnet, false);
setGatewayRules(osSubnet, osRouter, false);
- log.info("Disconnected subnet({}) from {}", osSubnet.getCidr(), osRouter.getName());
+ log.info("Disconnected subnet({}) from {}", osSubnet.getCidr(), deriveResourceName(osRouter));
}
private void setGatewayRules(Subnet osSubnet, Router osRouter, boolean install) {
@@ -658,8 +659,7 @@
}
log.debug("Router(name:{}, ID:{}) is created",
- event.subject().getName(),
- event.subject().getId());
+ deriveResourceName(event.subject()), event.subject().getId());
routerUpdated(event.subject());
}
@@ -670,8 +670,7 @@
}
log.debug("Router(name:{}, ID:{}) is updated",
- event.subject().getName(),
- event.subject().getId());
+ deriveResourceName(event.subject()), event.subject().getId());
routerUpdated(event.subject());
}
@@ -682,8 +681,7 @@
}
log.debug("Router(name:{}, ID:{}) is removed",
- event.subject().getName(),
- event.subject().getId());
+ deriveResourceName(event.subject()), event.subject().getId());
routerRemove(event.subject());
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java
index b3c1a1f..82e4196 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackRoutingSnatHandler.java
@@ -116,6 +116,7 @@
import static org.onosproject.openstacknetworking.api.OpenstackNetwork.Type.VLAN;
import static org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.USE_STATEFUL_SNAT;
import static org.onosproject.openstacknetworking.impl.OsgiPropertyConstants.USE_STATEFUL_SNAT_DEFAULT;
+import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalGatewayIpSnatEnabled;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.externalPeerRouterFromSubnet;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValueAsBoolean;
@@ -1348,8 +1349,7 @@
}
log.debug("Router(name:{}, ID:{}) is created",
- event.subject().getName(),
- event.subject().getId());
+ deriveResourceName(event.subject()), event.subject().getId());
routerUpdated(event.subject());
}
@@ -1360,8 +1360,7 @@
}
log.debug("Router(name:{}, ID:{}) is updated",
- event.subject().getName(),
- event.subject().getId());
+ deriveResourceName(event.subject()), event.subject().getId());
routerUpdated(event.subject());
}
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java
index c30ea73..fa1341a 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/impl/OpenstackSwitchingHandler.java
@@ -77,6 +77,7 @@
import static org.onosproject.openstacknetworking.api.Constants.STAT_FLAT_OUTBOUND_TABLE;
import static org.onosproject.openstacknetworking.api.Constants.VTAG_TABLE;
import static org.onosproject.openstacknetworking.api.InstancePortEvent.Type.OPENSTACK_INSTANCE_MIGRATION_STARTED;
+import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.deriveResourceName;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.getPropertyValue;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.structurePortName;
import static org.onosproject.openstacknetworking.util.OpenstackNetworkingUtil.swapStaleLocation;
@@ -549,7 +550,7 @@
if (osNet == null || Strings.isNullOrEmpty(osNet.getProviderSegID())) {
final String error =
String.format(ERR_SET_FLOWS_VNI,
- instPort, osNet == null ? STR_NONE : osNet.getName());
+ instPort, osNet == null ? STR_NONE : deriveResourceName(osNet));
throw new IllegalStateException(error);
}
@@ -567,7 +568,7 @@
if (osNet == null || Strings.isNullOrEmpty(osNet.getProviderSegID())) {
final String error =
String.format(ERR_SET_FLOWS_VNI,
- instPort, osNet == null ? STR_NONE : osNet.getName());
+ instPort, osNet == null ? STR_NONE : deriveResourceName(osNet));
throw new IllegalStateException(error);
}
return Long.valueOf(osNet.getProviderSegID());
diff --git a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/OpenstackNetworkingUtil.java b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/OpenstackNetworkingUtil.java
index cb78448..87b8d50 100644
--- a/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/OpenstackNetworkingUtil.java
+++ b/apps/openstacknetworking/app/src/main/java/org/onosproject/openstacknetworking/util/OpenstackNetworkingUtil.java
@@ -85,6 +85,7 @@
import org.openstack4j.core.transport.Config;
import org.openstack4j.core.transport.ObjectMapperSingleton;
import org.openstack4j.model.ModelEntity;
+import org.openstack4j.model.common.BasicResource;
import org.openstack4j.model.common.Identifier;
import org.openstack4j.model.network.ExternalGateway;
import org.openstack4j.model.network.IP;
@@ -173,6 +174,9 @@
private static final String PREFIX_DEVICE_NUMBER = "s";
private static final String PREFIX_FUNCTION_NUMBER = "f";
+ private static final String PARENTHESES_START = "(";
+ private static final String PARENTHESES_END = ")";
+
// keystone endpoint related variables
private static final String DOMAIN_DEFAULT = "default";
private static final String KEYSTONE_V2 = "v2.0";
@@ -526,7 +530,7 @@
* @param osSg openstack security group
*/
public static void printSecurityGroup(SecurityGroup osSg) {
- print(SECURITY_GROUP_FORMAT, osSg.getId(), osSg.getName());
+ print(SECURITY_GROUP_FORMAT, osSg.getId(), deriveResourceName(osSg));
}
/**
@@ -537,7 +541,7 @@
public static void printNetwork(Network osNet) {
final String strNet = String.format(NETWORK_FORMAT,
osNet.getId(),
- osNet.getName(),
+ deriveResourceName(osNet),
osNet.getProviderSegID(),
osNet.getSubnets());
print(strNet);
@@ -552,7 +556,7 @@
public static void printSubnet(Subnet osSubnet,
OpenstackNetworkService osNetService) {
final Network network = osNetService.network(osSubnet.getNetworkId());
- final String netName = network == null ? NOT_AVAILABLE : network.getName();
+ final String netName = network == null ? NOT_AVAILABLE : deriveResourceName(network);
final String strSubnet = String.format(SUBNET_FORMAT,
osSubnet.getId(),
netName,
@@ -572,7 +576,7 @@
.map(IP::getIpAddress)
.collect(Collectors.toList());
final Network network = osNetService.network(osPort.getNetworkId());
- final String netName = network == null ? NOT_AVAILABLE : network.getName();
+ final String netName = network == null ? NOT_AVAILABLE : deriveResourceName(network);
final String strPort = String.format(PORT_FORMAT,
osPort.getId(),
netName,
@@ -605,7 +609,7 @@
final String strRouter = String.format(ROUTER_FORMAT,
osRouter.getId(),
- osRouter.getName(),
+ deriveResourceName(osRouter),
externals.isEmpty() ? "" : externals,
internals.isEmpty() ? "" : internals);
print(strRouter);
@@ -1160,8 +1164,7 @@
}
if (osRouter.getExternalGatewayInfo() == null) {
// this router does not have external connectivity
- log.trace("router({}) has no external gateway",
- osRouter.getName());
+ log.trace("router({}) has no external gateway", deriveResourceName(osRouter));
return null;
}
@@ -1501,6 +1504,20 @@
return getDhcpOptionValue(port, "tag:ipxe,67");
}
+ /**
+ * Returns a valid resource name.
+ *
+ * @param resource openstack basic resource object
+ * @return a valid resource name
+ */
+ public static String deriveResourceName(BasicResource resource) {
+ if (Strings.isNullOrEmpty(resource.getName())) {
+ return PARENTHESES_START + resource.getId() + PARENTHESES_END;
+ } else {
+ return resource.getName();
+ }
+ }
+
private static String getDhcpOptionValue(NeutronPort port, String optionNameStr) {
ObjectNode node = modelEntityToJson(port, NeutronPort.class);
diff --git a/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackRouterManagerTest.java b/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackRouterManagerTest.java
index b4afb75..ee84361 100644
--- a/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackRouterManagerTest.java
+++ b/apps/openstacknetworking/app/src/test/java/org/onosproject/openstacknetworking/impl/OpenstackRouterManagerTest.java
@@ -187,18 +187,6 @@
}
/**
- * Tests if updating a router with null name fails with an exception.
- */
- @Test(expected = IllegalArgumentException.class)
- public void testCreateRouterWithNullName() {
- final Router testRouter = NeutronRouter.builder()
- .id(ROUTER_ID)
- .name(null)
- .build();
- target.createRouter(testRouter);
- }
-
- /**
* Tests if creating a duplicate router fails with an exception.
*/
@Test(expected = IllegalArgumentException.class)