[PR #322] [CLOSED] Centralize all standard LXC options to avoid code duplication #2684

Closed
opened 2026-02-26 13:31:01 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/community-scripts/ProxmoxVE/pull/322
Author: @remz1337
Created: 11/18/2024
Status: Closed

Base: mainHead: base_settings


📝 Commits (3)

  • 0e9623b Centralize all standard LXC options to avoid code duplication
  • 15d8382 Updated comment wording
  • be35a96 Updated comment wording

📊 Changes

1 file changed (+32 additions, -0 deletions)

View changed files

📝 misc/build.func (+32 -0)

📄 Description

Note

We are meticulous when it comes to merging code into the main branch, so please understand that we may reject pull requests that do not meet the project's standards. It's never personal. Also, game-related scripts have a lower chance of being merged.

Description

Add a function, base_settings, to centralize all common options so that scripts only need to define settings that need to be overridden. For the great majority of scripts, all the options use the default values for default_settings. Key settings are already captured outside of the default_settings function: var_XXX (eg. var_disk, var_cpu ...)

With this PR, the default_settings function in scripts could go from:

function default_settings() {
  CT_TYPE="1"
  PW=""
  CT_ID=$NEXTID
  HN=$NSAPP
  DISK_SIZE="$var_disk"
  CORE_COUNT="$var_cpu"
  RAM_SIZE="$var_ram"
  BRG="vmbr0"
  NET="dhcp"
  GATE=""
  APT_CACHER=""
  APT_CACHER_IP=""
  DISABLEIP6="no"
  MTU=""
  SD=""
  NS=""
  MAC=""
  VLAN=""
  SSH="no"
  VERB="no"
  echo_default
}

to

function default_settings() {
  CT_ID=$NEXTID
  HN=$NSAPP
  DISK_SIZE="$var_disk"
  CORE_COUNT="$var_cpu"
  RAM_SIZE="$var_ram"
  echo_default
}

and in case a script needs to overwrite an additional setting, simply add it back, like this:

function default_settings() {
  CT_ID=$NEXTID
  HN=$NSAPP
  DISK_SIZE="$var_disk"
  CORE_COUNT="$var_cpu"
  RAM_SIZE="$var_ram"
  DISABLEIP6="yes"
  VERB="yes"
  echo_default
}

I've been using this in my fork for some time. It's great when you need to add a new default variable, you don't need to update back all the scripts. Plus, it's good practice to avoid duplication of information.

Type of change

Please check the relevant option(s):

  • Bug fix (non-breaking change that resolves an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (a fix or feature that would cause existing functionality to change unexpectedly)
  • New script (a fully functional and thoroughly tested script or set of scripts.)

Prerequisites

The following efforts must be made for the PR to be considered. Please check when completed:

  • Self-review performed (I have reviewed my code, ensuring it follows established patterns and conventions)
  • Testing performed (I have tested my changes, ensuring everything works as expected)
  • Documentation updated (I have updated any relevant documentation)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/community-scripts/ProxmoxVE/pull/322 **Author:** [@remz1337](https://github.com/remz1337) **Created:** 11/18/2024 **Status:** ❌ Closed **Base:** `main` ← **Head:** `base_settings` --- ### 📝 Commits (3) - [`0e9623b`](https://github.com/community-scripts/ProxmoxVE/commit/0e9623b6625193bcc6208e5b3953b65339375830) Centralize all standard LXC options to avoid code duplication - [`15d8382`](https://github.com/community-scripts/ProxmoxVE/commit/15d8382c170701e0f6ff9d23185ff6cb7149ac6d) Updated comment wording - [`be35a96`](https://github.com/community-scripts/ProxmoxVE/commit/be35a96052547e881a831b793087731a5fc41779) Updated comment wording ### 📊 Changes **1 file changed** (+32 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `misc/build.func` (+32 -0) </details> ### 📄 Description > [!NOTE] > We are meticulous when it comes to merging code into the main branch, so please understand that we may reject pull requests that do not meet the project's standards. It's never personal. Also, game-related scripts have a lower chance of being merged. ## Description Add a function, `base_settings`, to centralize all common options so that scripts only need to define settings that need to be overridden. For the great majority of scripts, all the options use the default values for `default_settings`. Key settings are already captured outside of the `default_settings` function: `var_XXX` (eg. `var_disk`, `var_cpu` ...) With this PR, the default_settings function in scripts could go from: ``` function default_settings() { CT_TYPE="1" PW="" CT_ID=$NEXTID HN=$NSAPP DISK_SIZE="$var_disk" CORE_COUNT="$var_cpu" RAM_SIZE="$var_ram" BRG="vmbr0" NET="dhcp" GATE="" APT_CACHER="" APT_CACHER_IP="" DISABLEIP6="no" MTU="" SD="" NS="" MAC="" VLAN="" SSH="no" VERB="no" echo_default } ``` to ``` function default_settings() { CT_ID=$NEXTID HN=$NSAPP DISK_SIZE="$var_disk" CORE_COUNT="$var_cpu" RAM_SIZE="$var_ram" echo_default } ``` and in case a script needs to overwrite an additional setting, simply add it back, like this: ``` function default_settings() { CT_ID=$NEXTID HN=$NSAPP DISK_SIZE="$var_disk" CORE_COUNT="$var_cpu" RAM_SIZE="$var_ram" DISABLEIP6="yes" VERB="yes" echo_default } ``` I've been using this in my fork for some time. It's great when you need to add a new default variable, you don't need to update back all the scripts. Plus, it's good practice to avoid duplication of information. ## Type of change Please check the relevant option(s): - [ ] Bug fix (non-breaking change that resolves an issue) - [X] New feature (non-breaking change that adds functionality) - [ ] Breaking change (a fix or feature that would cause existing functionality to change unexpectedly) - [ ] New script (a fully functional and thoroughly tested script or set of scripts.) ## Prerequisites The following efforts must be made for the PR to be considered. Please check when completed: - [X] Self-review performed (I have reviewed my code, ensuring it follows established patterns and conventions) - [X] Testing performed (I have tested my changes, ensuring everything works as expected) - [ ] Documentation updated (I have updated any relevant documentation) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-26 13:31:01 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ProxmoxVE#2684
No description provided.