summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Holman <brett.holman@canonical.com>2023-02-06 03:44:27 -0700
committerGitHub <noreply@github.com>2023-02-06 11:44:27 +0100
commit51fef28bc561ca688308ac6ae060fa315e1c2d90 (patch)
treeeee03dde9bf93682c6908312ece68580b704597c
parent483f79cb3b94c8c7d176e748892a040c71132cb3 (diff)
downloadcloud-init-git-51fef28bc561ca688308ac6ae060fa315e1c2d90.tar.gz
cc_disk_setup: code cleanup (#1996)
-rw-r--r--cloudinit/config/cc_disk_setup.py62
1 files changed, 17 insertions, 45 deletions
diff --git a/cloudinit/config/cc_disk_setup.py b/cloudinit/config/cc_disk_setup.py
index 5ec5c793..0248e7ec 100644
--- a/cloudinit/config/cc_disk_setup.py
+++ b/cloudinit/config/cc_disk_setup.py
@@ -439,33 +439,6 @@ def is_disk_used(device):
return False
-def get_dyn_func(*args):
- """
- Call the appropriate function.
-
- The first value is the template for function name
- The second value is the template replacement
- The remain values are passed to the function
-
- For example: get_dyn_func("foo_%s", 'bar', 1, 2, 3,)
- would call "foo_bar" with args of 1, 2, 3
- """
- if len(args) < 2:
- raise Exception("Unable to determine dynamic funcation name")
-
- func_name = args[0] % args[1]
- func_args = args[2:]
-
- try:
- if func_args:
- return globals()[func_name](*func_args)
- else:
- return globals()[func_name]
-
- except KeyError as e:
- raise Exception("No such function %s to call!" % func_name) from e
-
-
def get_hdd_size(device):
try:
size_in_bytes, _ = subp.subp([BLKDEV_CMD, "--getsize64", device])
@@ -564,9 +537,12 @@ def check_partition_layout(table_type, device, layout):
to add support for other disk layout schemes, add a
function called check_partition_%s_layout
"""
- found_layout = get_dyn_func(
- "check_partition_%s_layout", table_type, device, layout
- )
+ if "gpt" == table_type:
+ found_layout = check_partition_gpt_layout(device, layout)
+ elif "mbr" == table_type:
+ found_layout = check_partition_mbr_layout(device, layout)
+ else:
+ raise Exception("Unable to determine table type")
LOG.debug(
"called check_partition_%s_layout(%s, %s), returned: %s",
@@ -722,7 +698,11 @@ def get_partition_layout(table_type, size, layout):
other layouts, simply add a "get_partition_%s_layout"
function.
"""
- return get_dyn_func("get_partition_%s_layout", table_type, size, layout)
+ if "mbr" == table_type:
+ return get_partition_mbr_layout(size, layout)
+ elif "gpt" == table_type:
+ return get_partition_gpt_layout(size, layout)
+ raise Exception("Unable to determine table type")
def read_parttbl(device):
@@ -787,19 +767,6 @@ def exec_mkpart_gpt(device, layout):
read_parttbl(device)
-def exec_mkpart(table_type, device, layout):
- """
- Fetches the function for creating the table type.
- This allows to dynamically find which function to call.
-
- Paramaters:
- table_type: type of partition table to use
- device: the device to work on
- layout: layout definition specific to partition table
- """
- return get_dyn_func("exec_mkpart_%s", table_type, device, layout)
-
-
def assert_and_settle_device(device):
"""Assert that device exists and settle so it is fully recognized."""
if not os.path.exists(device):
@@ -877,7 +844,12 @@ def mkpart(device, definition):
LOG.debug(" Layout is: %s", part_definition)
LOG.debug("Creating partition table on %s", device)
- exec_mkpart(table_type, device, part_definition)
+ if "mbr" == table_type:
+ exec_mkpart_mbr(device, part_definition)
+ elif "gpt" == table_type:
+ exec_mkpart_gpt(device, part_definition)
+ else:
+ raise Exception("Unable to determine table type")
LOG.debug("Partition table created for %s", device)