Class: VagrantPlugins::Rackspace::Config

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

Constant Summary collapse

SERVICE_NET_ID =

Default Rackspace Cloud Network IDs

'11111111-1111-1111-1111-111111111111'
PUBLIC_NET_ID =
'00000000-0000-0000-0000-000000000000'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/vagrant-rackspace/config.rb', line 137

def initialize
  @api_key  = UNSET_VALUE
  @rackspace_region = UNSET_VALUE
  @rackspace_compute_url = UNSET_VALUE
  @rackspace_auth_url = UNSET_VALUE
  @flavor   = UNSET_VALUE
  @image    = UNSET_VALUE
  @public_key_path = UNSET_VALUE
  @rackconnect = UNSET_VALUE
  @server_name = UNSET_VALUE
  @user_data = UNSET_VALUE
  @config_drive = UNSET_VALUE
  @username = UNSET_VALUE
  @disk_config = UNSET_VALUE
  @networks = []
  @rsync_includes = []
  @init_script = UNSET_VALUE
end

Instance Attribute Details

#admin_passwordString

Password to set for root (on Linux) or Administrator (on Windows) A random password will be generated if admin_password is not set or does not meet the password requirements of the operating system.

Returns:

  • (String)


120
121
122
# File 'lib/vagrant-rackspace/config.rb', line 120

def admin_password
  @admin_password
end

#api_keyString

The API key to access RackSpace.

Returns:

  • (String)


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

def api_key
  @api_key
end

#config_driveObject

Whether to attach a read-only configuration drive

@ return [Boolean]



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

def config_drive
  @config_drive
end

#disk_configObject

The disk configuration value.

* AUTO -   The server is built with a single partition the size of the target flavor disk. The file system is automatically adjusted to fit the entire partition.
           This keeps things simple and automated. AUTO is valid only for images and servers with a single partition that use the EXT3 file system.
           This is the default setting for applicable Rackspace base images.

* MANUAL - The server is built using whatever partition scheme and file system is in the source image. If the target flavor disk is larger,
           the remaining disk space is left unpartitioned. This enables images to have non-EXT3 file systems, multiple partitions,
           and so on, and enables you to manage the disk configuration.

This defaults to MANUAL



103
104
105
# File 'lib/vagrant-rackspace/config.rb', line 103

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



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

def flavor
  @flavor
end

#imageObject

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



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

def image
  @image
end

#init_scriptString

A initialization script to run on the target machine before Vagrant connects. It should generally be used only for enabling or securing shell connection transport protocols, like SSH or WinRM. Use normal Vagrant provisioners for other purposes.

This script may be subject to the limits for Server Personality.

Returns:

  • (String)

See Also:



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

def init_script
  @init_script
end

#key_nameString

Alternately, if a keypair were already uploaded to Rackspace, the key name could be provided.

Returns:

  • (String)


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

def key_name
  @key_name
end

#metadataHash

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

Returns:

  • (Hash)


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

def 
  @metadata
end

#networksArray

Cloud Networks to attach to the server

Returns:

  • (Array)


108
109
110
# File 'lib/vagrant-rackspace/config.rb', line 108

def networks
  @networks
end

#public_key_pathString

The path to the public key to set up on the remote server for SSH. This should match the private key configured with ‘config.ssh.private_key_path`.

Returns:

  • (String)


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

def public_key_path
  @public_key_path
end

#rackconnectBoolean

The option that indicates RackConnect usage or not.

Returns:

  • (Boolean)


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

def rackconnect
  @rackconnect
end

#rackspace_auth_urlObject

Note:

Currently, you must authenticate against the UK authenication endpoint to access the London Data center. Hopefully this method makes the experience more seemless for users of the UK cloud.



181
182
183
184
185
186
187
# File 'lib/vagrant-rackspace/config.rb', line 181

def rackspace_auth_url
  if (@rackspace_auth_url.nil? || @rackspace_auth_url == UNSET_VALUE) && lon_region?
    Fog::Rackspace::UK_AUTH_ENDPOINT
  else
    @rackspace_auth_url
  end
end

#rackspace_compute_urlObject

The compute_url to access RackSpace. If nil, it will default to DFW. (formerly know as ‘endpoint’)

expected to be a string url - ‘dfw.servers.api.rackspacecloud.com/v2’ ‘ord.servers.api.rackspacecloud.com/v2’ ‘lon.servers.api.rackspacecloud.com/v2

alternatively, can use constants if you require ‘fog/rackspace’ in your Vagrantfile Fog::Compute::RackspaceV2::DFW_ENDPOINT Fog::Compute::RackspaceV2::ORD_ENDPOINT Fog::Compute::RackspaceV2::LON_ENDPOINT

Users should preference the rackspace_region setting over rackspace_compute_url



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

def rackspace_compute_url
  @rackspace_compute_url
end

#rackspace_regionObject

The region to access RackSpace. If nil, it will default to DFW. (formerly know as ‘endpoint’)

expected to be a symbol - :dfw (default), :ord, :lon

Users should preference the rackspace_region setting over rackspace_compute_url



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

def rackspace_region
  @rackspace_region
end

#rsync_includesArray

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

Returns:

  • (Array)


113
114
115
# File 'lib/vagrant-rackspace/config.rb', line 113

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.



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

def server_name
  @server_name
end

#user_dataObject

The path to the file containing user data for cloud init

@ return [String]



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

def user_data
  @user_data
end

#usernameString

The username to access RackSpace.

Returns:

  • (String)


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

def username
  @username
end

Instance Method Details

#finalize!Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/vagrant-rackspace/config.rb', line 156

def finalize!
  @api_key  = nil if @api_key == UNSET_VALUE
  @rackspace_region = nil if @rackspace_region == UNSET_VALUE
  @rackspace_compute_url = nil if @rackspace_compute_url == UNSET_VALUE
  @rackspace_auth_url = nil if @rackspace_auth_url == UNSET_VALUE
  @flavor   = /512MB/ if @flavor == UNSET_VALUE
  @image    = /Ubuntu/ if @image == UNSET_VALUE
  @rackconnect = nil if @rackconnect == UNSET_VALUE
  @server_name = nil if @server_name == UNSET_VALUE
  @user_data = nil if @user_data == UNSET_VALUE
  @config_drive = nil if @config_drive == UNSET_VALUE
  @metadata = nil if @metadata == UNSET_VALUE
  @username = nil if @username == UNSET_VALUE
  @disk_config = nil if @disk_config == UNSET_VALUE
  @networks = nil if @networks.empty?
  @rsync_includes = nil if @rsync_includes.empty?
  @init_script = nil if @init_script == UNSET_VALUE

  if @public_key_path == UNSET_VALUE
    @public_key_path = Vagrant.source_root.join("keys/vagrant.pub")
  end
end

#network(net_id, options = {}) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File 'lib/vagrant-rackspace/config.rb', line 189

def network(net_id, options={})
  # Eventually, this should accept options for network configuration,
  # primarily the IP address, but at the time of writing these
  # options are unsupported by Cloud Networks.
  options = {:attached => true}.merge(options)

  # Add the default Public and ServiceNet networks
  if @networks.empty?
    @networks = [PUBLIC_NET_ID, SERVICE_NET_ID]
  end

  net_id = SERVICE_NET_ID if net_id == :service_net

  if options[:attached]
    @networks << net_id unless @networks.include? net_id
  else
    @networks.delete net_id
  end
end

#rsync_include(inc) ⇒ Object



209
210
211
# File 'lib/vagrant-rackspace/config.rb', line 209

def rsync_include(inc)
  @rsync_includes << inc
end

#validate(machine) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/vagrant-rackspace/config.rb', line 213

def validate(machine)
  errors = _detected_errors

  errors << I18n.t("vagrant_rackspace.config.api_key_required") if !@api_key
  errors << I18n.t("vagrant_rackspace.config.username_required") if !@username
  errors << I18n.t("one of vagrant.rackspace.config.key_name or vagrant.rackspace.config.public_key_path required") if !@key_name && !@public_key_path

  {
    :rackspace_compute_url => @rackspace_compute_url,
    :rackspace_auth_url => @rackspace_auth_url
  }.each_pair do |key, value|
    errors << I18n.t("vagrant_rackspace.config.invalid_uri", :key => key, :uri => value) unless value.nil? || valid_uri?(value)
  end

  if !@key_name
    public_key_path = File.expand_path(@public_key_path, machine.env.root_path)
    if !File.file?(public_key_path)
      errors << I18n.t("vagrant_rackspace.config.public_key_not_found")
    end
  end

  { "RackSpace Provider" => errors }
end