From bd57ab298232def719932d36b094ce60f9e305ca Mon Sep 17 00:00:00 2001 From: lasith-kg Date: Mon, 20 May 2024 12:53:19 +0000 Subject: [PATCH] (feat): Suggestions from Pull Request --- configs/ubuntu.yml | 2 +- internal/config/modifier.go | 5 ++--- internal/datastructures/lvm_graph.go | 2 ++ internal/model/lvm.go | 8 +++++--- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/configs/ubuntu.yml b/configs/ubuntu.yml index af81fb6..2ab6075 100644 --- a/configs/ubuntu.yml +++ b/configs/ubuntu.yml @@ -14,4 +14,4 @@ devices: mountPoint: /mnt/bar user: ubuntu group: ubuntu - permissions: 755 \ No newline at end of file + permissions: 755 diff --git a/internal/config/modifier.go b/internal/config/modifier.go index 09f7fcc..4dc5d99 100644 --- a/internal/config/modifier.go +++ b/internal/config/modifier.go @@ -70,9 +70,8 @@ func NewLvmModifier() *LvmModifier { } func (lm *LvmModifier) Modify(c *Config) error { - // Fetch a copy of the original keys as we are updating - // the config in-place and it is unsafe to iterate over it - // directly + // Fetch a copy of the original keys as we are updating the + // config in-place and it is unsafe to iterate over it directly keys := make([]string, len(c.Devices)) for name := range c.Devices { keys = append(keys, name) diff --git a/internal/datastructures/lvm_graph.go b/internal/datastructures/lvm_graph.go index 7e87f02..29bbd89 100644 --- a/internal/datastructures/lvm_graph.go +++ b/internal/datastructures/lvm_graph.go @@ -197,6 +197,7 @@ func (lg *LvmGraph) GetLogicalVolume(name string, vg string) (*LvmNode, error) { func (lg *LvmGraph) GetParents(node *LvmNode, state LvmNodeCategory) []*LvmNode { parents := []*LvmNode{} for _, p := range node.parents { + // Bitmasking to check if the parent nodes is of the desired category if int32(p.State)&int32(state) > 0 { parents = append(parents, p) } @@ -207,6 +208,7 @@ func (lg *LvmGraph) GetParents(node *LvmNode, state LvmNodeCategory) []*LvmNode func (lg *LvmGraph) GetChildren(node *LvmNode, state LvmNodeCategory) []*LvmNode { children := []*LvmNode{} for _, c := range node.children { + // Bitmasking to check if children nodes is of the desired category if int32(c.State)&int32(state) > 0 { children = append(children, c) } diff --git a/internal/model/lvm.go b/internal/model/lvm.go index 5b05cbb..1feb5de 100644 --- a/internal/model/lvm.go +++ b/internal/model/lvm.go @@ -1,5 +1,7 @@ package model +import "github.com/reecetech/ebs-bootstrap/internal/datastructures" + type PhysicalVolume struct { Name string } @@ -12,9 +14,9 @@ type VolumeGroup struct { type LogicalVolumeState int32 const ( - Inactive LogicalVolumeState = 0b0010000 - Active LogicalVolumeState = 0b0110000 - Unsupported LogicalVolumeState = 0b1110000 + Inactive LogicalVolumeState = LogicalVolumeState(datastructures.LogicalVolumeInactive) + Active LogicalVolumeState = LogicalVolumeState(datastructures.LogicalVolumeActive) + Unsupported LogicalVolumeState = LogicalVolumeState(datastructures.LogicalVolumeUnsupported) ) type LogicalVolume struct {