vagrant-softlayer 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,229 +1,246 @@
1
- require "ostruct"
2
-
3
- module VagrantPlugins
4
- module SoftLayer
5
- class Config < Vagrant.plugin("2", :config)
6
- # The API key to access SoftLayer.
7
- attr_accessor :api_key
8
-
9
- # The endpoint SoftLayer API url.
10
- attr_accessor :endpoint_url
11
-
12
- # The username to access SoftLayer.
13
- attr_accessor :username
14
-
15
- # The datacenter shortname.
16
- attr_accessor :datacenter
17
-
18
- # Whether to allocate a dedicated instance.
19
- attr_accessor :dedicated
20
-
21
- # The domain of the instance.
22
- attr_accessor :domain
23
-
24
- # The hostname of the instance.
25
- attr_accessor :hostname
26
-
27
- # The billing type of the instance (true for hourly, false for monthly).
28
- attr_accessor :hourly_billing
29
-
30
- # The disk type of the instance (true for local, false for SAN).
31
- attr_accessor :local_disk
32
-
33
- # The amount of RAM of the instance.
34
- attr_accessor :max_memory
35
-
36
- # Network port speed in Mbps.
37
- attr_accessor :network_speed
38
-
39
- # The instance operating system identifier.
40
- attr_accessor :operating_system
41
-
42
- # URI of post-install script to download.
43
- attr_accessor :post_install
44
-
45
- # Whether or not the instance only has access to the private network.
46
- attr_accessor :private_only
47
-
48
- # The id or name of the ssh key to be provisioned.
49
- attr_accessor :ssh_key
50
-
51
- # The number of processors of the instance.
52
- attr_accessor :start_cpus
53
-
54
- # User defined metadata string.
55
- attr_accessor :user_data
56
-
57
- # The ID of the private VLAN.
58
- attr_accessor :vlan_private
59
-
60
- # The ID of the public VLAN.
61
- attr_accessor :vlan_public
62
-
63
- # The load balancers service groups to join.
64
- attr_reader :load_balancers
65
-
66
- # Automatically update DNS on create and destroy.
67
- attr_accessor :manage_dns
68
-
69
- def initialize
70
- @api_key = UNSET_VALUE
71
- @endpoint_url = UNSET_VALUE
72
- @username = UNSET_VALUE
73
-
74
- @datacenter = UNSET_VALUE
75
- @dedicated = UNSET_VALUE
76
- @domain = UNSET_VALUE
77
- @hostname = UNSET_VALUE
78
- @hourly_billing = UNSET_VALUE
79
- @local_disk = UNSET_VALUE
80
- @max_memory = UNSET_VALUE
81
- @network_speed = UNSET_VALUE
82
- @operating_system = UNSET_VALUE
83
- @post_install = UNSET_VALUE
84
- @private_only = UNSET_VALUE
85
- @ssh_key = UNSET_VALUE
86
- @start_cpus = UNSET_VALUE
87
- @user_data = UNSET_VALUE
88
- @vlan_private = UNSET_VALUE
89
- @vlan_public = UNSET_VALUE
90
-
91
- @load_balancers = []
92
- @manage_dns = UNSET_VALUE
93
- end
94
-
95
- # Set the load balancer service group to join.
96
- #
97
- # Available options:
98
- #
99
- # :method => Routing method. Default to round robin.
100
- # :port => Load balancer virtual port.
101
- # :type => Routing type. Default to TCP.
102
- # :vip => Load balancer virtual IP address.
103
- #
104
- # An optional block will accept parameters for the
105
- # balanced service. Available parameters:
106
- #
107
- # :destination_port => TCP port on the node.
108
- # :health_check => Service health check. Default to ping.
109
- # :weight => Service weight. Default to 1.
110
- #
111
- def join_load_balancer(opts = {}, &block)
112
- # Defaults
113
- opts[:method] ||= "ROUND ROBIN"
114
- opts[:type] ||= "TCP"
115
- opts[:service] = OpenStruct.new(:destination_port => nil, :health_check => "PING", :weight => 1)
116
-
117
- yield opts[:service] if block_given?
118
-
119
- # Convert all options that belongs to
120
- # an enumeration in uppercase.
121
- opts[:method].upcase!
122
- opts[:type].upcase!
123
- opts[:service].health_check.upcase!
124
-
125
- @load_balancers << opts
126
- end
127
-
128
- def finalize!
129
- # Try to get username and api key from environment variables.
130
- # They will default to nil if the environment variables are not present.
131
- @api_key = ENV["SL_API_KEY"] if @api_key == UNSET_VALUE
132
- @username = ENV["SL_USERNAME"] if @username == UNSET_VALUE
133
-
134
- # Endpoint url defaults to public SoftLayer API url.
135
- @endpoint_url = API_PUBLIC_ENDPOINT if @endpoint_url == UNSET_VALUE
136
-
137
- # No default datacenter.
138
- @datacenter = nil if @datacenter == UNSET_VALUE
139
-
140
- # Shared instance by default.
141
- @dedicated = false if @dedicated == UNSET_VALUE
142
-
143
- # Domain should be specified in Vagrantfile, so we set default to nil.
144
- @domain = nil if @domain == UNSET_VALUE
145
-
146
- # Hostname should be specified in Vagrantfile, either using `config.vm.hostname`
147
- # or the provider specific configuration entry.
148
- @hostname = nil if @hostname == UNSET_VALUE
149
-
150
- # Bill hourly by default.
151
- @hourly_billing = true if @hourly_billing == UNSET_VALUE
152
-
153
- # Use local disk by default.
154
- @local_disk = true if @local_disk == UNSET_VALUE
155
-
156
- # 1Gb of RAM by default.
157
- @max_memory = 1024 if @max_memory == UNSET_VALUE
158
-
159
- # 10Mbps by default.
160
- @network_speed = 10 if @network_speed == UNSET_VALUE
161
-
162
- # Provision with the latest Ubuntu by default.
163
- @operating_system = "UBUNTU_LATEST" if @operating_system == UNSET_VALUE
164
-
165
- # No post install script by default.
166
- @post_install = nil if @post_install == UNSET_VALUE
167
-
168
- # Private-network only is false by default.
169
- @private_only = false if @private_only == UNSET_VALUE
170
-
171
- # SSH key should be specified in Vagrantfile, so we set default to nil.
172
- @ssh_key = nil if @ssh_key == UNSET_VALUE
173
-
174
- # One processor by default.
175
- @start_cpus = 1 if @start_cpus == UNSET_VALUE
176
-
177
- # No user metadata by default.
178
- @user_data = nil if @user_data == UNSET_VALUE
179
-
180
- # No specific private VLAN by default.
181
- @vlan_private = nil if @vlan_private == UNSET_VALUE
182
-
183
- # No specific public VLAN by default.
184
- @vlan_public = nil if @vlan_public == UNSET_VALUE
185
-
186
- # DNS management off by default
187
- @manage_dns = false if @manage_dns == UNSET_VALUE
188
- end
189
-
190
- # Aliases for ssh_key for beautiful semantic.
191
- def ssh_keys=(value)
192
- @ssh_key = value
193
- end
194
- alias_method :ssh_key_id=, :ssh_keys=
195
- alias_method :ssh_key_ids=, :ssh_keys=
196
- alias_method :ssh_key_name=, :ssh_keys=
197
- alias_method :ssh_key_names=, :ssh_keys=
198
-
199
- def validate(machine)
200
- errors = []
201
-
202
- errors << I18n.t("vagrant_softlayer.config.api_key_required") if !@api_key
203
- errors << I18n.t("vagrant_softlayer.config.username_required") if !@username
204
-
205
- errors << I18n.t("vagrant_softlayer.config.domain_required") if !@domain
206
- errors << I18n.t("vagrant_softlayer.config.ssh_key_required") if !@ssh_key
207
-
208
- # Fail if both `vm.hostname` and `provider.hostname` are nil.
209
- if !@hostname && !machine.config.vm.hostname
210
- errors << I18n.t("vagrant_softlayer.config.hostname_required")
211
- end
212
-
213
- # Fail if a load balancer has been specified without vip, port or destination port.
214
- unless @load_balancers.empty?
215
- @load_balancers.each do |lb|
216
- errors << I18n.t("vagrant_softlayer.config.lb_port_vip_required") unless (lb[:vip] && lb[:port] && lb[:service].destination_port)
217
- end
218
- end
219
-
220
- # Fail if two or more load balancers has been specified with same vip and port.
221
- if @load_balancers.map { |lb| { :port => lb[:port], :vip => lb[:vip] } }.uniq!
222
- errors << I18n.t("vagrant_softlayer.config.lb_duplicate")
223
- end
224
-
225
- { "SoftLayer" => errors }
226
- end
227
- end
228
- end
229
- end
1
+ require "ostruct"
2
+
3
+ module VagrantPlugins
4
+ module SoftLayer
5
+ class Config < Vagrant.plugin("2", :config)
6
+ # The API key to access SoftLayer.
7
+ attr_accessor :api_key
8
+
9
+ # The endpoint SoftLayer API url.
10
+ attr_accessor :endpoint_url
11
+
12
+ # The username to access SoftLayer.
13
+ attr_accessor :username
14
+
15
+ # The datacenter shortname.
16
+ attr_accessor :datacenter
17
+
18
+ # Whether to allocate a dedicated instance.
19
+ attr_accessor :dedicated
20
+
21
+ # The disk image capacity
22
+ attr_accessor :disk_capacity
23
+
24
+ # The domain of the instance.
25
+ attr_accessor :domain
26
+
27
+ # The hostname of the instance.
28
+ attr_accessor :hostname
29
+
30
+ # The billing type of the instance (true for hourly, false for monthly).
31
+ attr_accessor :hourly_billing
32
+
33
+ # The global identifier of the compute or flex image to use.
34
+ attr_accessor :image_guid
35
+
36
+ # The disk type of the instance (true for local, false for SAN).
37
+ attr_accessor :local_disk
38
+
39
+ # The amount of RAM of the instance.
40
+ attr_accessor :max_memory
41
+
42
+ # Network port speed in Mbps.
43
+ attr_accessor :network_speed
44
+
45
+ # The instance operating system identifier.
46
+ attr_accessor :operating_system
47
+
48
+ # URI of post-install script to download.
49
+ attr_accessor :post_install
50
+
51
+ # Whether or not the instance only has access to the private network.
52
+ attr_accessor :private_only
53
+
54
+ # The id or name of the ssh key to be provisioned.
55
+ attr_accessor :ssh_key
56
+
57
+ # The number of processors of the instance.
58
+ attr_accessor :start_cpus
59
+
60
+ # User defined metadata string.
61
+ attr_accessor :user_data
62
+
63
+ # The ID of the private VLAN.
64
+ attr_accessor :vlan_private
65
+
66
+ # The ID of the public VLAN.
67
+ attr_accessor :vlan_public
68
+
69
+ # The load balancers service groups to join.
70
+ attr_reader :load_balancers
71
+
72
+ # Automatically update DNS on create and destroy.
73
+ attr_accessor :manage_dns
74
+
75
+ def initialize
76
+ @api_key = UNSET_VALUE
77
+ @endpoint_url = UNSET_VALUE
78
+ @username = UNSET_VALUE
79
+
80
+ @datacenter = UNSET_VALUE
81
+ @dedicated = UNSET_VALUE
82
+ @disk_capacity = UNSET_VALUE
83
+ @domain = UNSET_VALUE
84
+ @hostname = UNSET_VALUE
85
+ @image_guid = UNSET_VALUE
86
+ @hourly_billing = UNSET_VALUE
87
+ @local_disk = UNSET_VALUE
88
+ @max_memory = UNSET_VALUE
89
+ @network_speed = UNSET_VALUE
90
+ @operating_system = UNSET_VALUE
91
+ @post_install = UNSET_VALUE
92
+ @private_only = UNSET_VALUE
93
+ @ssh_key = UNSET_VALUE
94
+ @start_cpus = UNSET_VALUE
95
+ @user_data = UNSET_VALUE
96
+ @vlan_private = UNSET_VALUE
97
+ @vlan_public = UNSET_VALUE
98
+
99
+ @load_balancers = []
100
+ @manage_dns = UNSET_VALUE
101
+ end
102
+
103
+ # Set the load balancer service group to join.
104
+ #
105
+ # Available options:
106
+ #
107
+ # :method => Routing method. Default to round robin.
108
+ # :port => Load balancer virtual port.
109
+ # :type => Routing type. Default to TCP.
110
+ # :vip => Load balancer virtual IP address.
111
+ #
112
+ # An optional block will accept parameters for the
113
+ # balanced service. Available parameters:
114
+ #
115
+ # :destination_port => TCP port on the node.
116
+ # :health_check => Service health check. Default to ping.
117
+ # :weight => Service weight. Default to 1.
118
+ #
119
+ def join_load_balancer(opts = {}, &block)
120
+ # Defaults
121
+ opts[:method] ||= "ROUND ROBIN"
122
+ opts[:type] ||= "TCP"
123
+ opts[:service] = OpenStruct.new(:destination_port => nil, :health_check => "PING", :weight => 1)
124
+
125
+ yield opts[:service] if block_given?
126
+
127
+ # Convert all options that belongs to
128
+ # an enumeration in uppercase.
129
+ opts[:method].upcase!
130
+ opts[:type].upcase!
131
+ opts[:service].health_check.upcase!
132
+
133
+ @load_balancers << opts
134
+ end
135
+
136
+ def finalize!
137
+ # Try to get username and api key from environment variables.
138
+ # They will default to nil if the environment variables are not present.
139
+ @api_key = ENV["SL_API_KEY"] if @api_key == UNSET_VALUE
140
+ @username = ENV["SL_USERNAME"] if @username == UNSET_VALUE
141
+
142
+ # Endpoint url defaults to public SoftLayer API url.
143
+ @endpoint_url = API_PUBLIC_ENDPOINT if @endpoint_url == UNSET_VALUE
144
+
145
+ # No default datacenter.
146
+ @datacenter = nil if @datacenter == UNSET_VALUE
147
+
148
+ # Shared instance by default.
149
+ @dedicated = false if @dedicated == UNSET_VALUE
150
+
151
+ # 25GB disk capacity image by default.
152
+ @disk_capacity = nil if @disk_capacity == UNSET_VALUE
153
+
154
+ # Domain should be specified in Vagrantfile, so we set default to nil.
155
+ @domain = nil if @domain == UNSET_VALUE
156
+
157
+ # Hostname should be specified in Vagrantfile, either using `config.vm.hostname`
158
+ # or the provider specific configuration entry.
159
+ @hostname = nil if @hostname == UNSET_VALUE
160
+
161
+ # Bill hourly by default.
162
+ @hourly_billing = true if @hourly_billing == UNSET_VALUE
163
+
164
+ # Disable the use of a specific block device image so we can leave the OS template as default
165
+ @image_guid = nil if @image_guid == UNSET_VALUE
166
+
167
+ # Use local disk by default.
168
+ @local_disk = true if @local_disk == UNSET_VALUE
169
+
170
+ # 1Gb of RAM by default.
171
+ @max_memory = 1024 if @max_memory == UNSET_VALUE
172
+
173
+ # 10Mbps by default.
174
+ @network_speed = 10 if @network_speed == UNSET_VALUE
175
+
176
+ # Provision with the latest Ubuntu by default.
177
+ @operating_system = "UBUNTU_LATEST" if @operating_system == UNSET_VALUE
178
+
179
+ # No post install script by default.
180
+ @post_install = nil if @post_install == UNSET_VALUE
181
+
182
+ # Private-network only is false by default.
183
+ @private_only = false if @private_only == UNSET_VALUE
184
+
185
+ # SSH key should be specified in Vagrantfile, so we set default to nil.
186
+ @ssh_key = nil if @ssh_key == UNSET_VALUE
187
+
188
+ # One processor by default.
189
+ @start_cpus = 1 if @start_cpus == UNSET_VALUE
190
+
191
+ # No user metadata by default.
192
+ @user_data = nil if @user_data == UNSET_VALUE
193
+
194
+ # No specific private VLAN by default.
195
+ @vlan_private = nil if @vlan_private == UNSET_VALUE
196
+
197
+ # No specific public VLAN by default.
198
+ @vlan_public = nil if @vlan_public == UNSET_VALUE
199
+
200
+ # DNS management off by default
201
+ @manage_dns = false if @manage_dns == UNSET_VALUE
202
+ end
203
+
204
+ # Aliases for ssh_key for beautiful semantic.
205
+ def ssh_keys=(value)
206
+ @ssh_key = value
207
+ end
208
+ alias_method :ssh_key_id=, :ssh_keys=
209
+ alias_method :ssh_key_ids=, :ssh_keys=
210
+ alias_method :ssh_key_name=, :ssh_keys=
211
+ alias_method :ssh_key_names=, :ssh_keys=
212
+
213
+ def validate(machine)
214
+ errors = []
215
+
216
+ errors << I18n.t("vagrant_softlayer.config.api_key_required") if !@api_key
217
+ errors << I18n.t("vagrant_softlayer.config.username_required") if !@username
218
+
219
+ errors << I18n.t("vagrant_softlayer.config.domain_required") if !@domain
220
+ errors << I18n.t("vagrant_softlayer.config.ssh_key_required") if !@ssh_key
221
+
222
+ errors << I18n.t("vagrant_softlayer.config.img_guid_os_code_mutually_exclusive") if @image_guid && @operating_system
223
+ errors << I18n.t("vagrant_softlayer.config.img_guid_capacity_mutually_exclusive") if @image_guid && @disk_capacity
224
+
225
+ # Fail if both `vm.hostname` and `provider.hostname` are nil.
226
+ if !@hostname && !machine.config.vm.hostname
227
+ errors << I18n.t("vagrant_softlayer.config.hostname_required")
228
+ end
229
+
230
+ # Fail if a load balancer has been specified without vip, port or destination port.
231
+ unless @load_balancers.empty?
232
+ @load_balancers.each do |lb|
233
+ errors << I18n.t("vagrant_softlayer.config.lb_port_vip_required") unless (lb[:vip] && lb[:port] && lb[:service].destination_port)
234
+ end
235
+ end
236
+
237
+ # Fail if two or more load balancers has been specified with same vip and port.
238
+ if @load_balancers.map { |lb| { :port => lb[:port], :vip => lb[:vip] } }.uniq!
239
+ errors << I18n.t("vagrant_softlayer.config.lb_duplicate")
240
+ end
241
+
242
+ { "SoftLayer" => errors }
243
+ end
244
+ end
245
+ end
246
+ end
@@ -1,5 +1,5 @@
1
- module VagrantPlugins
2
- module SoftLayer
3
- VERSION = "0.2.0"
4
- end
5
- end
1
+ module VagrantPlugins
2
+ module SoftLayer
3
+ VERSION = "0.3.0"
4
+ end
5
+ end