Skip to content

Commit 1046083

Browse files
committed
refactor for loop updateRootSize and use const
1 parent d5f087f commit 1046083

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

internal/services/baremetal/easy_partitioning_data_source.go

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ import (
1919
const (
2020
partitionSize = 20000000000
2121
defaultMountpoint = "/data"
22+
md0 = "/dev/md0"
23+
md1 = "/dev/md1"
24+
md2 = "/dev/md2"
25+
ext4 = "ext4"
26+
raidLevel1 = "raid_level_1"
27+
nvme0p2 = "/dev/nvme0n1p2"
28+
nvme0p3 = "/dev/nvme0n1p3"
29+
nvme1p1 = "/dev/nvme1n1p1"
30+
nvme1p2 = "/dev/nvme1n1p2"
31+
uefi = "uefi"
32+
swap = "swap"
33+
root = "root"
34+
boot = "boot"
2235
)
2336

2437
func DataEasyPartitioning() *schema.Resource {
@@ -152,19 +165,19 @@ func dataEasyPartitioningRead(ctx context.Context, d *schema.ResourceData, m int
152165
func updateRaidRemoveSwap(partitionSchema *baremetal.Schema) {
153166
raidSchema := []*baremetal.SchemaRAID{
154167
{
155-
Name: "/dev/md0",
156-
Level: "raid_level_1",
168+
Name: md0,
169+
Level: raidLevel1,
157170
Devices: []string{
158-
"/dev/nvme0n1p2",
159-
"/dev/nvme1n1p1",
171+
nvme0p2,
172+
nvme1p1,
160173
},
161174
},
162175
{
163-
Name: "/dev/md1",
164-
Level: "raid_level_1",
176+
Name: md1,
177+
Level: raidLevel1,
165178
Devices: []string{
166-
"/dev/nvme0n1p3",
167-
"/dev/nvme1n1p2",
179+
nvme0p3,
180+
nvme1p2,
168181
},
169182
},
170183
}
@@ -175,8 +188,8 @@ func updateRaidNewPartition(partitionSchema *baremetal.Schema) {
175188
lenDisk0Partition := len(partitionSchema.Disks[0].Partitions)
176189
lenDisk1Partition := len(partitionSchema.Disks[1].Partitions)
177190
raid := &baremetal.SchemaRAID{
178-
Name: "/dev/md2",
179-
Level: "raid_level_1",
191+
Name: md2,
192+
Level: raidLevel1,
180193
Devices: []string{
181194
fmt.Sprintf("%sp%d", partitionSchema.Disks[0].Device, lenDisk0Partition),
182195
fmt.Sprintf("%sp%d", partitionSchema.Disks[1].Device, lenDisk1Partition),
@@ -200,8 +213,8 @@ func addExtraExt4Partition(mountpoint string, defaultPartitionSchema *baremetal.
200213
}
201214

202215
filesystem := &baremetal.SchemaFilesystem{
203-
Device: "/dev/md2",
204-
Format: "ext4",
216+
Device: md2,
217+
Format: ext4,
205218
Mountpoint: mountpoint,
206219
}
207220
defaultPartitionSchema.Filesystems = append(defaultPartitionSchema.Filesystems, filesystem)
@@ -210,13 +223,12 @@ func addExtraExt4Partition(mountpoint string, defaultPartitionSchema *baremetal.
210223
func updateSizeRoot(originalDisks []*baremetal.SchemaDisk, hasExtraPartition bool) {
211224
for _, disk := range originalDisks {
212225
for _, partition := range disk.Partitions {
213-
if partition.Label == "root" {
226+
if partition.Label == root {
227+
partition.Size = 0
228+
partition.UseAllAvailableSpace = true
214229
if hasExtraPartition {
215230
partition.Size = partitionSize
216231
partition.UseAllAvailableSpace = false
217-
} else {
218-
partition.Size = 0
219-
partition.UseAllAvailableSpace = true
220232
}
221233
}
222234
}
@@ -228,11 +240,11 @@ func removeSwap(originalDisks []*baremetal.SchemaDisk) {
228240
newPartitions := make([]*baremetal.SchemaPartition, 0, len(disk.Partitions))
229241

230242
for _, partition := range disk.Partitions {
231-
if partition.Label == "swap" {
243+
if partition.Label == swap {
232244
continue
233245
}
234246

235-
if partition.Label != "uefi" {
247+
if partition.Label != uefi {
236248
partition.Number--
237249
}
238250

0 commit comments

Comments
 (0)