Class: VagrantPlugins::OneCloud::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-1cloud/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
29
30
# File 'lib/vagrant-1cloud/config.rb', line 17

def initialize
  @token              = UNSET_VALUE
  @image              = UNSET_VALUE
  @region             = UNSET_VALUE
  @hdd                = UNSET_VALUE
  @hdd_type           = UNSET_VALUE
  @cpu                = UNSET_VALUE
  @ram                = UNSET_VALUE
  @hi_perf            = UNSET_VALUE
  @api_url            = UNSET_VALUE
  @ca_path            = UNSET_VALUE
  @private_net        = UNSET_VALUE
  @ssh_key_name       = UNSET_VALUE
end

Instance Attribute Details

#api_urlObject

Returns the value of attribute api_url.



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

def api_url
  @api_url
end

#ca_pathObject

Returns the value of attribute ca_path.



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

def ca_path
  @ca_path
end

#cpuObject

Returns the value of attribute cpu.



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

def cpu
  @cpu
end

#hddObject

Returns the value of attribute hdd.



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

def hdd
  @hdd
end

#hdd_typeObject

Returns the value of attribute hdd_type.



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

def hdd_type
  @hdd_type
end

#hi_perfObject

Returns the value of attribute hi_perf.



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

def hi_perf
  @hi_perf
end

#imageObject

Returns the value of attribute image.



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

def image
  @image
end

#private_netObject

Returns the value of attribute private_net.



14
15
16
# File 'lib/vagrant-1cloud/config.rb', line 14

def private_net
  @private_net
end

#ramObject

Returns the value of attribute ram.



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

def ram
  @ram
end

#regionObject

Returns the value of attribute region.



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

def region
  @region
end

#ssh_key_nameObject

Returns the value of attribute ssh_key_name.



15
16
17
# File 'lib/vagrant-1cloud/config.rb', line 15

def ssh_key_name
  @ssh_key_name
end

#tokenObject

Returns the value of attribute token.



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

def token
  @token
end

Instance Method Details

#finalize!Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vagrant-1cloud/config.rb', line 32

def finalize!
  @token              = ENV['DO_TOKEN'] if @token == UNSET_VALUE
  @image              = '7' if @image == UNSET_VALUE
  @region             = 'SdnSpb' if @region == UNSET_VALUE
  @hdd                = '10' if @hdd == UNSET_VALUE
  @hdd_type           = 'SAS' if @hdd_type == UNSET_VALUE
  @cpu                = '1' if @cpu == UNSET_VALUE
  @ram                = '512' if @ram == UNSET_VALUE
  @hi_perf            = false if @hi_perf == UNSET_VALUE
  @api_url            = 'https://api.1cloud.ru/' if @api_url == UNSET_VALUE
  @ca_path            = nil if @ca_path == UNSET_VALUE
  @private_net        = nil if @private_net == UNSET_VALUE
  @ssh_key_name       = 'Vagrant' if @ssh_key_name == UNSET_VALUE
end

#validate(machine) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vagrant-1cloud/config.rb', line 47

def validate(machine)
  errors = []
  errors << I18n.t('vagrant_1cloud.config.token') if !@token

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

  { '1cloud Provider' => errors }
end