Class: VagrantPlugins::ConoHa::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/vagrant-conoha/config.rb', line 207

def initialize
  @password = UNSET_VALUE
  @openstack_compute_url = UNSET_VALUE
  @openstack_network_url = UNSET_VALUE
  @openstack_volume_url = UNSET_VALUE
  @openstack_orchestration_url = UNSET_VALUE
  @openstack_image_url = UNSET_VALUE
  @openstack_auth_url = UNSET_VALUE
  @endpoint_type = UNSET_VALUE
  @region = UNSET_VALUE
  @flavor = UNSET_VALUE
  @image = UNSET_VALUE
  @volume_boot = UNSET_VALUE
  @tenant_name = UNSET_VALUE
  @server_name = UNSET_VALUE
  @username = UNSET_VALUE
  @rsync_includes = []
  @rsync_ignore_files = []
  @keypair_name = UNSET_VALUE
  @admin_pass   = UNSET_VALUE
  @ssh_username = UNSET_VALUE
  @ssh_timeout = UNSET_VALUE
  @floating_ip = UNSET_VALUE
  @floating_ip_pool = []
  @floating_ip_pool_always_allocate = UNSET_VALUE
  @sync_method = UNSET_VALUE
  @availability_zone = UNSET_VALUE
  @networks = []
  @stacks = []
  @volumes = []
  @public_key_path = UNSET_VALUE
  @scheduler_hints = UNSET_VALUE
  @security_groups = UNSET_VALUE
  @user_data = UNSET_VALUE
  @metadata = UNSET_VALUE
  @ssh_disabled = UNSET_VALUE
  @server_create_timeout = UNSET_VALUE
  @server_active_timeout = UNSET_VALUE
  @server_stop_timeout = UNSET_VALUE
  @server_delete_timeout = UNSET_VALUE
  @stack_create_timeout = UNSET_VALUE
  @stack_delete_timeout = UNSET_VALUE
  @meta_args_support = UNSET_VALUE
  @http = HttpConfig.new
end

Instance Attribute Details

#admin_passString

The unix root password of OpenStack instance.

Returns:

  • (String)


73
74
75
# File 'lib/vagrant-conoha/config.rb', line 73

def admin_pass
  @admin_pass
end

#availability_zoneString

Availability Zone

Returns:

  • (String)


143
144
145
# File 'lib/vagrant-conoha/config.rb', line 143

def availability_zone
  @availability_zone
end

#endpoint_typeString

Specify the endpoint_type to use : publicURL, adminURL, or internalURL (default is publicURL)

Returns:

  • (String)


173
174
175
# File 'lib/vagrant-conoha/config.rb', line 173

def endpoint_type
  @endpoint_type
end

#flavorObject

The flavor of server to launch, either the ID or name. This can also be a regular expression to partially match a name.



40
41
42
# File 'lib/vagrant-conoha/config.rb', line 40

def flavor
  @flavor
end

#floating_ipString

The floating IP address from the IP pool which will be assigned to the instance.

Returns:

  • (String)


96
97
98
# File 'lib/vagrant-conoha/config.rb', line 96

def floating_ip
  @floating_ip
end

#floating_ip_poolString

The floating IP pool from where new IPs will be allocated

Returns:

  • (String)


101
102
103
# File 'lib/vagrant-conoha/config.rb', line 101

def floating_ip_pool
  @floating_ip_pool
end

#floating_ip_pool_always_allocateBoolean

if set to true, vagrant will always allocate floating ip instead of trying to reuse unassigned ones default to false

Returns:

  • (Boolean)


107
108
109
# File 'lib/vagrant-conoha/config.rb', line 107

def floating_ip_pool_always_allocate
  @floating_ip_pool_always_allocate
end

#httpHttpConfig

Returns:



201
202
203
# File 'lib/vagrant-conoha/config.rb', line 201

def http
  @http
end

#imageObject

The name or ID of the image to use. This can also be a regular expression to partially match a name.



44
45
46
# File 'lib/vagrant-conoha/config.rb', line 44

def image
  @image
end

#keypair_nameString

The name of the keypair to use.

Returns:

  • (String)


68
69
70
# File 'lib/vagrant-conoha/config.rb', line 68

def keypair_name
  @keypair_name
end

#meta_args_supportBoolean

Returns:

  • (Boolean)


205
206
207
# File 'lib/vagrant-conoha/config.rb', line 205

def meta_args_support
  @meta_args_support
end

#metadataHash

A Hash of metadata that will be sent to the instance for configuration

Returns:

  • (Hash)


163
164
165
# File 'lib/vagrant-conoha/config.rb', line 163

def 
  @metadata
end

#networksArray

Network list the VM will be connected to

Returns:

  • (Array)


123
124
125
# File 'lib/vagrant-conoha/config.rb', line 123

def networks
  @networks
end

#openstack_auth_urlObject

The authentication endpoint. This defaults to Openstack’s global authentication endpoint.



33
34
35
# File 'lib/vagrant-conoha/config.rb', line 33

def openstack_auth_url
  @openstack_auth_url
end

#openstack_compute_urlObject

The compute service url to access Openstack. If nil, it will read from hypermedia catalog form REST API



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

def openstack_compute_url
  @openstack_compute_url
end

#openstack_image_urlObject

The image service url to access Openstack. If nil, it will read from hypermedia catalog form REST API



30
31
32
# File 'lib/vagrant-conoha/config.rb', line 30

def openstack_image_url
  @openstack_image_url
end

#openstack_network_urlObject

The network service url to access Openstack. If nil, it will read from hypermedia catalog form REST API



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

def openstack_network_url
  @openstack_network_url
end

#openstack_orchestration_urlObject

The orchestration service url to access Openstack. If nil, it will read from hypermedia catalog form REST API



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

def openstack_orchestration_url
  @openstack_orchestration_url
end

#openstack_volume_urlObject

The block storage service url to access Openstack. If nil, it will read from hypermedia catalog form REST API



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

def openstack_volume_url
  @openstack_volume_url
end

#passwordObject

The API key to access Openstack.



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

def password
  @password
end

#public_key_pathArray

Public key path to create OpenStack keypair

Returns:

  • (Array)


138
139
140
# File 'lib/vagrant-conoha/config.rb', line 138

def public_key_path
  @public_key_path
end

#regionObject

Openstack region



36
37
38
# File 'lib/vagrant-conoha/config.rb', line 36

def region
  @region
end

#rsync_ignore_filesArray

Sync folder ignore files. A list of files containing exclude patterns to ignore in the rsync operation

performed by this provider

Returns:

  • (Array)


118
119
120
# File 'lib/vagrant-conoha/config.rb', line 118

def rsync_ignore_files
  @rsync_ignore_files
end

#rsync_includesArray

Opt files/directories in to the rsync operation performed by this provider

Returns:

  • (Array)


91
92
93
# File 'lib/vagrant-conoha/config.rb', line 91

def rsync_includes
  @rsync_includes
end

#scheduler_hintsObject

Pass hints to the OpenStack scheduler, e.g. { “cell”: “some cell name” }



146
147
148
# File 'lib/vagrant-conoha/config.rb', line 146

def scheduler_hints
  @scheduler_hints
end

#security_groupsArray[String]

List of strings representing the security groups to apply. e.g. [‘ssh’, ‘http’]

Returns:

  • (Array[String])


152
153
154
# File 'lib/vagrant-conoha/config.rb', line 152

def security_groups
  @security_groups
end

#server_active_timeoutInteger

Returns:

  • (Integer)


181
182
183
# File 'lib/vagrant-conoha/config.rb', line 181

def server_active_timeout
  @server_active_timeout
end

#server_create_timeoutInteger

Returns:

  • (Integer)


177
178
179
# File 'lib/vagrant-conoha/config.rb', line 177

def server_create_timeout
  @server_create_timeout
end

#server_delete_timeoutInteger

Returns:

  • (Integer)


189
190
191
# File 'lib/vagrant-conoha/config.rb', line 189

def server_delete_timeout
  @server_delete_timeout
end

#server_nameObject

The name of the server. This defaults to the name of the machine defined by Vagrant (via ‘config.vm.define`), but can be overriden here.



58
59
60
# File 'lib/vagrant-conoha/config.rb', line 58

def server_name
  @server_name
end

#server_stop_timeoutInteger

Returns:

  • (Integer)


185
186
187
# File 'lib/vagrant-conoha/config.rb', line 185

def server_stop_timeout
  @server_stop_timeout
end

#ssh_disabledBoolean

Flag to enable/disable all SSH actions (to use for instance on private networks)

Returns:

  • (Boolean)


168
169
170
# File 'lib/vagrant-conoha/config.rb', line 168

def ssh_disabled
  @ssh_disabled
end

#ssh_timeoutInteger

The SSH timeout use after server creation.

Deprecated. Use config.vm.boot_timeout instead.

Returns:

  • (Integer)


86
87
88
# File 'lib/vagrant-conoha/config.rb', line 86

def ssh_timeout
  @ssh_timeout
end

#ssh_usernameString

The SSH username to use with this OpenStack instance. This overrides the ‘config.ssh.username` variable.

Returns:

  • (String)


79
80
81
# File 'lib/vagrant-conoha/config.rb', line 79

def ssh_username
  @ssh_username
end

#stack_create_timeoutInteger

Returns:

  • (Integer)


193
194
195
# File 'lib/vagrant-conoha/config.rb', line 193

def stack_create_timeout
  @stack_create_timeout
end

#stack_delete_timeoutInteger

Returns:

  • (Integer)


197
198
199
# File 'lib/vagrant-conoha/config.rb', line 197

def stack_delete_timeout
  @stack_delete_timeout
end

#stacksArray

Stack that will be created and associated to the instances

Returns:

  • (Array)


133
134
135
# File 'lib/vagrant-conoha/config.rb', line 133

def stacks
  @stacks
end

#sync_methodString

Sync folder method. Can be either “rsync” or “none”

Returns:

  • (String)


112
113
114
# File 'lib/vagrant-conoha/config.rb', line 112

def sync_method
  @sync_method
end

#tenant_nameObject

The name of the openstack project on witch the vm will be created.



53
54
55
# File 'lib/vagrant-conoha/config.rb', line 53

def tenant_name
  @tenant_name
end

#user_dataString

User data to be sent to the newly created OpenStack instance. Use this e.g. to inject a script at boot time.

Returns:

  • (String)


158
159
160
# File 'lib/vagrant-conoha/config.rb', line 158

def user_data
  @user_data
end

#usernameString

The username to access Openstack.

Returns:

  • (String)


63
64
65
# File 'lib/vagrant-conoha/config.rb', line 63

def username
  @username
end

#volume_bootObject

Volume to boot the vm from



48
49
50
# File 'lib/vagrant-conoha/config.rb', line 48

def volume_boot
  @volume_boot
end

#volumesArray

Volumes list that will be attached to the VM

Returns:

  • (Array)


128
129
130
# File 'lib/vagrant-conoha/config.rb', line 128

def volumes
  @volumes
end

Instance Method Details

#finalize!Object

rubocop:disable Metrics/CyclomaticComplexity



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/vagrant-conoha/config.rb', line 292

def finalize!
  @password = nil if @password == UNSET_VALUE
  @openstack_compute_url = nil if @openstack_compute_url == UNSET_VALUE
  @openstack_network_url = nil if @openstack_network_url == UNSET_VALUE
  @openstack_orchestration_url = nil if @openstack_orchestration_url == UNSET_VALUE
  @openstack_volume_url = nil if @openstack_volume_url == UNSET_VALUE
  @openstack_image_url = nil if @openstack_image_url == UNSET_VALUE
  @openstack_auth_url = nil if @openstack_auth_url == UNSET_VALUE
  @endpoint_type = 'publicURL' if @endpoint_type == UNSET_VALUE
  @region = nil if @region == UNSET_VALUE
  @flavor = nil if @flavor == UNSET_VALUE
  @image = nil if @image == UNSET_VALUE
  @volume_boot = nil if @volume_boot == UNSET_VALUE
  @tenant_name = nil if @tenant_name == UNSET_VALUE
  @server_name = nil if @server_name == UNSET_VALUE
  @username = nil if @username == UNSET_VALUE
  @rsync_includes = nil if @rsync_includes.empty?
  @rsync_ignore_files = nil if @rsync_ignore_files.empty?
  @floating_ip = nil if @floating_ip == UNSET_VALUE
  @floating_ip_pool = nil if @floating_ip_pool == UNSET_VALUE
  @floating_ip_pool_always_allocate = false if floating_ip_pool_always_allocate == UNSET_VALUE
  @sync_method = 'rsync' if @sync_method == UNSET_VALUE
  @keypair_name = nil if @keypair_name == UNSET_VALUE
  @admin_pass = nil if @admin_pass == UNSET_VALUE
  @public_key_path = nil if @public_key_path == UNSET_VALUE
  @availability_zone = nil if @availability_zone == UNSET_VALUE
  @scheduler_hints = nil if @scheduler_hints == UNSET_VALUE
  @security_groups = nil if @security_groups == UNSET_VALUE
  @user_data = nil if @user_data == UNSET_VALUE
  @metadata = nil if @metadata == UNSET_VALUE
  @ssh_disabled = false if @ssh_disabled == UNSET_VALUE

  # The SSH values by default are nil, and the top-level config
  # `config.ssh` and `config.vm.boot_timeout` values are used.
  @ssh_username = nil if @ssh_username == UNSET_VALUE
  @ssh_timeout = nil if @ssh_timeout == UNSET_VALUE

  @server_create_timeout = 200 if @server_create_timeout == UNSET_VALUE
  @server_active_timeout = 200 if @server_active_timeout == UNSET_VALUE
  @server_stop_timeout = 200 if @server_stop_timeout == UNSET_VALUE
  @server_delete_timeout = 200 if @server_delete_timeout == UNSET_VALUE
  @stack_create_timeout = 200 if @stack_create_timeout == UNSET_VALUE
  @stack_delete_timeout = 200 if @stack_delete_timeout == UNSET_VALUE
  @meta_args_support = false if @meta_args_support == UNSET_VALUE
  @networks = nil if @networks.empty?
  @volumes = nil if @volumes.empty?
  @stacks = nil if @stacks.empty?
  @http.finalize!
end

#merge(other) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/vagrant-conoha/config.rb', line 253

def merge(other)
  result = self.class.new

  # Set all of our instance variables on the new class
  [self, other].each do |obj|
    obj.instance_variables.each do |key|
      # Ignore keys that start with a double underscore. This allows
      # configuration classes to still hold around internal state
      # that isn't propagated.
      next if key.to_s.start_with?('@__')

      # Let user inputs a string or an array for floating ip pool attribute
      obj.floating_ip_pool = [obj.floating_ip_pool].flatten if key.eql?(:@floating_ip_pool) && !obj.floating_ip_pool.nil?

      # Let user inputs a string or an array for networks attribute
      obj.networks = [obj.networks].flatten if key.eql?(:@networks) && !obj.networks.nil?

      # Don't set the value if it is the unset value, either.
      value = obj.instance_variable_get(key)

      if [:@networks, :@volumes, :@rsync_includes, :@rsync_ignore_files, :@floating_ip_pool, :@stacks].include? key
        result.instance_variable_set(key, value) unless value.empty?
      elsif [:@http].include? key
        result.instance_variable_set(key, instance_variable_get(key).merge(other.instance_variable_get(key))) if value != UNSET_VALUE
      else
        result.instance_variable_set(key, value) if value != UNSET_VALUE
      end
    end
  end

  # Persist through the set of invalid methods
  this_invalid  = @__invalid_methods || Set.new
  other_invalid = other.instance_variable_get(:"@__invalid_methods") || Set.new
  result.instance_variable_set(:"@__invalid_methods", this_invalid + other_invalid)

  result
end

#rsync_include(inc) ⇒ Object

rubocop:enable Metrics/CyclomaticComplexity



343
344
345
# File 'lib/vagrant-conoha/config.rb', line 343

def rsync_include(inc)
  @rsync_includes << inc
end

#validate(machine) ⇒ Object



347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/vagrant-conoha/config.rb', line 347

def validate(machine)
  errors = _detected_errors

  errors << I18n.t('vagrant_openstack.config.password_required') if @password.nil? || @password.empty?
  errors << I18n.t('vagrant_openstack.config.username_required') if @username.nil? || @username.empty?
  errors << I18n.t('vagrant_openstack.config.tenant_name_required') if @tenant_name.nil? || @tenant_name.empty?
  errors << I18n.t('vagrant_openstack.config.invalid_endpoint_type') unless  %w(publicURL adminURL internalURL).include?(@endpoint_type)

  validate_ssh_username(machine, errors)
  validate_stack_config(errors)
  validate_ssh_timeout(errors)
  validate_admin_pass(errors)

  if machine.config.ssh.private_key_path
    puts I18n.t('vagrant_openstack.config.keypair_name_required').yellow unless @keypair_name || @public_key_path
  else
    errors << I18n.t('vagrant_openstack.config.private_key_missing') if @keypair_name || @public_key_path
  end

  {
    openstack_compute_url: @openstack_compute_url,
    openstack_network_url: @openstack_network_url,
    openstack_volume_url: @openstack_volume_url,
    openstack_orchestration_url: @openstack_orchestration_url,
    openstack_image_url: @openstack_image_url,
    openstack_auth_url: @openstack_auth_url
  }.each_pair do |key, value|
    errors << I18n.t('vagrant_openstack.config.invalid_uri', key: key, uri: value) unless value.nil? || valid_uri?(value)
  end

  { 'Openstack Provider' => errors }
end