Class: VagrantPlugins::StartCloud::Action::LoadConfig
- Inherits:
-
Object
- Object
- VagrantPlugins::StartCloud::Action::LoadConfig
- Defined in:
- lib/vagrant-startcloud/action/load_config.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, _env) ⇒ LoadConfig
constructor
A new instance of LoadConfig.
Constructor Details
#initialize(app, _env) ⇒ LoadConfig
Returns a new instance of LoadConfig.
9 10 11 |
# File 'lib/vagrant-startcloud/action/load_config.rb', line 9 def initialize(app, _env) @app = app end |
Instance Method Details
#call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vagrant-startcloud/action/load_config.rb', line 13 def call(env) machine = env[:machine] config = machine.config.startcloud if config.config_path && File.file?(config.config_path) yaml_config = YAML.load_file(config.config_path) host = yaml_config['hosts']&.find do |h| name = "#{h['settings']['server_id']}--#{h['settings']['hostname']}.#{h['settings']['domain']}" name == machine.name.to_s end if host config.settings = host['settings'] config.networks = host['networks'] || [] config.disks = host['disks'] || {} config.provisioning = host['provisioning'] || {} config.folders = host['folders'] || [] config.roles = host['roles'] || [] config.vars = host['vars'] || {} config.plugins = host['plugins'] || {} config.zones = host['zones'] || {} env[:ui].info(I18n.t('vagrant_startcloud.config.loaded', name: machine.name)) else env[:ui].warn(I18n.t('vagrant_startcloud.config.machine_not_found', name: machine.name)) end else env[:ui].warn(I18n.t('vagrant_startcloud.config.not_found', path: config.config_path)) end @app.call(env) end |