Class: VagrantPlugins::OrbStack::Util::MachineNamer
- Inherits:
-
Object
- Object
- VagrantPlugins::OrbStack::Util::MachineNamer
- Defined in:
- lib/vagrant-orbstack/util/machine_namer.rb
Overview
Utility class for generating unique machine names with collision avoidance
Generates machine names in the format: vagrant-
Constant Summary collapse
- MAX_RETRIES =
Maximum number of retry attempts for collision avoidance
3- MAX_NAME_LENGTH =
Maximum machine name length (DNS hostname limit)
63
Class Method Summary collapse
-
.generate(machine) ⇒ String
Generate a unique machine name with collision avoidance.
Class Method Details
.generate(machine) ⇒ String
Generate a unique machine name with collision avoidance.
Creates a machine name in the format vagrant-
- name is sanitized from machine.name (lowercase, hyphens, alphanumeric)
- id is a 6-character random hex string
If a collision is detected (name already exists in OrbStack), retries with a new random ID up to MAX_RETRIES times.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/vagrant-orbstack/util/machine_namer.rb', line 49 def self.generate(machine) machine_name = machine.name.to_s sanitized = sanitize_name(machine_name) MAX_RETRIES.times do short_id = SecureRandom.hex(3) candidate = "vagrant-#{sanitized}-#{short_id}" return candidate unless check_collision?(candidate) end # All retries exhausted - raise error raise MachineNameCollisionError, "Failed to generate unique machine name after #{MAX_RETRIES} attempts (machine: #{machine_name})" end |