Skip to content

Commit

Permalink
Implemented % unit feature, removed some unnecessary comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyJiang1 committed Aug 17, 2023
1 parent f53ad3f commit 6691c75
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 20 deletions.
13 changes: 9 additions & 4 deletions examples/partitionContainer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## What does it do?

The container will partition the hard disk into a user specified number of partitions. The user can define the specific size of each partition and what type of partition it is _(eg. EFI, swap, root etc...)_. Users also have the option of specifying each partition's type through UUID (https://uapi-group.org/specifications/specs/discoverable_partitions_specification/) as well as its mount point.

## Inputting Configurations
All of the configuration will be passed through a JSON file with the following format:
```json
Expand All @@ -15,21 +16,25 @@ All of the configuration will be passed through a JSON file with the following f
"device_name": {
"blkSize": "512B",
"partitions": [{
"size": "1000MiB",
"size": "512MiB",
"type": "efi"
},{
"size": "2000MiB",
"size": "2GiB",
"type": "swap"
},{
"size": "16GiB",
"type": "linux",
"optional": {
"UUID": "75250d76-8cc6-458e-bd66-bd47cc81a812",
"mountPoint": "/usr/"
"UUID": "44479540-f297-41b2-9af7-d131d5f0458a",
"mountPoint": "/"
}
}
]
}
}
}
```

### Explanation:
Accepted units for sizes: B, KB, kB, MB, MiB, GB, GiB, TB, TiB
* **general**
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 0 additions & 1 deletion examples/partitionContainer/inputScript.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ then
fi

filename=$(mktemp -p .)
# curl --insecure -L -o $filename -v $PARTITIONING
# Checks if the curl created a non empty file
if curl --insecure -L -o $filename -v $PARTITIONING
then
Expand Down
4 changes: 0 additions & 4 deletions examples/partitionContainer/interactive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ then
echo "file does not exist"
fi
else
# TODO: Figure out how to get the file name from the curl
# command, and the run that file. Right now it assumes there
# is only one JSON file in the local directory. Will break if
# mulitple JSON files are in the same folder.
read -p "Please enter the URL: " URL
filename=$(mktemp -p .)
curl --insecure -L -o $filename -v $URL
Expand Down
16 changes: 5 additions & 11 deletions examples/partitionContainer/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def convertToBytes(value, unit):

storage = Storage(environment)
storage.probe()
probed = storage.get_probed()
staging = storage.get_staging()


Expand Down Expand Up @@ -90,16 +91,9 @@ def convertToBytes(value, unit):
if part_unit != "%":
partSizeBytes = convertToBytes(part_size, part_unit)
else:
print("Does not support percentage unit currently")

# Code breaks if probing occurs, but using the percentage unit requires probing
# else:
# storage.probe()
# probed = storage.get_probed()
# disks = probed.get_all_disks()
# for d in disks:
# print(d.get_name())

disk = Disk.find_by_name(probed, device_name)
dev_size = disk.get_size() - convertToBytes(units(initial_gap)[0], units(initial_gap)[1])
partSizeBytes = int(dev_size * (part_size / 100))
# Creates a region based on the starting point, size, and block size.
reg = Region(int(startingPoint / blockSizeBytes), int(partSizeBytes / blockSizeBytes), int(blockSizeBytes))

Expand All @@ -121,4 +115,4 @@ def convertToBytes(value, unit):
print(devList)
# NOTE: Uncommenting the line below will cause the program
# to impact your current hardware.
commit(storage)
# commit(storage)

0 comments on commit 6691c75

Please sign in to comment.