Class: VagrantPlugins::OpenStack::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ Config

Returns a new instance of Config.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/vagrant-openstack-plugin/config.rb', line 94

def initialize
  @api_key  = UNSET_VALUE
  @endpoint = UNSET_VALUE
  @flavor   = UNSET_VALUE
  @image    = UNSET_VALUE
  @server_name = UNSET_VALUE
  @metatdata = UNSET_VALUE
  @username = UNSET_VALUE
  @keypair_name = UNSET_VALUE
  @network  = UNSET_VALUE
  @address_id  = UNSET_VALUE
  @scheduler_hints = UNSET_VALUE
  @availability_zone = UNSET_VALUE
  @security_groups = UNSET_VALUE
  @ssh_username = UNSET_VALUE
  @tenant = UNSET_VALUE
  @user_data = UNSET_VALUE
  @floating_ip = UNSET_VALUE
  @region = UNSET_VALUE
end

Instance Attribute Details

#address_id ⇒ Object

A specific address identifier to use when connecting. Overrides network above if both are set.



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

def address_id
  @address_id
end

#api_key ⇒ String

The API key to access OpenStack.

Returns:

  • (String)


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

def api_key
  @api_key
end

#availability_zone ⇒ Object

Specify the availability zone in which to create the instance



54
55
56
# File 'lib/vagrant-openstack-plugin/config.rb', line 54

def availability_zone
  @availability_zone
end

#endpoint ⇒ String

The endpoint to access OpenStack. If nil, it will default to DFW.

Returns:

  • (String)


15
16
17
# File 'lib/vagrant-openstack-plugin/config.rb', line 15

def endpoint
  @endpoint
end

#flavor ⇒ Object

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



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

def flavor
  @flavor
end

#floating_ip ⇒ String

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

Returns:

  • (String)


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

def floating_ip
  @floating_ip
end

#image ⇒ Object

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



23
24
25
# File 'lib/vagrant-openstack-plugin/config.rb', line 23

def image
  @image
end

#keypair_name ⇒ String

The name of the keypair to use.

Returns:

  • (String)


38
39
40
# File 'lib/vagrant-openstack-plugin/config.rb', line 38

def keypair_name
  @keypair_name
end

#metadata ⇒ Hash

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

Returns:

  • (Hash)


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

def 
  @metadata
end

#network ⇒ String

Network configurations for the instance

Returns:

  • (String)


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

def network
  @network
end

#region ⇒ String

The region to specify when the OpenStack cloud has multiple regions

Returns:

  • (String)


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

def region
  @region
end

#scheduler_hints ⇒ Object

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



51
52
53
# File 'lib/vagrant-openstack-plugin/config.rb', line 51

def scheduler_hints
  @scheduler_hints
end

#security_groups ⇒ Array[String]

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

Returns:

  • (Array[String])


60
61
62
# File 'lib/vagrant-openstack-plugin/config.rb', line 60

def security_groups
  @security_groups
end

#server_name ⇒ Object

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.



28
29
30
# File 'lib/vagrant-openstack-plugin/config.rb', line 28

def server_name
  @server_name
end

#ssh_username ⇒ String

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

Returns:

  • (String)


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

def ssh_username
  @ssh_username
end

#tenant ⇒ String

The tenant to use.

Returns:

  • (String)


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

def tenant
  @tenant
end

#user_data ⇒ String

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

Returns:

  • (String)


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

def user_data
  @user_data
end

#username ⇒ String

The username to access OpenStack.

Returns:

  • (String)


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

def username
  @username
end

Instance Method Details

#finalize! ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/vagrant-openstack-plugin/config.rb', line 115

def finalize!
  @api_key  = nil if @api_key == UNSET_VALUE
  @endpoint = nil if @endpoint == UNSET_VALUE
  @flavor   = /m1.tiny/ if @flavor == UNSET_VALUE
  @image    = /cirros/ if @image == UNSET_VALUE
  @server_name = nil if @server_name == UNSET_VALUE
  @metadata = nil if @metadata == UNSET_VALUE
  @username = nil if @username == UNSET_VALUE
  @network = nil if @network == UNSET_VALUE
  @address_id = 'public' if @address_id == UNSET_VALUE

  # Keypair defaults to nil
  @keypair_name = nil if @keypair_name == UNSET_VALUE

  @scheduler_hints = nil if @scheduler_hints == UNSET_VALUE
  @availability_zone = nil if @availability_zone == UNSET_VALUE
  @security_groups = nil if @security_groups == 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

  @tenant = nil if @tenant == UNSET_VALUE
  @user_data = "" if @user_data == UNSET_VALUE
  @floating_ip = nil if @floating_ip == UNSET_VALUE

  @region = nil if @region == UNSET_VALUE
end

#validate(machine) ⇒ Object



144
145
146
147
148
149
150
151
# File 'lib/vagrant-openstack-plugin/config.rb', line 144

def validate(machine)
  errors = []

  errors << I18n.t("vagrant_openstack.config.api_key_required") if !@api_key
  errors << I18n.t("vagrant_openstack.config.username_required") if !@username

  { "OpenStack Provider" => errors }
end