Class: VagrantAWS::VM

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = nil) ⇒ VM

Copied from Vagrant VM, but modified to generate a VagrantAWS::Environment



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/vagrant-aws/vm.rb', line 42

def initialize(opts=nil)
  defaults = { :vm => nil, :env => nil, :name => nil }

  opts = defaults.merge(opts || {})

  @vm = opts[:vm]
  @connection = @vm.connection if @vm  # Initialize connection from intialized server
			
			@name = opts[:name]

  if !opts[:env].nil?
    # We have an environment, so we create a new child environment
    # specifically for this VM. This step will load any custom
    # config and such.
    @env = VagrantAWS::Environment.new({
      :cwd => opts[:env].cwd,
      :parent => opts[:env],
      :vm => self
    }).load!

    # Load the associated system.
    load_system!
  end

  @loaded_system_distro = false
end

Class Method Details

.find(desc, env = nil, name = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/vagrant-aws/vm.rb', line 26

def find(desc, env=nil, name=nil)
				env.ui.info I18n.t("vagrant.plugins.aws.general.getting_status") if env
				
				vm = Fog::Compute.new(:provider => 'AWS', :region => desc['region']).servers.get(desc['id'])
				my_vm = new(:vm => vm, :env => env, :name => name)
		
				# Recover key configuration values from data store not available from AWS directly
				unless my_vm.env.nil?
					my_vm.env.config.aws.region = desc['region']
				end
				
				my_vm
end

Instance Method Details

#connection(region = nil) ⇒ Object



87
88
89
90
91
92
# File 'lib/vagrant-aws/vm.rb', line 87

def connection(region = nil)
	@connection ||= Fog::Compute.new(
		:provider => 'AWS',
		:region   => region || env.config.aws.region || nil
	)
end

#vm=(value) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/vagrant-aws/vm.rb', line 69

def vm=(value)
  @vm = value
  env.local_data[:active] ||= {}

  if value && value.id
    env.local_data[:active][name.to_s] = {
	'id'     => value.id,
	'region' => value.connection.instance_variable_get(:@region)
}
  else
    env.local_data[:active].delete(name.to_s)
  end

  # Commit the local data so that the next time vagrant is initialized,
  # it realizes the VM exists
  env.local_data.commit
end