Class: VagrantPlugins::Openstack::ConfigResolver
- Inherits:
-
Object
- Object
- VagrantPlugins::Openstack::ConfigResolver
- Defined in:
- lib/vagrant-openstack-provider/config_resolver.rb
Instance Method Summary collapse
-
#initialize ⇒ ConfigResolver
constructor
A new instance of ConfigResolver.
- #resolve_flavor(env) ⇒ Object
- #resolve_floating_ip(env) ⇒ Object
- #resolve_image(env) ⇒ Object
- #resolve_keypair(env) ⇒ Object
- #resolve_networks(env) ⇒ Object
- #resolve_security_groups(env) ⇒ Object
- #resolve_ssh_port(env) ⇒ Object
- #resolve_ssh_username(env) ⇒ Object
- #resolve_volume_boot(env) ⇒ Object
- #resolve_volumes(env) ⇒ Object
Constructor Details
#initialize ⇒ ConfigResolver
Returns a new instance of ConfigResolver.
4 5 6 |
# File 'lib/vagrant-openstack-provider/config_resolver.rb', line 4 def initialize @logger = Log4r::Logger.new('vagrant_openstack::action::config_resolver') end |
Instance Method Details
#resolve_flavor(env) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vagrant-openstack-provider/config_resolver.rb', line 14 def resolve_flavor(env) @logger.info 'Resolving flavor' config = env[:machine].provider_config nova = env[:openstack_client].nova env[:ui].info(I18n.t('vagrant_openstack.finding_flavor')) flavors = nova.get_all_flavors(env) @logger.info "Finding flavor matching name '#{config.flavor}'" flavor = find_matching(flavors, config.flavor) fail Errors::NoMatchingFlavor unless flavor flavor end |
#resolve_floating_ip(env) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vagrant-openstack-provider/config_resolver.rb', line 39 def resolve_floating_ip(env) config = env[:machine].provider_config nova = env[:openstack_client].nova return config.floating_ip if config.floating_ip fail Errors::UnableToResolveFloatingIP unless config.floating_ip_pool nova.get_all_floating_ips(env).each do |single| return single.ip if single.pool == config.floating_ip_pool && single.instance_id.nil? end unless config.floating_ip_pool_always_allocate nova.allocate_floating_ip(env, config.floating_ip_pool).ip end |
#resolve_image(env) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vagrant-openstack-provider/config_resolver.rb', line 26 def resolve_image(env) @logger.info 'Resolving image' config = env[:machine].provider_config return nil if config.image.nil? nova = env[:openstack_client].nova env[:ui].info(I18n.t('vagrant_openstack.finding_image')) images = nova.get_all_images(env) @logger.info "Finding image matching name '#{config.image}'" image = find_matching(images, config.image) fail Errors::NoMatchingImage unless image image end |
#resolve_keypair(env) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/vagrant-openstack-provider/config_resolver.rb', line 50 def resolve_keypair(env) config = env[:machine].provider_config nova = env[:openstack_client].nova return config.keypair_name if config.keypair_name return nova.import_keypair_from_file(env, config.public_key_path) if config.public_key_path generate_keypair(env) end |
#resolve_networks(env) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vagrant-openstack-provider/config_resolver.rb', line 58 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_openstack.finding_networks')) return resolve_networks_without_network_service(env) unless env[:openstack_client].session.endpoints.key? :network all_networks = env[:openstack_client].neutron.get_all_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_security_groups(env) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/vagrant-openstack-provider/config_resolver.rb', line 121 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
8 9 10 11 12 |
# File 'lib/vagrant-openstack-provider/config_resolver.rb', line 8 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
113 114 115 116 117 118 119 |
# File 'lib/vagrant-openstack-provider/config_resolver.rb', line 113 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_volume_boot(env) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/vagrant-openstack-provider/config_resolver.rb', line 76 def resolve_volume_boot(env) @logger.info 'Resolving image' config = env[:machine].provider_config return nil if config.volume_boot.nil? return resolve_volume_without_volume_service(env, config.volume_boot, 'vda') unless env[:openstack_client].session.endpoints.key? :volume volume_list = env[:openstack_client].cinder.get_all_volumes(env) volume_ids = volume_list.map { |v| v.id } @logger.debug(volume_list) volume = resolve_volume(config.volume_boot, volume_list, volume_ids) device = volume[:device].nil? ? 'vda' : volume[:device] { id: volume[:id], device: device } end |
#resolve_volumes(env) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/vagrant-openstack-provider/config_resolver.rb', line 93 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_openstack.finding_volumes')) return resolve_volumes_without_volume_service(env) unless env[:openstack_client].session.endpoints.key? :volume volume_list = env[:openstack_client].cinder.get_all_volumes(env) volume_ids = volume_list.map { |v| v.id } @logger.debug(volume_list) volumes = [] config.volumes.each do |volume| volumes << resolve_volume(volume, volume_list, volume_ids) end @logger.debug("Resolved volumes : #{volumes.to_json}") volumes end |