Skip to content

Commit 1fa4f10

Browse files
committed
Merge remote-tracking branch 'origin/4.11'
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2 parents 5313c04 + f430f41 commit 1fa4f10

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider/RootCAProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ private boolean loadManagementKeyStore() {
359359
return true;
360360
}
361361
final Certificate serverCertificate = issueCertificate(Collections.singletonList(NetUtils.getHostName()),
362-
Collections.singletonList(NetUtils.getDefaultHostIp()), getCaValidityDays());
362+
NetUtils.getAllDefaultNicIps(), getCaValidityDays());
363363
if (serverCertificate == null || serverCertificate.getPrivateKey() == null) {
364364
throw new CloudRuntimeException("Failed to generate management server certificate and load management server keystore");
365365
}

utils/src/main/java/com/cloud/utils/net/NetUtils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,27 @@ public static String getDefaultHostIp() {
225225
}
226226
}
227227

228+
public static List<String> getAllDefaultNicIps() {
229+
final List<String> addrs = new ArrayList<>();
230+
final String pubNic = getDefaultEthDevice();
231+
232+
if (pubNic == null) {
233+
return addrs;
234+
}
235+
236+
NetworkInterface nic = null;
237+
try {
238+
nic = NetworkInterface.getByName(pubNic);
239+
} catch (final SocketException e) {
240+
return addrs;
241+
}
242+
243+
for (InterfaceAddress address : nic.getInterfaceAddresses()) {
244+
addrs.add(address.getAddress().getHostAddress().split("%")[0]);
245+
}
246+
return addrs;
247+
}
248+
228249
public static String getDefaultEthDevice() {
229250
if (SystemUtils.IS_OS_MAC) {
230251
final String defDev = Script.runSimpleBashScript("/sbin/route -n get default 2> /dev/null | grep interface | awk '{print $2}'");

utils/src/test/java/com/cloud/utils/net/NetUtilsTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,4 +694,9 @@ public void testIsIpv4ExpectException() {
694694
public void testIsIpv4ExpectException2() {
695695
NetUtils.isIpv4("2001:db8:300::/64");
696696
}
697+
698+
public void testAllIpsOfDefaultNic() {
699+
final String defaultHostIp = NetUtils.getDefaultHostIp();
700+
assertTrue(NetUtils.getAllDefaultNicIps().stream().anyMatch(defaultHostIp::contains));
701+
}
697702
}

0 commit comments

Comments
 (0)