Class: VagrantPlugins::Linode::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/vagrant-linode/config.rb', line 33

def initialize
  # @logger  = Log4r::Logger.new('vagrant::linode::config')

  @token              = UNSET_VALUE
  @api_key            = UNSET_VALUE
  @api_url            = UNSET_VALUE
  @distributionid     = UNSET_VALUE
  @distribution       = UNSET_VALUE
  @stackscriptid      = UNSET_VALUE
  @stackscript        = UNSET_VALUE
  @stackscript_udf_responses = UNSET_VALUE
  @imageid            = UNSET_VALUE
  @image              = UNSET_VALUE
  @datacenterid       = UNSET_VALUE
  @datacenter         = UNSET_VALUE
  @planid             = UNSET_VALUE
  @plan               = UNSET_VALUE
  @paymentterm        = UNSET_VALUE
  @private_networking = UNSET_VALUE
  @ca_path            = UNSET_VALUE
  @ssh_key_name       = UNSET_VALUE
  @setup              = UNSET_VALUE
  @xvda_size          = UNSET_VALUE
  @swap_size          = UNSET_VALUE
  @kernelid           = UNSET_VALUE
  @kernel             = UNSET_VALUE
  @label              = UNSET_VALUE
  @group              = UNSET_VALUE
  @volumes            = UNSET_VALUE
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#api_urlObject

Returns the value of attribute api_url.



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

def api_url
  @api_url
end

#ca_pathObject

Returns the value of attribute ca_path.



17
18
19
# File 'lib/vagrant-linode/config.rb', line 17

def ca_path
  @ca_path
end

#datacenterObject

Returns the value of attribute datacenter.



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

def datacenter
  @datacenter
end

#datacenteridObject

Returns the value of attribute datacenterid.



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

def datacenterid
  @datacenterid
end

#distributionObject

Returns the value of attribute distribution.



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

def distribution
  @distribution
end

#distributionidObject

Returns the value of attribute distributionid.



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

def distributionid
  @distributionid
end

#groupObject

Returns the value of attribute group.



28
29
30
# File 'lib/vagrant-linode/config.rb', line 28

def group
  @group
end

#imageObject

Returns the value of attribute image.



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

def image
  @image
end

#imageidObject

Returns the value of attribute imageid.



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

def imageid
  @imageid
end

#kernelObject

Returns the value of attribute kernel.



26
27
28
# File 'lib/vagrant-linode/config.rb', line 26

def kernel
  @kernel
end

#kernelidObject

Returns the value of attribute kernelid.



25
26
27
# File 'lib/vagrant-linode/config.rb', line 25

def kernelid
  @kernelid
end

#labelObject

Returns the value of attribute label.



27
28
29
# File 'lib/vagrant-linode/config.rb', line 27

def label
  @label
end

#paymenttermObject

Returns the value of attribute paymentterm.



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

def paymentterm
  @paymentterm
end

#planObject

Returns the value of attribute plan.



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

def plan
  @plan
end

#planidObject

Returns the value of attribute planid.



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

def planid
  @planid
end

#private_networkingObject

Returns the value of attribute private_networking.



16
17
18
# File 'lib/vagrant-linode/config.rb', line 16

def private_networking
  @private_networking
end

#setupObject Also known as: setup?

Returns the value of attribute setup.



19
20
21
# File 'lib/vagrant-linode/config.rb', line 19

def setup
  @setup
end

#ssh_key_nameObject

Returns the value of attribute ssh_key_name.



18
19
20
# File 'lib/vagrant-linode/config.rb', line 18

def ssh_key_name
  @ssh_key_name
end

#stackscriptObject

Returns the value of attribute stackscript.



21
22
23
# File 'lib/vagrant-linode/config.rb', line 21

def stackscript
  @stackscript
end

#stackscript_udf_responsesObject

Returns the value of attribute stackscript_udf_responses.



22
23
24
# File 'lib/vagrant-linode/config.rb', line 22

def stackscript_udf_responses
  @stackscript_udf_responses
end

#stackscriptidObject

Returns the value of attribute stackscriptid.



20
21
22
# File 'lib/vagrant-linode/config.rb', line 20

def stackscriptid
  @stackscriptid
end

#swap_sizeObject

Returns the value of attribute swap_size.



24
25
26
# File 'lib/vagrant-linode/config.rb', line 24

def swap_size
  @swap_size
end

#tokenObject

deprecated



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

def token
  @token
end

#volumesObject

Returns the value of attribute volumes.



29
30
31
# File 'lib/vagrant-linode/config.rb', line 29

def volumes
  @volumes
end

#xvda_sizeObject

Returns the value of attribute xvda_size.



23
24
25
# File 'lib/vagrant-linode/config.rb', line 23

def xvda_size
  @xvda_size
end

Instance Method Details

#finalize!Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/vagrant-linode/config.rb', line 64

def finalize!
  @api_key            = ENV['LINODE_API_KEY'] if @api_key == UNSET_VALUE
  @token              = ENV['LINODE_TOKEN'] if @token == UNSET_VALUE
  @api_key            = @token if ((@api_key == nil) and (@token != nil))
  @api_url            = ENV['LINODE_URL'] if @api_url == UNSET_VALUE
  @imageid            = nil if @imageid == UNSET_VALUE
  @image              = nil if @image == UNSET_VALUE
  @distributionid     = nil if @distributionid == UNSET_VALUE
  @distribution       = nil if @distribution == UNSET_VALUE
  @distribution       = 'Ubuntu 16.04 LTS' if @distribution.nil? and @distributionid.nil? and @imageid.nil? and @image.nil?
  @stackscriptid      = nil if @stackscriptid == UNSET_VALUE
  @stackscript        = nil if @stackscript == UNSET_VALUE
  @stackscript_udf_responses = nil if @stackscript_udf_responses == UNSET_VALUE
  @datacenterid       = nil if @datacenterid == UNSET_VALUE
  @datacenter         = nil if @datacenter == UNSET_VALUE
  @datacenter         = 'dallas' if @datacenter.nil? and @datacenterid.nil?
  @planid             = nil if @planid == UNSET_VALUE
  @plan               = nil if @plan == UNSET_VALUE
  @planid             = '1' if @plan.nil? and @planid.nil?
  @paymentterm        = '1' if @paymentterm == UNSET_VALUE
  @private_networking = false if @private_networking == 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
  @xvda_size          = true if @xvda_size == UNSET_VALUE
  @swap_size          = '256' if @swap_size == UNSET_VALUE
  @kernelid           = nil if @kernelid == UNSET_VALUE
  @kernel             = nil if @kernel == UNSET_VALUE
  @kernel             = 'Latest 64 bit' if @kernel.nil? and @kernelid.nil?
  @label              = false if @label == UNSET_VALUE
  @group              = false if @group == UNSET_VALUE
  @volumes            = [] if @volumes == UNSET_VALUE
end

#validate(machine) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/vagrant-linode/config.rb', line 98

def validate(machine)
  errors = []
  errors << I18n.t('vagrant_linode.config.api_key') unless @api_key
  # Log4r::Logger.new('vagrant_linode.config.token') if @token
  # env[:ui].info I18n.t('vagrant_linode.config.token') if @token
  # errors << I18n.t('vagrant_linode.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_linode.config.private_key')
  elsif !File.file?(File.expand_path("#{key}.pub", machine.env.root_path))
    errors << I18n.t('vagrant_linode.config.public_key', key: "#{key}.pub")
  end

  if @distributionid and @distribution
    errors << I18n.t('vagrant_linode.config.distributionid_or_distribution')
  end

  if @stackscriptid and @stackscript
    errors << I18n.t('vagrant_linode.config.stackscriptid_or_stackscript')
  end

  if @datacenterid and @datacenter
    errors << I18n.t('vagrant_linode.config.datacenterid_or_datacenter')
  end

  if @kernelid and @kernel
    errors << I18n.t('vagrant_linode.config.kernelid_or_kernel')
  end

  if @planid and @plan
    errors << I18n.t('vagrant_linode.config.planid_or_plan')
  end

  if @imageid and @image
    errors << I18n.t('vagrant_linode.config.imageid_or_image')
  end

  if (@distribution or @distributionid) and (@imageid or @image)
    errors << I18n.t('vagrant_linode.config.distribution_or_image')
  end

  if !@volumes.is_a? Array
    errors << I18n.t("vagrant_linode.config.volumes")
  end

  { 'Linode Provider' => errors }
end