Class: VagrantPlugins::Openstack::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/vagrant-openstack-provider/config.rb', line 163

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
  @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
  @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
end

Instance Attribute Details

#availability_zoneString

Availability Zone

Returns:

  • (String)


136
137
138
# File 'lib/vagrant-openstack-provider/config.rb', line 136

def availability_zone
  @availability_zone
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.



39
40
41
# File 'lib/vagrant-openstack-provider/config.rb', line 39

def flavor
  @flavor
end

#floating_ipString

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

Returns:

  • (String)


89
90
91
# File 'lib/vagrant-openstack-provider/config.rb', line 89

def floating_ip
  @floating_ip
end

#floating_ip_poolString

The floating IP pool from where new IPs will be allocated

Returns:

  • (String)


94
95
96
# File 'lib/vagrant-openstack-provider/config.rb', line 94

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)


100
101
102
# File 'lib/vagrant-openstack-provider/config.rb', line 100

def floating_ip_pool_always_allocate
  @floating_ip_pool_always_allocate
end

#imageObject

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



43
44
45
# File 'lib/vagrant-openstack-provider/config.rb', line 43

def image
  @image
end

#keypair_nameString

The name of the keypair to use.

Returns:

  • (String)


67
68
69
# File 'lib/vagrant-openstack-provider/config.rb', line 67

def keypair_name
  @keypair_name
end

#metadataHash

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

Returns:

  • (Hash)


156
157
158
# File 'lib/vagrant-openstack-provider/config.rb', line 156

def 
  @metadata
end

#networksArray

Network list the VM will be connected to

Returns:

  • (Array)


116
117
118
# File 'lib/vagrant-openstack-provider/config.rb', line 116

def networks
  @networks
end

#openstack_auth_urlObject

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



32
33
34
# File 'lib/vagrant-openstack-provider/config.rb', line 32

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



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

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



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

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



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

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



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

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



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

def openstack_volume_url
  @openstack_volume_url
end

#passwordObject

The API key to access Openstack.



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

def password
  @password
end

#public_key_pathArray

Public key path to create OpenStack keypair

Returns:

  • (Array)


131
132
133
# File 'lib/vagrant-openstack-provider/config.rb', line 131

def public_key_path
  @public_key_path
end

#regionObject

Openstack region



35
36
37
# File 'lib/vagrant-openstack-provider/config.rb', line 35

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)


111
112
113
# File 'lib/vagrant-openstack-provider/config.rb', line 111

def rsync_ignore_files
  @rsync_ignore_files
end

#rsync_includesArray

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

Returns:

  • (Array)


84
85
86
# File 'lib/vagrant-openstack-provider/config.rb', line 84

def rsync_includes
  @rsync_includes
end

#scheduler_hintsObject

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



139
140
141
# File 'lib/vagrant-openstack-provider/config.rb', line 139

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])


145
146
147
# File 'lib/vagrant-openstack-provider/config.rb', line 145

def security_groups
  @security_groups
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.



57
58
59
# File 'lib/vagrant-openstack-provider/config.rb', line 57

def server_name
  @server_name
end

#ssh_disabledBoolean

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

Returns:

  • (Boolean)


161
162
163
# File 'lib/vagrant-openstack-provider/config.rb', line 161

def ssh_disabled
  @ssh_disabled
end

#ssh_timeoutInteger

The SSH timeout use after server creation. If server startup is too long the timeout value can be increase with this variable. Default is 60 seconds

Returns:

  • (Integer)


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

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)


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

def ssh_username
  @ssh_username
end

#stacksArray

Stack that will be created and associated to the instances

Returns:

  • (Array)


126
127
128
# File 'lib/vagrant-openstack-provider/config.rb', line 126

def stacks
  @stacks
end

#sync_methodString

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

Returns:

  • (String)


105
106
107
# File 'lib/vagrant-openstack-provider/config.rb', line 105

def sync_method
  @sync_method
end

#tenant_nameObject

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



52
53
54
# File 'lib/vagrant-openstack-provider/config.rb', line 52

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)


151
152
153
# File 'lib/vagrant-openstack-provider/config.rb', line 151

def user_data
  @user_data
end

#usernameString

The username to access Openstack.

Returns:

  • (String)


62
63
64
# File 'lib/vagrant-openstack-provider/config.rb', line 62

def username
  @username
end

#volume_bootObject

Volume to boot the vm from



47
48
49
# File 'lib/vagrant-openstack-provider/config.rb', line 47

def volume_boot
  @volume_boot
end

#volumesArray

Volumes list that will be attached to the VM

Returns:

  • (Array)


121
122
123
# File 'lib/vagrant-openstack-provider/config.rb', line 121

def volumes
  @volumes
end

Instance Method Details

#finalize!Object

rubocop:disable Style/CyclomaticComplexity



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/vagrant-openstack-provider/config.rb', line 233

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
  @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
  @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` values are used.
  @ssh_username = nil if @ssh_username == UNSET_VALUE
  @ssh_timeout = 180 if @ssh_timeout == UNSET_VALUE
  @networks = nil if @networks.empty?
  @volumes = nil if @volumes.empty?
  @stacks = nil if @stacks.empty?
end

#merge(other) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/vagrant-openstack-provider/config.rb', line 199

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?

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

      if [:@networks, :@volumes, :@rsync_includes, :@ignore_files, :@floating_ip_pool, :@stacks].include? key
        result.instance_variable_set(key, value) unless value.empty?
      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 Style/CyclomaticComplexity



273
274
275
# File 'lib/vagrant-openstack-provider/config.rb', line 273

def rsync_include(inc)
  @rsync_includes << inc
end

#validate(machine) ⇒ Object



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/vagrant-openstack-provider/config.rb', line 277

def validate(machine)
  errors = _detected_errors

  errors << I18n.t('vagrant_openstack.config.password_required') unless @password
  errors << I18n.t('vagrant_openstack.config.username_required') unless @username

  validate_ssh_username(machine, errors)
  validate_stack_config(errors)
  validate_ssh_timeout(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