Skip to content

Commit fb04f1b

Browse files
Support increased block storage volume limits
1 parent dc3164c commit fb04f1b

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

linode_api4/objects/linode.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from linode_api4.objects.serializable import JSONObject, StrEnum
4040
from linode_api4.objects.vpc import VPC, VPCSubnet
4141
from linode_api4.paginated_list import PaginatedList
42-
from linode_api4.util import drop_null_keys
42+
from linode_api4.util import drop_null_keys, generate_device_suffixes
4343

4444
PASSWORD_CHARS = string.ascii_letters + string.digits + string.punctuation
4545

@@ -1258,9 +1258,11 @@ def config_create(
12581258
from .volume import Volume # pylint: disable=import-outside-toplevel
12591259

12601260
hypervisor_prefix = "sd" if self.hypervisor == "kvm" else "xvd"
1261-
device_names = [
1262-
hypervisor_prefix + string.ascii_lowercase[i] for i in range(0, 8)
1263-
]
1261+
1262+
device_limit = int(max(8, min(self.specs.memory // 1024, 64)))
1263+
1264+
device_names = [hypervisor_prefix + suffix for suffix in generate_device_suffixes(device_limit)]
1265+
12641266
device_map = {
12651267
device_names[i]: None for i in range(0, len(device_names))
12661268
}

linode_api4/util.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
from typing import Any, Dict
6+
import string
67

78

89
def drop_null_keys(data: Dict[Any, Any], recursive=True) -> Dict[Any, Any]:
@@ -27,3 +28,28 @@ def recursive_helper(value: Any) -> Any:
2728
return value
2829

2930
return recursive_helper(data)
31+
32+
33+
def generate_device_suffixes(n):
34+
"""
35+
Generate n alphabetical suffixes starting with a, b, c, etc.
36+
After z, continue with aa, ab, ac, etc. followed by aaa, aab, etc.
37+
Example:
38+
generate_device_suffixes(30) ->
39+
['a', 'b', 'c', ..., 'z', 'aa', 'ab', 'ac', 'ad']
40+
"""
41+
letters = string.ascii_lowercase
42+
result = []
43+
i = 0
44+
45+
while len(result) < n:
46+
s = ""
47+
x = i
48+
while True:
49+
s = letters[x % 26] + s
50+
x = x // 26 - 1
51+
if x < 0:
52+
break
53+
result.append(s)
54+
i += 1
55+
return result

test/unit/util_test.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22

3-
from linode_api4.util import drop_null_keys
3+
from linode_api4.util import drop_null_keys, generate_device_suffixes
44

55

66
class UtilTest(unittest.TestCase):
@@ -53,3 +53,21 @@ def test_drop_null_keys_recursive(self):
5353
}
5454

5555
assert drop_null_keys(value) == expected_output
56+
57+
def test_generate_device_suffixes(self):
58+
"""
59+
Tests whether generate_device_suffixes works as expected.
60+
"""
61+
62+
expected_output_12 = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"]
63+
assert generate_device_suffixes(12) == expected_output_12
64+
65+
expected_output_30 = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
66+
"s", "t", "u", "v", "w", "x", "y", "z", "aa", "ab", "ac", "ad"]
67+
assert generate_device_suffixes(30) == expected_output_30
68+
69+
expected_output_60 = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
70+
"s", "t", "u", "v", "w", "x", "y", "z", "aa", "ab", "ac", "ad", "ae", "af", "ag", "ah",
71+
"ai", "aj", "ak", "al", "am", "an", "ao", "ap", "aq", "ar", "as", "at", "au", "av", "aw",
72+
"ax", "ay", "az", "ba", "bb", "bc", "bd", "be", "bf", "bg", "bh"]
73+
assert generate_device_suffixes(60) == expected_output_60

0 commit comments

Comments
 (0)