Class: VagrantPlugins::Deltacloud::ConfigResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-deltacloud-provider/config_resolver.rb

Instance Method Summary collapse

Constructor Details

#initializeConfigResolver

Returns a new instance of ConfigResolver.



5
6
7
8
# File 'lib/vagrant-deltacloud-provider/config_resolver.rb', line 5

def initialize
  @logger = Log4r::Logger.new('vagrant_deltacloud::action::config_resolver')
  @deltacloud = Deltacloud::DeltacloudClient.instance
end

Instance Method Details

#resolve_hardware_profile(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/vagrant-deltacloud-provider/config_resolver.rb', line 16

def resolve_hardware_profile(env)
  @logger.info 'Resolving hardware profile'
  config = env[:machine].provider_config
  env[:ui].info(I18n.t('vagrant_deltacloud.finding_hardware_profile'))
  hardware_profiles = @deltacloud.list_hardware_profiles(env)
  @logger.info "Finding hardware profile matching name '#{config.hardware_profile}'"
  hardware_profile = find_matching(hardware_profiles, config.hardware_profile)
  fail Errors::NoMatchingHardwareProfile unless hardware_profile
  hardware_profile
end

#resolve_image(env) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vagrant-deltacloud-provider/config_resolver.rb', line 27

def resolve_image(env)
  @logger.info 'Resolving image'
  config = env[:machine].provider_config
  return nil if config.image.nil?
  env[:ui].info(I18n.t('vagrant_deltacloud.finding_image'))
  images = @deltacloud.list_images(env)
  @logger.info "Finding image matching name '#{config.image}'"
  image = find_matching(images, config.image)
  fail Errors::NoMatchingImage unless image
  image
end

#resolve_networks(env) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/vagrant-deltacloud-provider/config_resolver.rb', line 46

def resolve_networks(env)
  @logger.info 'Resolving network(s)'
  config = env[:machine].provider_config
  return [] if config.networks.nil? || config.networks.empty?
  env[:ui].info(I18n.t('vagrant_deltacloud.finding_networks'))
  all_networks = @deltacloud.list_networks(env)
  all_network_ids = all_networks.map { |v| v.id }

  networks = []
  config.networks.each do |network|
    networks << resolve_network(network, all_networks, all_network_ids)
  end
  @logger.debug("Resolved networks : #{networks.to_json}")
  networks
end

#resolve_public_key(env) ⇒ Object



39
40
41
42
43
44
# File 'lib/vagrant-deltacloud-provider/config_resolver.rb', line 39

def resolve_public_key(env)
  config = env[:machine].provider_config
  return config.public_key_name if config.public_key_name
  return @deltacloud.import_public_key_from_file(env, config.public_key_path) if config.public_key_path
  generate_keypair(env)
end

#resolve_security_groups(env) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/vagrant-deltacloud-provider/config_resolver.rb', line 78

def resolve_security_groups(env)
  groups = []
  env[:machine].provider_config.security_groups.each do |group|
    case group
    when String
      groups << { name: group }
    when Hash
      groups << group
    end
  end unless env[:machine].provider_config.security_groups.nil?
  groups
end

#resolve_ssh_port(env) ⇒ Object



10
11
12
13
14
# File 'lib/vagrant-deltacloud-provider/config_resolver.rb', line 10

def resolve_ssh_port(env)
  machine_config = env[:machine].config
  return machine_config.ssh.port if machine_config.ssh.port
  22
end

#resolve_ssh_username(env) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/vagrant-deltacloud-provider/config_resolver.rb', line 70

def resolve_ssh_username(env)
  config = env[:machine].provider_config
  machine_config = env[:machine].config
  return machine_config.ssh.username if machine_config.ssh.username
  return config.ssh_username if config.ssh_username
  fail Errors::NoMatchingSshUsername
end

#resolve_volumes(env) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/vagrant-deltacloud-provider/config_resolver.rb', line 62

def resolve_volumes(env)
  @logger.info 'Resolving volume(s)'
  config = env[:machine].provider_config
  return [] if config.volumes.nil? || config.volumes.empty?
  env[:ui].info(I18n.t('vagrant_deltacloud.finding_volumes'))
  resolve_volumes_without_volume_service(env)
end