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.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/vagrant-openstack-provider/config.rb', line 99

def initialize
  @password = UNSET_VALUE
  @openstack_compute_url = UNSET_VALUE
  @openstack_network_url = UNSET_VALUE
  @openstack_auth_url = UNSET_VALUE
  @flavor = UNSET_VALUE
  @image = UNSET_VALUE
  @tenant_name = UNSET_VALUE
  @server_name = UNSET_VALUE
  @username = UNSET_VALUE
  @rsync_includes = []
  @keypair_name = UNSET_VALUE
  @ssh_username = UNSET_VALUE
  @ssh_timeout = UNSET_VALUE
  @floating_ip = UNSET_VALUE
  @floating_ip_pool = UNSET_VALUE
  @sync_method = UNSET_VALUE
  @availability_zone = UNSET_VALUE
  @networks = []
  @public_key_path = UNSET_VALUE
end

Instance Attribute Details

#availability_zoneString

Availability Zone

Returns:

  • (String)


97
98
99
# File 'lib/vagrant-openstack-provider/config.rb', line 97

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.



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

def flavor
  @flavor
end

#floating_ipString

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

Returns:

  • (String)


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

def floating_ip
  @floating_ip
end

#floating_ip_poolString

The floating IP pool from where new IPs will be allocated

Returns:

  • (String)


77
78
79
# File 'lib/vagrant-openstack-provider/config.rb', line 77

def floating_ip_pool
  @floating_ip_pool
end

#imageObject

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



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

def image
  @image
end

#keypair_nameString

The name of the keypair to use.

Returns:

  • (String)


50
51
52
# File 'lib/vagrant-openstack-provider/config.rb', line 50

def keypair_name
  @keypair_name
end

#networksArray

Network list the VM will be connected to

Returns:

  • (Array)


87
88
89
# File 'lib/vagrant-openstack-provider/config.rb', line 87

def networks
  @networks
end

#openstack_auth_urlObject

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



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

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-openstack-provider/config.rb', line 14

def openstack_compute_url
  @openstack_compute_url
end

#openstack_network_urlObject

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



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

def openstack_network_url
  @openstack_network_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)


92
93
94
# File 'lib/vagrant-openstack-provider/config.rb', line 92

def public_key_path
  @public_key_path
end

#rsync_includesArray

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

Returns:

  • (Array)


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

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



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

def server_name
  @server_name
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)


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

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)


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

def ssh_username
  @ssh_username
end

#sync_methodString

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

Returns:

  • (String)


82
83
84
# File 'lib/vagrant-openstack-provider/config.rb', line 82

def sync_method
  @sync_method
end

#tenant_nameObject

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



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

def tenant_name
  @tenant_name
end

#usernameString

The username to access Openstack.

Returns:

  • (String)


45
46
47
# File 'lib/vagrant-openstack-provider/config.rb', line 45

def username
  @username
end

Instance Method Details

#finalize!Object

rubocop:disable Style/CyclomaticComplexity



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-openstack-provider/config.rb', line 122

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_auth_url = nil if @openstack_auth_url == UNSET_VALUE
  @flavor = nil if @flavor == UNSET_VALUE
  @image = nil if @image == 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?
  @floating_ip = nil if @floating_ip == UNSET_VALUE
  @floating_ip_pool = nil if @floating_ip_pool == 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

  # 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?
end

#rsync_include(inc) ⇒ Object

rubocop:enable Style/CyclomaticComplexity



148
149
150
# File 'lib/vagrant-openstack-provider/config.rb', line 148

def rsync_include(inc)
  @rsync_includes << inc
end

#validate(machine) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/vagrant-openstack-provider/config.rb', line 152

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

  if machine.config.ssh.private_key_path
    # Waiting for https://github.com/mitchellh/vagrant/issues/4388 to improve this
    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_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