Class: VagrantPlugins::StartCloud::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::StartCloud::Config
- Defined in:
- lib/vagrant-startcloud/config.rb
Instance Attribute Summary collapse
-
#config_path ⇒ Object
Returns the value of attribute config_path.
-
#disks ⇒ Object
Returns the value of attribute disks.
-
#folders ⇒ Object
Returns the value of attribute folders.
-
#networks ⇒ Object
Returns the value of attribute networks.
-
#plugins ⇒ Object
Returns the value of attribute plugins.
-
#provisioning ⇒ Object
Returns the value of attribute provisioning.
-
#roles ⇒ Object
Returns the value of attribute roles.
-
#settings ⇒ Object
Returns the value of attribute settings.
-
#vars ⇒ Object
Returns the value of attribute vars.
-
#zones ⇒ Object
Returns the value of attribute zones.
Instance Method Summary collapse
- #finalize! ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_config(machine) ⇒ Object
- #validate(_machine) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/vagrant-startcloud/config.rb', line 8 def initialize super @config_path = UNSET_VALUE @settings = {} @networks = [] @disks = {} @provisioning = {} @folders = [] @roles = [] @vars = {} @plugins = {} @zones = {} end |
Instance Attribute Details
#config_path ⇒ Object
Returns the value of attribute config_path.
6 7 8 |
# File 'lib/vagrant-startcloud/config.rb', line 6 def config_path @config_path end |
#disks ⇒ Object
Returns the value of attribute disks.
6 7 8 |
# File 'lib/vagrant-startcloud/config.rb', line 6 def disks @disks end |
#folders ⇒ Object
Returns the value of attribute folders.
6 7 8 |
# File 'lib/vagrant-startcloud/config.rb', line 6 def folders @folders end |
#networks ⇒ Object
Returns the value of attribute networks.
6 7 8 |
# File 'lib/vagrant-startcloud/config.rb', line 6 def networks @networks end |
#plugins ⇒ Object
Returns the value of attribute plugins.
6 7 8 |
# File 'lib/vagrant-startcloud/config.rb', line 6 def plugins @plugins end |
#provisioning ⇒ Object
Returns the value of attribute provisioning.
6 7 8 |
# File 'lib/vagrant-startcloud/config.rb', line 6 def provisioning @provisioning end |
#roles ⇒ Object
Returns the value of attribute roles.
6 7 8 |
# File 'lib/vagrant-startcloud/config.rb', line 6 def roles @roles end |
#settings ⇒ Object
Returns the value of attribute settings.
6 7 8 |
# File 'lib/vagrant-startcloud/config.rb', line 6 def settings @settings end |
#vars ⇒ Object
Returns the value of attribute vars.
6 7 8 |
# File 'lib/vagrant-startcloud/config.rb', line 6 def vars @vars end |
#zones ⇒ Object
Returns the value of attribute zones.
6 7 8 |
# File 'lib/vagrant-startcloud/config.rb', line 6 def zones @zones end |
Instance Method Details
#finalize! ⇒ Object
22 23 24 |
# File 'lib/vagrant-startcloud/config.rb', line 22 def finalize! @config_path = nil if @config_path == UNSET_VALUE end |
#load_config(machine) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vagrant-startcloud/config.rb', line 43 def load_config(machine) return unless @config_path && File.exist?(@config_path) begin yaml_config = YAML.load_file(@config_path) return unless yaml_config && yaml_config['hosts'] host = yaml_config['hosts'].first # Load all configuration sections @settings = host['settings'] || {} @networks = host['networks'] || [] @disks = host['disks'] || {} @provisioning = host['provisioning'] || {} @folders = host['folders'] || [] @roles = host['roles'] || [] @vars = host['vars'] || {} @plugins = host['plugins'] || {} @zones = host['zones'] || {} # Configure plugins if specified configure_plugins(host['plugins']) if host['plugins'] # Configure provider-specific settings configure_provider(machine, host) if @settings['provider_type'] rescue StandardError => e raise Errors::YAMLParseError, _key: :yaml_error, error: e. end end |
#validate(_machine) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vagrant-startcloud/config.rb', line 26 def validate(_machine) errors = _detected_errors errors << "Configuration file '#{@config_path}' does not exist" if @config_path && !File.exist?(@config_path) if @settings.empty? errors << 'No settings defined in configuration' return { 'StartCloud configuration' => errors } end required_settings = %w[hostname domain server_id box] missing_settings = required_settings - @settings.keys errors << "Missing required settings: #{missing_settings.join(', ')}" unless missing_settings.empty? { 'StartCloud configuration' => errors } end |