Class: VagrantAWS::Environment

Inherits:
Vagrant::Environment
  • Object
show all
Defined in:
lib/vagrant-aws/environment.rb

Overview

Represents a single Vagrant environment, overridden to not alias with existing Vagrant data storage, VM implementation, etc.

Constant Summary collapse

DEFAULT_DOTFILE =
".vagrantaws"
FOGFILE =
".fog"

Instance Method Summary collapse

Instance Method Details

#aws_home_pathObject



14
15
16
# File 'lib/vagrant-aws/environment.rb', line 14

def aws_home_path
  home_path.join("aws")
end

#boxesObject



22
23
24
25
# File 'lib/vagrant-aws/environment.rb', line 22

def boxes
  return parent.boxes if parent
  @_boxes ||= VagrantAWS::BoxCollection.new(self)
end

#boxes_pathObject



18
19
20
# File 'lib/vagrant-aws/environment.rb', line 18

def boxes_path
	aws_home_path.join("images")
end

#dotfile_pathObject



10
11
12
# File 'lib/vagrant-aws/environment.rb', line 10

def dotfile_path
	root_path.join(DEFAULT_DOTFILE) rescue nil
end

#load!Object



36
37
38
39
40
41
42
43
44
# File 'lib/vagrant-aws/environment.rb', line 36

def load!
	super
	
	# Setup fog credential path
	project_fog_path = root_path.join(FOGFILE) rescue nil
	Fog.credentials_path = File.expand_path(fogfile_path) if project_fog_path && File.exist?(project_fog_path)

	self
end

#load_home_directory!Object

Override to create “AWS” specific directories in ‘home_dir’



47
48
49
50
51
52
53
54
55
56
# File 'lib/vagrant-aws/environment.rb', line 47

def load_home_directory!
	super

	dirs = %w{ images keys }.map { |d| aws_home_path.join(d) }
	dirs.each do |dir|
		next if File.directory?(dir)
		ui.info I18n.t("vagrant.general.creating_home_dir", :directory => dir)
      FileUtils.mkdir_p(dir)
    end	
end

#load_vms!Object

Override to create “AWS” VM



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/vagrant-aws/environment.rb', line 59

def load_vms!
	result = {}

	# Load the VM UUIDs from the local data store
	(local_data[:active] || {}).each do |name, desc|
		result[name.to_sym] = VagrantAWS::VM.find(desc, self, name.to_sym)
	end

	# For any VMs which aren't created, create a blank VM instance for
	# them
	all_keys = config.vm.defined_vm_keys
	all_keys = [DEFAULT_VM] if all_keys.empty?
	all_keys.each do |name|
		result[name] = VagrantAWS::VM.new(:name => name, :env => self) if !result.has_key?(name)
	end

	result
end

#ssh_keysObject



31
32
33
34
# File 'lib/vagrant-aws/environment.rb', line 31

def ssh_keys
	return parent.ssh_keys if parent
	Dir.chdir(ssh_keys_path) { |unused| Dir.entries('.').select { |f| File.file?(f) } }
end

#ssh_keys_pathObject



27
28
29
# File 'lib/vagrant-aws/environment.rb', line 27

def ssh_keys_path
	aws_home_path.join("keys")
end