-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[controller] Add a sds scaner and a cache (#47)
Signed-off-by: Viktor Kramarenko <[email protected]>
- Loading branch information
1 parent
fe2c39b
commit 9cb4133
Showing
12 changed files
with
412 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package cache | ||
|
||
import ( | ||
"fmt" | ||
"sds-node-configurator/internal" | ||
"sds-node-configurator/pkg/logger" | ||
) | ||
|
||
type Cache struct { | ||
devices []internal.Device | ||
pvs []internal.PVData | ||
vgs []internal.VGData | ||
lvs []internal.LVData | ||
} | ||
|
||
func New() Cache { | ||
return Cache{} | ||
} | ||
|
||
func (c *Cache) StoreDevices(devices []internal.Device) { | ||
c.devices = devices | ||
} | ||
|
||
func (c *Cache) GetDevices() []internal.Device { | ||
dst := make([]internal.Device, len(c.devices)) | ||
copy(dst, c.devices) | ||
|
||
return dst | ||
} | ||
|
||
func (c *Cache) StorePVs(pvs []internal.PVData) { | ||
c.pvs = pvs | ||
} | ||
|
||
func (c *Cache) GetPVs() []internal.PVData { | ||
dst := make([]internal.PVData, len(c.pvs)) | ||
copy(dst, c.pvs) | ||
|
||
return dst | ||
} | ||
|
||
func (c *Cache) StoreVGs(vgs []internal.VGData) { | ||
c.vgs = vgs | ||
} | ||
|
||
func (c *Cache) GetVGs() []internal.VGData { | ||
dst := make([]internal.VGData, len(c.vgs)) | ||
copy(dst, c.vgs) | ||
|
||
return dst | ||
} | ||
|
||
func (c *Cache) StoreLVs(lvs []internal.LVData) { | ||
c.lvs = lvs | ||
} | ||
|
||
func (c *Cache) GetLVs() []internal.LVData { | ||
dst := make([]internal.LVData, len(c.lvs)) | ||
copy(dst, c.lvs) | ||
|
||
return dst | ||
} | ||
|
||
func (c *Cache) PrintTheCache(log logger.Logger) { | ||
log.Cache("*****************CACHE BEGIN*****************") | ||
log.Cache("[Devices BEGIN]") | ||
for _, d := range c.devices { | ||
log.Cache(fmt.Sprintf(" Device Name: %s, size: %s, fsType: %s, serial: %s, wwn: %s", d.Name, d.Size.String(), d.FSType, d.Serial, d.Wwn)) | ||
} | ||
log.Cache("[Devices ENDS]") | ||
log.Cache("[PVs BEGIN]") | ||
for _, pv := range c.pvs { | ||
log.Cache(fmt.Sprintf(" PV Name: %s, VG Name: %s, size: %s, vgTags: %s", pv.PVName, pv.VGName, pv.PVSize.String(), pv.VGTags)) | ||
} | ||
log.Cache("[PVs ENDS]") | ||
log.Cache("[VGs BEGIN]") | ||
for _, vg := range c.vgs { | ||
log.Cache(fmt.Sprintf(" VG Name: %s, size: %s, free: %s, vgTags: %s", vg.VGName, vg.VGSize.String(), vg.VGFree.String(), vg.VGTags)) | ||
} | ||
log.Cache("[VGs ENDS]") | ||
log.Cache("[LVs BEGIN]") | ||
for _, lv := range c.lvs { | ||
log.Cache(fmt.Sprintf(" LV Name: %s, VG name: %s, size: %s, tags: %s, attr: %s, pool: %s", lv.LVName, lv.VGName, lv.LVSize.String(), lv.LvTags, lv.LVAttr, lv.PoolLv)) | ||
} | ||
log.Cache("[LVs ENDS]") | ||
log.Cache("*****************CACHE ENDS*****************") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package cache | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"sds-node-configurator/internal" | ||
"testing" | ||
) | ||
|
||
func TestCache(t *testing.T) { | ||
sdsCache := New() | ||
devices := []internal.Device{ | ||
{ | ||
Name: "test-1", | ||
}, | ||
{ | ||
Name: "test-2", | ||
}, | ||
{ | ||
Name: "test-3", | ||
}, | ||
} | ||
|
||
pvs := []internal.PVData{ | ||
{ | ||
PVName: "pv-1", | ||
}, | ||
{ | ||
PVName: "pv-2", | ||
}, | ||
{ | ||
PVName: "pv-3", | ||
}, | ||
} | ||
|
||
vgs := []internal.VGData{ | ||
{ | ||
VGName: "vg-1", | ||
}, | ||
{ | ||
VGName: "vg-2", | ||
}, | ||
{ | ||
VGName: "vg-3", | ||
}, | ||
} | ||
|
||
lvs := []internal.LVData{ | ||
{ | ||
LVName: "lv-1", | ||
}, | ||
{ | ||
LVName: "lv-2", | ||
}, | ||
{ | ||
LVName: "lv-3", | ||
}, | ||
} | ||
|
||
sdsCache.StoreDevices(devices) | ||
sdsCache.StorePVs(pvs) | ||
sdsCache.StoreVGs(vgs) | ||
sdsCache.StoreLVs(lvs) | ||
|
||
assert.ElementsMatch(t, devices, sdsCache.GetDevices()) | ||
assert.ElementsMatch(t, pvs, sdsCache.GetPVs()) | ||
assert.ElementsMatch(t, vgs, sdsCache.GetVGs()) | ||
assert.ElementsMatch(t, lvs, sdsCache.GetLVs()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.