ssulav commented on code in PR #2:
URL: https://github.com/apache/ozone-installer/pull/2#discussion_r2831737186


##########
ozone_installer.py:
##########
@@ -296,57 +310,97 @@ def parse_hosts(hosts_raw: Optional[str]) -> List[dict]:
             out.append({"host": host, "user": user, "port": port})
     return out
 
-def read_hosts_from_file(filepath: str) -> Optional[str]:
+def read_hosts_from_file(filepath: str) -> Tuple[Optional[str], Optional[str]]:
     """
-    Reads hosts from a file (one host per line).
-    Lines starting with # are treated as comments and ignored.
-    Empty lines are ignored.
-    Supports same format as CLI: user@host:port
-    Returns comma-separated host string suitable for parse_hosts().
+    Reads hosts from a file.
+
+    Two formats supported:
+    1) Master/worker: [masters] and [workers] sections (INI-style). Returns 
(masters_csv, workers_csv).
+    2) Legacy: plain list, one host per line. Returns (hosts_csv, None).
+
+    Lines starting with # are comments. Empty lines ignored. Supports 
user@host:port.
     """
     logger = get_logger()
     try:
         path = Path(filepath)
         if not path.exists():
             logger.error(f"Host file not found: {filepath}")
-            return None
-        hosts = []
+            return (None, None)
+        masters: List[str] = []
+        workers: List[str] = []
+        flat: List[str] = []
+        current_section: Optional[str] = None
         with path.open('r') as f:
             for line in f:
                 line = line.strip()
-                # Skip empty lines and comments
                 if not line or line.startswith('#'):
                     continue
-                hosts.append(line)
-        if hosts:
-            logger.info(f"Read {len(hosts)} host(s) from {filepath}")
-            return ','.join(hosts)
-        else:
-            logger.error(f"No valid hosts found in {filepath}")
-            return None
+                if line.startswith('[') and line.endswith(']'):
+                    current_section = line[1:-1].lower()
+                    continue
+                if current_section == "masters":
+                    masters.append(line)
+                elif current_section == "workers":
+                    workers.append(line)
+                elif current_section is None:
+                    flat.append(line)
+        if masters and workers:
+            logger.info(f"Read {len(masters)} master(s) and {len(workers)} 
worker(s) from {filepath}")
+            return (','.join(masters), ','.join(workers))
+        if flat:
+            logger.info(f"Read {len(flat)} host(s) from {filepath}")
+            return (','.join(flat), None)
+        logger.error(f"No valid hosts found in {filepath}")
+        return (None, None)
     except Exception as e:
         logger.error(f"Error reading host file {filepath}: {e}")
-        return None
+        return (None, None)
 
-def auto_cluster_mode(hosts: List[dict], forced: Optional[str] = None) -> str:
+def auto_cluster_mode(hosts: List[dict], forced: Optional[str] = None, 
master_count: Optional[int] = None) -> str:
     if forced in ("non-ha", "ha"):
         return forced
-    return "ha" if len(hosts) >= 3 else "non-ha"
-
-def build_inventory(hosts: List[dict], ssh_user: Optional[str] = None, 
keyfile: Optional[str] = None, password: Optional[str] = None, cluster_mode: 
str = "non-ha", python_interpreter: Optional[str] = None) -> str:
+    n = master_count if master_count is not None else len(hosts)
+    return "ha" if n >= 3 else "non-ha"

Review Comment:
   Sure. Let me fix that



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to