Răsfoiți Sursa

Added wip raid template

Toby Chui 1 an în urmă
părinte
comite
7889c48e7b

+ 24 - 14
mod/disk/raid/mdadm.go

@@ -4,7 +4,6 @@ import (
 	"fmt"
 	"os"
 	"os/exec"
-	"regexp"
 	"strconv"
 	"strings"
 )
@@ -136,28 +135,39 @@ func UpdateMDADMConfig() error {
 		return fmt.Errorf("error running mdadm command: %v", err)
 	}
 
-	arrayConfigs := strings.TrimSpace(string(output))
+	//Load the config from system
+	currentConfigBytes, err := os.ReadFile("/etc/mdadm/mdadm.conf")
+	if err != nil {
+		return fmt.Errorf("unable to open mdadm.conf: " + err.Error())
+	}
+	currentConf := string(currentConfigBytes)
 
-	lines := strings.Split(arrayConfigs, "\n")
-	//TODO: Add line filter for 2nd line appending
+	//Check if the current config already contains the setting
+	newConfigLines := []string{}
+	arrayConfigs := strings.TrimSpace(string(output))
+	lines := strings.Split(arrayConfigs, "ARRAY")
 	for _, line := range lines {
 		//For each line, you should have something like this
 		//ARRAY /dev/md0 metadata=1.2 name=debian:0 UUID=cbc11a2b:fbd42653:99c1340b:9c4962fb
 		//   devices=/dev/sdb,/dev/sdc
+
+		line = strings.ReplaceAll(line, "\n", " ")
 		fields := strings.Fields(line)
+		poolUUID := strings.TrimPrefix(fields[3], "UUID=")
 
-	}
+		//Check if this uuid already in the config file
+		if strings.Contains(currentConf, poolUUID) {
+			continue
+		}
 
-	//Extract the UUID from the output
-	// Define a regular expression to match the UUID pattern
-	uuidRegex := regexp.MustCompile(`UUID=([0-9a-fA-F:]+)`)
+		//This config not exists in the settings. Add it to append lines
+		settingLine := "ARRAY " + strings.Join(fields, " ")
+		newConfigLines = append(newConfigLines, settingLine)
 
-	// Find the first match of the UUID pattern in the output string
-	matches := uuidRegex.FindStringSubmatch(output)
-	if len(matches) < 2 {
-		return "", fmt.Errorf("UUID not found in mdadm output")
 	}
 
-	// Extract the UUID from the matched string
-	uuid := matches[1]
+	fmt.Println(newConfigLines)
+
+	//TODO: APPEND THE LINES INTO THE CONFIG FILE
+	return nil
 }

+ 20 - 0
mod/disk/raid/raidutils.go

@@ -2,6 +2,7 @@ package raid
 
 import (
 	"bufio"
+	"errors"
 	"fmt"
 	"os"
 	"os/exec"
@@ -40,6 +41,25 @@ func (m *Manager) WipeDisk(diskPath string) error {
 	return nil
 }
 
+// ClearSuperblock clears the superblock of the specified disk.
+func (m *Manager) ClearSuperblock(devicePath string) error {
+	isMounted, err := DeviceIsMounted(devicePath)
+	if err != nil {
+		return errors.New("unable to validate if the device is unmounted: " + err.Error())
+	}
+	if isMounted {
+		return errors.New("target device is mounted. Make sure it is unmounted before clearing")
+	}
+	cmd := exec.Command("sudo", "mdadm", "--zero-superblock", devicePath)
+
+	err = cmd.Run()
+	if err != nil {
+		return fmt.Errorf("error clearing superblock: %v", err)
+	}
+
+	return nil
+}
+
 // Check if a device is mounted given the path name, like /dev/sdc
 func DeviceIsMounted(devicePath string) (bool, error) {
 	// Open the mountinfo file

+ 71 - 6
web/SystemAO/disk/raid/index.html

@@ -10,6 +10,51 @@
         <script type="text/javascript" src="../../../script/semantic/semantic.min.js"></script>
         <script src="../disk/quota/script/Chart.min.js"></script>
         <style>
+            .mdevice{
+                color: rgb(59, 59, 59);
+                font-size: 0.8em;
+            }
+            .mdevuuid{
+                font-size: 0.6em !important;
+            }
+
+            .volinfo{
+                text-align: left !important;
+                margin-top: 0.6em !important;
+            }
+
+            .volinfo .numeric{
+                font-weight: lighter;
+                color: #0d79ea;
+            }
+
+            .volinfo .percentage{
+                font-weight: lighter;
+                color: rgb(102, 102, 102);
+                position: absolute;
+                text-align: right;
+                right: 1em;
+                top: 0em;
+            }
+
+            .raidVol .usedvol{
+                margin-bottom: 2em !important;
+            }
+            .raidVol .usedvol .bar{
+                background-color: #0d79ea !important;
+            }
+
+            .healthIcon{
+                position: absolute;
+                left: 35px;
+                top: 38px;
+                border-radius: 50% !important;
+                background-color: white; 
+            }
+
+            .healthIcon i {
+                margin-right: 0 !important;
+            }
 
         </style>
     </head>
@@ -26,7 +71,27 @@
             <div class="ui stackable grid">
                 <div class="six wide column" style="border-right: 1px solid #e0e0e0;">
                     <p>List of RAID Volumes</p>
-                    <div id="poolNameList">
+                    <div id="raidVolList">
+                        <div class="ui segment raidVol">
+                            <h4 class="ui header">
+                                <img src="../../img/system/raid.svg">
+                                <div class="healthIcon"><i class="ui green check circle icon"></i></div>
+                                <div class="content">
+                                    <span>Volume 1</span> <span class="mdevice">(/dev/md0)</span>
+                                    <div class="sub header mdevuuid" style="margin-top: 0.4em;">
+                                        cbc11a2b:fbd42653:99c1340b:9c4962fb
+                                    </div>
+                                </div>
+                                <br><br>
+                                <div class="ui small fluid usedvol progress">
+                                    <div class="bar"></div>
+                                    <div class="label volinfo">
+                                        <div class="numeric">100 / 100PB</div>
+                                        <div class="percentage">1%</div>
+                                    </div>
+                                </div>
+                            </h4>
+                        </div>
                         <div><i class="ui green check circle icon"></i> No RAID Volumes</div>
                     </div>
                     <div class="ui divider"></div>
@@ -37,16 +102,16 @@
                     </div>
                 </div>
                 <div class="ten wide column">
-                    <div id="disklist">
+                    <div id="raidDiskList">
     
                     </div>
                     <div class="ui divider"></div>
                     <div style="width: 100%;" align="center">
-                        <button onclick="newFsh();" title="Add Storage" class="circular basic large ui icon button">
-                            <i class="add icon"></i>
+                        <button onclick="" class="circular basic ui button">
+                            <i class="orange unlink icon"></i> Unlink Array
                         </button>
-                        <button onclick="bridgeFsh();" title="Bridge Storage" class="circular basic blue large ui icon button">
-                            <i class="linkify icon"></i>
+                        <button onclick="" class="circular basic red ui button">
+                            <i class="red trash icon"></i> Remove & Wipe Array
                         </button>
                     </div>
                 </div>

Fișier diff suprimat deoarece este prea mare
+ 27 - 0
web/img/system/raid.ai


BIN
web/img/system/raid.png


+ 18 - 0
web/img/system/raid.svg

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Generator: Adobe Illustrator 16.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="128px"
+	 height="128px" viewBox="0 0 128 128" enable-background="new 0 0 128 128" xml:space="preserve">
+<g id="圖層_1">
+</g>
+<g id="圖層_2">
+	<rect x="15.623" y="79.039" fill="#3E3A39" width="98.418" height="27.934"/>
+	<ellipse fill="#727171" cx="64.832" cy="79.038" rx="49.209" ry="12.69"/>
+	<rect x="15.623" y="51.106" fill="#727171" width="98.418" height="27.933"/>
+	<ellipse fill="#DCDDDD" cx="64.832" cy="51.105" rx="49.209" ry="12.689"/>
+	<rect x="15.623" y="23.128" fill="#DCDDDD" width="98.418" height="27.978"/>
+	<ellipse fill="#3E3A39" cx="64.832" cy="105.695" rx="49.209" ry="12.689"/>
+	<ellipse fill="#DCDDDD" stroke="#F7F8F8" stroke-miterlimit="10" cx="64.832" cy="24.427" rx="49.209" ry="12.689"/>
+	<ellipse fill="#00A0E9" cx="103.481" cy="99.728" rx="3.186" ry="5.968"/>
+</g>
+</svg>

Unele fișiere nu au fost afișate deoarece prea multe fișiere au fost modificate în acest diff