Class: VagrantPlugins::ProviderLibvirt::Action::SetNameOfDomain

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-libvirt/action/set_name_of_domain.rb

Overview

Setup name for domain and domain volumes.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ SetNameOfDomain

Returns a new instance of SetNameOfDomain.



7
8
9
10
# File 'lib/vagrant-libvirt/action/set_name_of_domain.rb', line 7

def initialize(app, env)
  @logger     = Log4r::Logger.new("vagrant_libvirt::action::set_name_of_domain")
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
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
# File 'lib/vagrant-libvirt/action/set_name_of_domain.rb', line 12

def call(env)
  require 'securerandom'
  config = env[:machine].provider_config
  if config.default_prefix.nil?
    env[:domain_name] = env[:root_path].basename.to_s.dup
  else
    env[:domain_name] = config.default_prefix.to_s
  end
  env[:domain_name].gsub!(/[^-a-z0-9_]/i, '')
  env[:domain_name] << '_'
  env[:domain_name] << env[:machine].name.to_s
  
  begin
  @logger.info("Looking for domain #{env[:domain_name]} through list #{env[:libvirt_compute].servers.all}")
  # Check if the domain name is not already taken
  
    domain = ProviderLibvirt::Util::Collection.find_matching(
    env[:libvirt_compute].servers.all, env[:domain_name])
  rescue Fog::Errors::Error => e
    @logger.info("#{e}")
    domain = nil
  end

  @logger.info("Looking for domain #{env[:domain_name]}")

  if domain != nil
    raise ProviderLibvirt::Errors::DomainNameExists,
      :domain_name => env[:domain_name]
  end

  @app.call(env)
end