Class: VagrantPlugins::DigitalOcean::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-digitalocean/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant-digitalocean/config.rb', line 17

def initialize
  @client_id          = UNSET_VALUE
  @api_key            = UNSET_VALUE
  @image              = UNSET_VALUE
  @region             = UNSET_VALUE
  @size               = UNSET_VALUE
  @private_networking = UNSET_VALUE
  @backups_enable     = UNSET_VALUE
  @ca_path            = UNSET_VALUE
  @ssh_key_name       = UNSET_VALUE
  @setup              = UNSET_VALUE
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



5
6
7
# File 'lib/vagrant-digitalocean/config.rb', line 5

def api_key
  @api_key
end

#backups_enabledObject

Returns the value of attribute backups_enabled.



10
11
12
# File 'lib/vagrant-digitalocean/config.rb', line 10

def backups_enabled
  @backups_enabled
end

#ca_pathObject

Returns the value of attribute ca_path.



11
12
13
# File 'lib/vagrant-digitalocean/config.rb', line 11

def ca_path
  @ca_path
end

#client_idObject

Returns the value of attribute client_id.



4
5
6
# File 'lib/vagrant-digitalocean/config.rb', line 4

def client_id
  @client_id
end

#imageObject

Returns the value of attribute image.



6
7
8
# File 'lib/vagrant-digitalocean/config.rb', line 6

def image
  @image
end

#private_networkingObject

Returns the value of attribute private_networking.



9
10
11
# File 'lib/vagrant-digitalocean/config.rb', line 9

def private_networking
  @private_networking
end

#regionObject

Returns the value of attribute region.



7
8
9
# File 'lib/vagrant-digitalocean/config.rb', line 7

def region
  @region
end

#setupObject Also known as: setup?

Returns the value of attribute setup.



13
14
15
# File 'lib/vagrant-digitalocean/config.rb', line 13

def setup
  @setup
end

#sizeObject

Returns the value of attribute size.



8
9
10
# File 'lib/vagrant-digitalocean/config.rb', line 8

def size
  @size
end

#ssh_key_nameObject

Returns the value of attribute ssh_key_name.



12
13
14
# File 'lib/vagrant-digitalocean/config.rb', line 12

def ssh_key_name
  @ssh_key_name
end

Instance Method Details

#finalize!Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vagrant-digitalocean/config.rb', line 30

def finalize!
  @client_id          = ENV['DO_CLIENT_ID'] if @client_id == UNSET_VALUE
  @api_key            = ENV['DO_API_KEY'] if @api_key == UNSET_VALUE
  @image              = 'Ubuntu 12.04.3 x64' if @image == UNSET_VALUE
  @region             = 'New York 2' if @region == UNSET_VALUE
  @size               = '512MB' if @size == UNSET_VALUE
  @private_networking = false if @private_networking == UNSET_VALUE
  @backups_enabled    = false if @backups_enabled == UNSET_VALUE
  @ca_path            = nil if @ca_path == UNSET_VALUE
  @ssh_key_name       = 'Vagrant' if @ssh_key_name == UNSET_VALUE
  @setup              = true if @setup == UNSET_VALUE
end

#validate(machine) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vagrant-digitalocean/config.rb', line 43

def validate(machine)
  errors = []
  errors << I18n.t('vagrant_digital_ocean.config.client_id') if !@client_id
  errors << I18n.t('vagrant_digital_ocean.config.api_key') if !@api_key

  key = machine.config.ssh.private_key_path
				key = key[0] if key.is_a?(Array)
  if !key
    errors << I18n.t('vagrant_digital_ocean.config.private_key')
  elsif !File.file?(File.expand_path("#{key}.pub", machine.env.root_path))
    errors << I18n.t('vagrant_digital_ocean.config.public_key', {
      :key => "#{key}.pub"
    })
  end

  { 'Digital Ocean Provider' => errors }
end