Skip to content

Commit 0dde23a

Browse files
authored
Merge pull request #59 from linux-kdevops/cel/oci-dynamic-menu
Dynamically generate the OCI terraform menus
2 parents 1cb3ea5 + 68ce84e commit 0dde23a

36 files changed

+3820
-764
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ terraform/aws/kconfigs/Kconfig.instance.generated
122122
terraform/aws/kconfigs/Kconfig.location.generated
123123
terraform/aws/scripts/__pycache__/
124124

125+
terraform/oci/kconfigs/Kconfig.image.generated
126+
terraform/oci/kconfigs/Kconfig.location.generated
127+
terraform/oci/kconfigs/Kconfig.shape.generated
128+
terraform/oci/scripts/__pycache__/
129+
125130
.cloud.initialized
126131

127132
scripts/__pycache__/

scripts/dynamic-cloud-kconfig.Makefile

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,16 @@ AWS_KCONFIG_LOCATION := $(AWS_KCONFIG_DIR)/Kconfig.location.generated
2020

2121
AWS_KCONFIGS := $(AWS_KCONFIG_AMI) $(AWS_KCONFIG_INSTANCE) $(AWS_KCONFIG_LOCATION)
2222

23+
# OCI dynamic configuration
24+
OCI_KCONFIG_DIR := terraform/oci/kconfigs
25+
OCI_KCONFIG_IMAGE := $(OCI_KCONFIG_DIR)/Kconfig.image.generated
26+
OCI_KCONFIG_LOCATION := $(OCI_KCONFIG_DIR)/Kconfig.location.generated
27+
OCI_KCONFIG_SHAPE := $(OCI_KCONFIG_DIR)/Kconfig.shape.generated
28+
29+
OCI_KCONFIGS := $(OCI_KCONFIG_IMAGE) $(OCI_KCONFIG_LOCATION) $(OCI_KCONFIG_SHAPE)
30+
2331
# Add generated files to mrproper clean list
24-
KDEVOPS_MRPROPER += $(LAMBDALABS_KCONFIGS) $(AWS_KCONFIGS)
32+
KDEVOPS_MRPROPER += $(LAMBDALABS_KCONFIGS) $(AWS_KCONFIGS) $(OCI_KCONFIGS)
2533

2634
# Touch Lambda Labs generated files so Kconfig can source them
2735
# This ensures the files exist (even if empty) before Kconfig runs
@@ -32,7 +40,11 @@ dynamic_lambdalabs_kconfig_touch:
3240
dynamic_aws_kconfig_touch:
3341
$(Q)touch $(AWS_KCONFIGS)
3442

35-
DYNAMIC_KCONFIG += dynamic_lambdalabs_kconfig_touch dynamic_aws_kconfig_touch
43+
# Touch OCI generated files so Kconfig can source them
44+
dynamic_oci_kconfig_touch:
45+
$(Q)touch $(OCI_KCONFIGS)
46+
47+
DYNAMIC_KCONFIG += dynamic_lambdalabs_kconfig_touch dynamic_aws_kconfig_touch dynamic_oci_kconfig_touch
3648

3749
# Lambda Labs targets use --provider argument for efficiency
3850
cloud-config-lambdalabs:
@@ -42,6 +54,10 @@ cloud-config-lambdalabs:
4254
cloud-config-aws:
4355
$(Q)python3 scripts/generate_cloud_configs.py --provider aws
4456

57+
# OCI targets use --provider argument for efficiency
58+
cloud-config-oci:
59+
$(Q)python3 scripts/generate_cloud_configs.py --provider oci
60+
4561
# Clean Lambda Labs generated files
4662
clean-cloud-config-lambdalabs:
4763
$(Q)rm -f $(LAMBDALABS_KCONFIGS)
@@ -50,7 +66,11 @@ clean-cloud-config-lambdalabs:
5066
clean-cloud-config-aws:
5167
$(Q)rm -f $(AWS_KCONFIGS)
5268

53-
DYNAMIC_CLOUD_KCONFIG += cloud-config-lambdalabs cloud-config-aws
69+
# Clean OCI generated files
70+
clean-cloud-config-oci:
71+
$(Q)rm -f $(OCI_KCONFIGS)
72+
73+
DYNAMIC_CLOUD_KCONFIG += cloud-config-lambdalabs cloud-config-aws cloud-config-oci
5474

5575
cloud-config-help:
5676
@echo "Cloud-specific dynamic kconfig targets:"
@@ -72,4 +92,7 @@ cloud-list-all:
7292
$(Q)chmod +x scripts/cloud_list_all.sh
7393
$(Q)scripts/cloud_list_all.sh
7494

75-
PHONY += cloud-config cloud-config-lambdalabs cloud-config-aws clean-cloud-config clean-cloud-config-lambdalabs clean-cloud-config-aws cloud-config-help cloud-list-all
95+
PHONY += cloud-config clean-cloud-config cloud-config-help cloud-list-all
96+
PHONY += cloud-config-aws clean-cloud-config-aws
97+
PHONY += cloud-config-lambdalabs clean-cloud-config-lambdalabs
98+
PHONY += cloud-config-oci clean-cloud-config-oci

scripts/generate_cloud_configs.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,52 @@ def generate_aws_kconfig() -> bool:
147147
return all_success
148148

149149

150+
def generate_oci_kconfig() -> bool:
151+
"""
152+
Generate OCI Kconfig files.
153+
Returns True on success, False on failure.
154+
"""
155+
script_dir = os.path.dirname(os.path.abspath(__file__))
156+
project_root = os.path.dirname(script_dir)
157+
oci_scripts_dir = os.path.join(project_root, "terraform", "oci", "scripts")
158+
oci_kconfigs_dir = os.path.join(project_root, "terraform", "oci", "kconfigs")
159+
160+
# Define the script-to-output mapping
161+
scripts_to_run = [
162+
("gen_kconfig_image", "Kconfig.image.generated"),
163+
("gen_kconfig_location", "Kconfig.location.generated"),
164+
("gen_kconfig_shape", "Kconfig.shape.generated"),
165+
]
166+
167+
all_success = True
168+
169+
for script_name, kconfig_file in scripts_to_run:
170+
script_path = os.path.join(oci_scripts_dir, script_name)
171+
output_path = os.path.join(oci_kconfigs_dir, kconfig_file)
172+
173+
# Run the script and capture its output
174+
result = subprocess.run(
175+
[script_path],
176+
capture_output=True,
177+
text=True,
178+
check=False,
179+
)
180+
181+
if result.returncode == 0:
182+
# Write the output to the corresponding Kconfig file
183+
try:
184+
with open(output_path, "w") as f:
185+
f.write(result.stdout)
186+
except IOError as e:
187+
print(f"Error writing {kconfig_file}: {e}", file=sys.stderr)
188+
all_success = False
189+
else:
190+
print(f"Error running {script_name}: {result.stderr}", file=sys.stderr)
191+
all_success = False
192+
193+
return all_success
194+
195+
150196
def process_lambdalabs():
151197
"""Process Lambda Labs configuration."""
152198
# Generate Kconfig files first
@@ -186,8 +232,13 @@ def process_gce():
186232

187233

188234
def process_oci():
189-
"""Process OCI configuration (placeholder)."""
190-
print("⚠ OCI: Dynamic configuration not yet implemented")
235+
"""Process OCI configuration."""
236+
kconfig_generated = generate_oci_kconfig()
237+
if kconfig_generated:
238+
print("✓ OCI: Kconfig files generated successfully")
239+
else:
240+
print("⚠ OCI: Failed to generate Kconfig files - using defaults")
241+
print()
191242

192243

193244
def main():

terraform/oci/Kconfig

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1+
# OCI provider configuration
2+
#
3+
# This file sources dynamically Kconfig menus. Run
4+
# 'make cloud-config-oci' to populate the .generated files
5+
# with current OCI resource information.
6+
17
if TERRAFORM_OCI
28

39
menu "Resource location"
4-
source "terraform/oci/kconfigs/Kconfig.location"
10+
source "terraform/oci/kconfigs/Kconfig.location.generated"
511
endmenu
612
menu "Compute"
7-
source "terraform/oci/kconfigs/Kconfig.compute"
13+
comment "Shape selection"
14+
source "terraform/oci/kconfigs/Kconfig.shape.generated"
15+
comment "OS image selection"
16+
source "terraform/oci/kconfigs/Kconfig.image.generated"
817
endmenu
918
menu "Storage"
1019
source "terraform/oci/kconfigs/Kconfig.storage"

terraform/oci/kconfigs/Kconfig.compute

Lines changed: 0 additions & 79 deletions
This file was deleted.

0 commit comments

Comments
 (0)