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.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/vagrant-openstack-provider/config.rb', line 83

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
  @sync_method = UNSET_VALUE
  @networks = []
end

Instance Attribute Details

#flavorObject

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



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

def flavor
  @flavor
end

#floating_ipString

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

Returns:

  • (String)


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

def floating_ip
  @floating_ip
end

#imageObject

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



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

def image
  @image
end

#keypair_nameString

The name of the keypair to use.

Returns:

  • (String)


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

def keypair_name
  @keypair_name
end

#networksArray

Network list the VM will be connected to

Returns:

  • (Array)


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

def networks
  @networks
end

#openstack_auth_urlObject

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



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

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

def openstack_network_url
  @openstack_network_url
end

#passwordObject

The API key to access Openstack.



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

def password
  @password
end

#rsync_includesArray

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

Returns:

  • (Array)


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

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.



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

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)


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

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)


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

def ssh_username
  @ssh_username
end

#sync_methodString

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

Returns:

  • (String)


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

def sync_method
  @sync_method
end

#tenant_nameObject

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



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

def tenant_name
  @tenant_name
end

#usernameString

The username to access Openstack.

Returns:

  • (String)


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

def username
  @username
end

Instance Method Details

#finalize!Object

rubocop:disable Style/CyclomaticComplexity



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/vagrant-openstack-provider/config.rb', line 103

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
  @sync_method = 'rsync' if @sync_method == UNSET_VALUE
  @keypair_name = nil if @keypair_name == 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



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

def rsync_include(inc)
  @rsync_includes << inc
end

#validate(_machine) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/vagrant-openstack-provider/config.rb', line 130

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
  errors << I18n.t('vagrant_openstack.config.keypair_name_required') unless @keypair_name

  {
    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