You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by "weizhouapache (via GitHub)" <gi...@apache.org> on 2026/10/14 13:19:38 UTC

[PR] utils: add RbdUtils [cloudstack]

weizhouapache opened a new pull request, #14402:
URL: https://github.com/apache/cloudstack/pull/14402

   ### Description
   
   This PR...
   <!--- Describe your changes in DETAIL - And how has behaviour functionally changed. -->
   
   <!-- For new features, provide link to FS, dev ML discussion etc. -->
   <!-- In case of bug fix, the expected and actual behaviours, steps to reproduce. -->
   
   <!-- When "Fixes: #<id>" is specified, the issue/PR will automatically be closed when this PR gets merged -->
   <!-- For addressing multiple issues/PRs, use multiple "Fixes: #<id>" -->
   <!-- Fixes: # -->
   
   <!--- ******************************************************************************* -->
   <!--- NOTE: AUTOMATION USES THE DESCRIPTIONS TO SET LABELS AND PRODUCE DOCUMENTATION. -->
   <!--- PLEASE PUT AN 'X' in only **ONE** box -->
   <!--- ******************************************************************************* -->
   
   ### Types of changes
   
   - [ ] Breaking change (fix or feature that would cause existing functionality to change)
   - [ ] New feature (non-breaking change which adds functionality)
   - [ ] Bug fix (non-breaking change which fixes an issue)
   - [ ] Enhancement (improves an existing feature and functionality)
   - [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
   - [ ] Build/CI
   - [ ] Test (unit or integration test code)
   
   ### Feature/Enhancement Scale or Bug Severity
   
   #### Feature/Enhancement Scale
   
   - [ ] Major
   - [ ] Minor
   
   #### Bug Severity
   
   - [ ] BLOCKER
   - [ ] Critical
   - [ ] Major
   - [ ] Minor
   - [ ] Trivial
   
   ### Screenshots (if appropriate):
   
   ### How Has This Been Tested?
   
   <!-- Please describe in detail how you tested your changes. -->
   <!-- Include details of your testing environment, and the tests you ran to -->
   
   #### How did you try to break this feature and the system with this change?
   
   <!-- see how your change affects other areas of the code, etc. -->
   
   <!-- Please read the [CONTRIBUTING](https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md) document -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] utils,kvm: build every Ceph monitor list with RbdUtils [cloudstack]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #14402:
URL: https://github.com/apache/cloudstack/pull/14402#issuecomment-6169465418

   ## [Codecov](https://app.codecov.io/gh/apache/cloudstack/pull/14402?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 3.69%. Comparing base ([`a945a7c`](https://app.codecov.io/gh/apache/cloudstack/commit/a945a7c203e95ce427b9e9954e971a3d3c9967b3?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`1f3f501`](https://app.codecov.io/gh/apache/cloudstack/commit/1f3f501861b40ecf4ab148e152b4f75ed2a71c40?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   > :exclamation:  There is a different number of reports uploaded between BASE (a945a7c) and HEAD (1f3f501). Click for more details.
   > 
   > <details><summary>HEAD has 1 upload less than BASE</summary>
   >
   >| Flag | BASE (a945a7c) | HEAD (1f3f501) |
   >|------|------|------|
   >|unittests|1|0|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@              Coverage Diff              @@
   ##               main   #14402       +/-   ##
   =============================================
   - Coverage     20.21%    3.69%   -16.53%     
   =============================================
     Files          6426      491     -5935     
     Lines        580181    42220   -537961     
     Branches      71033     7974    -63059     
   =============================================
   - Hits         117292     1558   -115734     
   + Misses       450174    40436   -409738     
   + Partials      12715      226    -12489     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/cloudstack/pull/14402/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [uitests](https://app.codecov.io/gh/apache/cloudstack/pull/14402/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `3.69% <ø> (ø)` | |
   | [unittests](https://app.codecov.io/gh/apache/cloudstack/pull/14402/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/cloudstack/pull/14402?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] utils,kvm: build every Ceph monitor list with RbdUtils [cloudstack]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #14402:
URL: https://github.com/apache/cloudstack/pull/14402#discussion_r4281792031


##########
utils/src/main/java/com/cloud/utils/RbdUtils.java:
##########
@@ -0,0 +1,78 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+
+public class RbdUtils {
+
+    private RbdUtils() {
+    }
+
+    /**
+     * Returns the Ceph monitors as expected by "--mon-host": the comma-separated monitors of the pool, trimmed
+     * and without empty entries. If the pool has a monitor port, it is added to each monitor which has none yet.
+     *
+     * @param sourceHost the comma-separated monitors, IPv4 or IPv6 addresses or host names
+     * @param sourcePort the port of the monitors, or 0 (or less) if the pool has none
+     */
+    public static String getRbdMonitors(String sourceHost, int sourcePort) {
+        List<String> monitors = new ArrayList<>();
+        for (String monitor : sourceHost.split(",")) {
+            monitor = monitor.trim();
+            if (monitor.isEmpty()) {
+                continue;
+            }
+            monitors.add(sourcePort > 0 ? addPortToRbdMonitor(monitor, sourcePort) : monitor);
+        }
+        return String.join(",", monitors);
+    }
+
+    public static String addPortToRbdMonitor(String monitor, int port) {
+        if (monitor.startsWith("[")) {
+            // IPv6 address in square brackets, which has a port if followed by ":<port>"
+            return monitor.contains("]:") ? monitor : monitor + ":" + port;
+        }
+        int colons = StringUtils.countMatches(monitor, ":");
+        if (colons == 0) {
+            return monitor + ":" + port;
+        }
+        if (colons == 1) {
+            // IPv4 address or host name, with a port
+            return monitor;
+        }
+        // IPv6 address without square brackets, so without a port
+        return "[" + monitor + "]:" + port;
+    }
+
+    /**
+     * The monitor list as the {@code rbd:} option string of a disk needs it: ':' separates the
+     * options of that string and ';' its monitors, so both are escaped inside the list, as is
+     * every ':' of an IPv6 address.
+     */
+    public static String composeOptionForMonHosts(String monHost, int monPort) {
+        List<String> hosts = new ArrayList<>();
+        for (String monitor : getRbdMonitors(monHost, monPort).split(",")) {
+            hosts.add(monitor.replace(":", "\\:"));

Review Comment:
   `composeOptionForMonHosts` escapes `:` in each monitor and uses an escaped `\;` as the join delimiter, but it does not escape any literal `;` characters that may already be present in `monHost` entries. This contradicts the method Javadoc (“';' … escaped inside the list”) and can produce an unparseable `rbd:` option string if a monitor token contains `;`. Consider escaping `;` inside each monitor token as well (or adjusting the Javadoc to reflect actual behavior).



##########
utils/src/main/java/com/cloud/utils/RbdUtils.java:
##########
@@ -0,0 +1,78 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+
+public class RbdUtils {
+
+    private RbdUtils() {
+    }
+
+    /**
+     * Returns the Ceph monitors as expected by "--mon-host": the comma-separated monitors of the pool, trimmed
+     * and without empty entries. If the pool has a monitor port, it is added to each monitor which has none yet.
+     *
+     * @param sourceHost the comma-separated monitors, IPv4 or IPv6 addresses or host names
+     * @param sourcePort the port of the monitors, or 0 (or less) if the pool has none
+     */
+    public static String getRbdMonitors(String sourceHost, int sourcePort) {
+        List<String> monitors = new ArrayList<>();
+        for (String monitor : sourceHost.split(",")) {
+            monitor = monitor.trim();
+            if (monitor.isEmpty()) {
+                continue;
+            }
+            monitors.add(sourcePort > 0 ? addPortToRbdMonitor(monitor, sourcePort) : monitor);
+        }
+        return String.join(",", monitors);
+    }
+
+    public static String addPortToRbdMonitor(String monitor, int port) {
+        if (monitor.startsWith("[")) {
+            // IPv6 address in square brackets, which has a port if followed by ":<port>"
+            return monitor.contains("]:") ? monitor : monitor + ":" + port;
+        }
+        int colons = StringUtils.countMatches(monitor, ":");
+        if (colons == 0) {
+            return monitor + ":" + port;
+        }
+        if (colons == 1) {
+            // IPv4 address or host name, with a port
+            return monitor;
+        }
+        // IPv6 address without square brackets, so without a port
+        return "[" + monitor + "]:" + port;
+    }

Review Comment:
   `addPortToRbdMonitor` is a public API but has no Javadoc describing accepted input formats (e.g., bracketed IPv6, unbracketed IPv6, host:port) and the key heuristic used (colon counting). Adding Javadoc here would make the behavior/contracts clearer for future callers and reduce chances of misuse.



##########
utils/src/test/java/com/cloud/utils/RbdUtilsTest.java:
##########
@@ -0,0 +1,143 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class RbdUtilsTest {
+
+    @Test
+    public void testRbdMonitorsWithoutPort() {
+        assertEquals("10.0.0.1", RbdUtils.getRbdMonitors("10.0.0.1", 0));
+        assertEquals("10.0.0.1,10.0.0.2,10.0.0.3", RbdUtils.getRbdMonitors("10.0.0.1,10.0.0.2,10.0.0.3", 0));
+        assertEquals("fd00::1,fd00::2", RbdUtils.getRbdMonitors("fd00::1,fd00::2", 0));
+    }
+
+    @Test
+    public void testRbdMonitorsIpv4WithPort() {
+        assertEquals("10.0.0.1:6789", RbdUtils.getRbdMonitors("10.0.0.1", 6789));
+        assertEquals("10.0.0.1:3300,10.0.0.2:3300,10.0.0.3:3300", RbdUtils.getRbdMonitors("10.0.0.1,10.0.0.2,10.0.0.3", 3300));
+    }
+
+    @Test
+    public void testRbdMonitorsIpv6WithPort() {
+        assertEquals("[fd00::1]:3300", RbdUtils.getRbdMonitors("fd00::1", 3300));
+        assertEquals("[fd00::1]:3300,[fd00::2]:3300", RbdUtils.getRbdMonitors("fd00::1,fd00::2", 3300));
+        // already enclosed in square brackets
+        assertEquals("[fd00::1]:3300,[fd00::2]:3300", RbdUtils.getRbdMonitors("[fd00::1],[fd00::2]", 3300));
+    }
+
+    @Test
+    public void testRbdMonitorsMixedIpv4AndIpv6WithPort() {
+        assertEquals("10.0.0.1:3300,[fd00::1]:3300,[fd00::2]:3300,mon4.example.com:3300",
+                RbdUtils.getRbdMonitors("10.0.0.1, fd00::1,[fd00::2] ,mon4.example.com", 3300));
+    }
+
+    @Test
+    public void testRbdMonitorsMultipleIpv4AndIpv6WithoutPort() {
+        // no port: the default Ceph port is used, so the monitors are passed as they are
+        assertEquals("[fd00::1],[fd00::2],[fd00::3]", RbdUtils.getRbdMonitors("[fd00::1],[fd00::2],[fd00::3]", 0));
+        assertEquals("10.0.0.1,10.0.0.2,fd00::1,[fd00::2]", RbdUtils.getRbdMonitors("10.0.0.1,10.0.0.2,fd00::1,[fd00::2]", 0));
+        assertEquals("10.0.0.1,fd00::1", RbdUtils.getRbdMonitors("10.0.0.1,fd00::1", -1));
+    }
+
+    @Test
+    public void testRbdMonitorsMultipleIpv4AndIpv6WithPort() {
+        assertEquals("10.0.0.1:6789,10.0.0.2:6789,[fd00::1]:6789,[fd00::2]:6789",
+                RbdUtils.getRbdMonitors("10.0.0.1,10.0.0.2,fd00::1,[fd00::2]", 6789));
+        assertEquals("[fd00::1]:6789,10.0.0.1:6789,[fd00::2]:6789,10.0.0.2:6789",
+                RbdUtils.getRbdMonitors("fd00::1,10.0.0.1,[fd00::2],10.0.0.2", 6789));
+    }
+
+    @Test
+    public void testRbdMonitorsAreTrimmedAndEmptyEntriesSkipped() {
+        assertEquals("10.0.0.1,10.0.0.2,fd00::1", RbdUtils.getRbdMonitors(" 10.0.0.1, 10.0.0.2,,fd00::1 ,", 0));
+        assertEquals("10.0.0.1:6789,10.0.0.2:6789,[fd00::1]:6789", RbdUtils.getRbdMonitors(" 10.0.0.1, 10.0.0.2,,fd00::1 ,", 6789));
+    }
+
+    @Test
+    public void testRbdMonitorsWhichHaveAPortAlready() {
+        // the monitors keep their port, with or without a port of the pool
+        String withPorts = "10.0.0.1:6789,mon.example.com:3300,[fd00::1]:6789";
+        assertEquals(withPorts, RbdUtils.getRbdMonitors(withPorts, 0));
+        assertEquals(withPorts, RbdUtils.getRbdMonitors(withPorts, 6789));
+        assertEquals(withPorts, RbdUtils.getRbdMonitors(withPorts, 3300));
+    }
+
+    @Test
+    public void testRbdMonitorsWithAndWithoutAPortAreMixed() {
+        assertEquals("10.0.0.1:6789,10.0.0.2:3300,mon.example.com:3300,[fd00::1]:3300,[fd00::2]:6789,[fd00::3]:3300",
+                RbdUtils.getRbdMonitors("10.0.0.1:6789,10.0.0.2,mon.example.com,fd00::1,[fd00::2]:6789,[fd00::3]", 3300));
+    }
+
+    @Test
+    public void testAddPortToRbdMonitor() {
+        assertEquals("10.0.0.1:6789", RbdUtils.addPortToRbdMonitor("10.0.0.1", 6789));
+        assertEquals("10.0.0.1:3300", RbdUtils.addPortToRbdMonitor("10.0.0.1:3300", 6789));
+        assertEquals("mon.example.com:6789", RbdUtils.addPortToRbdMonitor("mon.example.com", 6789));
+        assertEquals("[fd00::1]:6789", RbdUtils.addPortToRbdMonitor("fd00::1", 6789));
+        assertEquals("[fd00::1]:6789", RbdUtils.addPortToRbdMonitor("[fd00::1]", 6789));
+        assertEquals("[fd00::1]:3300", RbdUtils.addPortToRbdMonitor("[fd00::1]:3300", 6789));
+    }
+
+    @Test
+    public void testComposeOptionForMonHostsEscapesThePortSeparator() {
+        // ':' separates the options of an rbd: string, so the one before the port is escaped.
+        assertEquals("ceph-monitor\\:8000", RbdUtils.composeOptionForMonHosts("ceph-monitor", 8000));
+    }
+
+    @Test
+    public void testComposeOptionForMonHostsJoinsMonitorsWithAnEscapedSemicolon() {
+        assertEquals("mon1\\:3300\\;mon2\\:3300\\;mon3\\:3300",
+                RbdUtils.composeOptionForMonHosts("mon1,mon2,mon3", 3300));
+    }
+
+    @Test
+    public void testComposeOptionForMonHostsEscapesEveryColonOfAnIpv6Monitor() {
+        // Without this the address' own colons would read as option separators.
+        assertEquals("[fc00\\:1234\\:\\:1]\\:3300",
+                RbdUtils.composeOptionForMonHosts("[fc00:1234::1]", 3300));
+    }
+
+    @Test
+    public void testComposeOptionForMonHostsWithoutAPortLeavesTheMonitorAlone() {
+        assertEquals("ceph-monitor", RbdUtils.composeOptionForMonHosts("ceph-monitor", 0));

Review Comment:
   There’s test coverage for “no port” with an IPv4/hostname monitor, but not for a bare IPv6 monitor with `monPort == 0`. Since `composeOptionForMonHosts` now escapes colons for any monitor, adding a test like `composeOptionForMonHosts("fd00::1", 0)` would lock in the intended behavior and prevent regressions for IPv6 pools using the default port.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] utils,kvm: build every Ceph monitor list with RbdUtils [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #14402:
URL: https://github.com/apache/cloudstack/pull/14402#issuecomment-6169438687

   @weizhouapache a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] utils,kvm: build every Ceph monitor list with RbdUtils [cloudstack]

Posted by "weizhouapache (via GitHub)" <gi...@apache.org>.
weizhouapache commented on code in PR #14402:
URL: https://github.com/apache/cloudstack/pull/14402#discussion_r4282029333


##########
utils/src/main/java/com/cloud/utils/RbdUtils.java:
##########
@@ -0,0 +1,78 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.utils;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang3.StringUtils;
+
+public class RbdUtils {
+
+    private RbdUtils() {
+    }
+
+    /**
+     * Returns the Ceph monitors as expected by "--mon-host": the comma-separated monitors of the pool, trimmed
+     * and without empty entries. If the pool has a monitor port, it is added to each monitor which has none yet.
+     *
+     * @param sourceHost the comma-separated monitors, IPv4 or IPv6 addresses or host names
+     * @param sourcePort the port of the monitors, or 0 (or less) if the pool has none
+     */
+    public static String getRbdMonitors(String sourceHost, int sourcePort) {
+        List<String> monitors = new ArrayList<>();
+        for (String monitor : sourceHost.split(",")) {
+            monitor = monitor.trim();
+            if (monitor.isEmpty()) {
+                continue;
+            }
+            monitors.add(sourcePort > 0 ? addPortToRbdMonitor(monitor, sourcePort) : monitor);
+        }
+        return String.join(",", monitors);
+    }
+
+    public static String addPortToRbdMonitor(String monitor, int port) {
+        if (monitor.startsWith("[")) {
+            // IPv6 address in square brackets, which has a port if followed by ":<port>"
+            return monitor.contains("]:") ? monitor : monitor + ":" + port;
+        }
+        int colons = StringUtils.countMatches(monitor, ":");
+        if (colons == 0) {
+            return monitor + ":" + port;
+        }
+        if (colons == 1) {
+            // IPv4 address or host name, with a port
+            return monitor;
+        }
+        // IPv6 address without square brackets, so without a port
+        return "[" + monitor + "]:" + port;
+    }
+
+    /**
+     * The monitor list as the {@code rbd:} option string of a disk needs it: ':' separates the
+     * options of that string and ';' its monitors, so both are escaped inside the list, as is
+     * every ':' of an IPv6 address.
+     */
+    public static String composeOptionForMonHosts(String monHost, int monPort) {
+        List<String> hosts = new ArrayList<>();
+        for (String monitor : getRbdMonitors(monHost, monPort).split(",")) {
+            hosts.add(monitor.replace(":", "\\:"));

Review Comment:
   `getRbdMonitors(monHost, monPort)` returns the monitors separated by comma, it doesnot have `;`
   the monitors are joined by `\\;`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] utils,kvm: build every Ceph monitor list with RbdUtils [cloudstack]

Posted by "weizhouapache (via GitHub)" <gi...@apache.org>.
weizhouapache commented on PR #14402:
URL: https://github.com/apache/cloudstack/pull/14402#issuecomment-6169429859

   @blueorangutan package


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] utils,kvm: build every Ceph monitor list with RbdUtils [cloudstack]

Posted by "blueorangutan (via GitHub)" <gi...@apache.org>.
blueorangutan commented on PR #14402:
URL: https://github.com/apache/cloudstack/pull/14402#issuecomment-6170702736

   Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19556


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cloudstack.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org