File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
plugins/ca/root-ca/src/main/java/org/apache/cloudstack/ca/provider
main/java/com/cloud/utils/net
test/java/com/cloud/utils/net Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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}'" );
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments