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

Closed
opened 2025-11-20 05:30:17 -05:00 by saavagebueno · 0 comments
Owner

Original Pull Request: https://github.com/community-scripts/ProxmoxVE/pull/322

State: closed
Merged: No


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)
**Original Pull Request:** https://github.com/community-scripts/ProxmoxVE/pull/322 **State:** closed **Merged:** No --- > [!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)
saavagebueno added the pull-request label 2025-11-20 05:30:17 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SVI/ProxmoxVE#2488