Class: VagrantPlugins::HP::Config

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region_specific = false) ⇒ Config

Returns a new instance of Config.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vagrant-hp/config.rb', line 37

def initialize(region_specific = false)
  @access_key = UNSET_VALUE
  @secret_key = UNSET_VALUE
  @server_name = UNSET_VALUE
  @private_ip_address = UNSET_VALUE
  @keypair_name = UNSET_VALUE
  @tenant_id = UNSET_VALUE
  @availability_zone = UNSET_VALUE
  @image = UNSET_VALUE
  @ssh_private_key_path = UNSET_VALUE
  @ssh_username = UNSET_VALUE
  @flavor = UNSET_VALUE
  @network = UNSET_VALUE
  @config = UNSET_VALUE


  @__compiled_region_configs = {}
  @__finalized = false
  @__region_config = {}
  @__region_specific = region_specific
end

Instance Attribute Details

#access_keyObject

Returns the value of attribute access_key.



11
12
13
# File 'lib/vagrant-hp/config.rb', line 11

def access_key
  @access_key
end

#availability_zoneObject

Returns the value of attribute availability_zone.



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

def availability_zone
  @availability_zone
end

#flavorObject

Returns the value of attribute flavor.



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

def flavor
  @flavor
end

#floating_ipObject

Returns the value of attribute floating_ip.



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

def floating_ip
  @floating_ip
end

#imageObject

Returns the value of attribute image.



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

def image
  @image
end

#keypair_nameObject

Returns the value of attribute keypair_name.



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

def keypair_name
  @keypair_name
end

#networkObject

Returns the value of attribute network.



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

def network
  @network
end

#secret_keyObject

Returns the value of attribute secret_key.



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

def secret_key
  @secret_key
end

#security_groupsObject

Returns the value of attribute security_groups.



31
32
33
# File 'lib/vagrant-hp/config.rb', line 31

def security_groups
  @security_groups
end

#server_nameObject

Returns the value of attribute server_name.



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

def server_name
  @server_name
end

#ssh_private_key_pathObject

Returns the value of attribute ssh_private_key_path.



27
28
29
# File 'lib/vagrant-hp/config.rb', line 27

def ssh_private_key_path
  @ssh_private_key_path
end

#ssh_usernameObject

Returns the value of attribute ssh_username.



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

def ssh_username
  @ssh_username
end

#tenant_idObject

Returns the value of attribute tenant_id.



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

def tenant_id
  @tenant_id
end

Instance Method Details

#finalize!Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/vagrant-hp/config.rb', line 89

def finalize!
  # The access keys default to nil
  @access_key = nil if @access_key == UNSET_VALUE
  @secret_key = nil if @secret_key == UNSET_VALUE
  @tenant_id = nil if @tenant_id == UNSET_VALUE

  @server_name = nil if @server_name == UNSET_VALUE

  # AMI must be nil, since we can't default that
  @image = nil if @image == UNSET_VALUE

  # Default instance type is an standard.small
  @flavor = 'standard.small' if @flavor == UNSET_VALUE

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

  # Default the private IP to nil since VPC is not default
  @private_ip_address = nil if @private_ip_address == UNSET_VALUE

  # Default availability-zone is az1. This is sensible because HP Cloud
  # generally defaults to this as well.
  @availability_zone = 'az1' if @availability_zone == UNSET_VALUE

  # The SSH values by default are nil, and the top-level config
  # `config.ssh` values are used.
  @ssh_private_key_path = nil if @ssh_private_key_path == UNSET_VALUE
  @ssh_username = nil if @ssh_username == UNSET_VALUE

  # The network values.
  @network = [] if @network == UNSET_VALUE

  # Mark that we finalized
  @__finalized = true
end

#get_region_config(name) ⇒ Object

This gets the configuration for a specific region. It shouldn’t be called by the general public and is only used internally.



159
160
161
162
163
164
165
166
# File 'lib/vagrant-hp/config.rb', line 159

def get_region_config(name)
  unless @__finalized
    raise 'Configuration must be finalized before calling this method.'
  end

  # Return the compiled region config
  @__compiled_region_configs[name] || self
end

#merge(other) ⇒ Object


Internal methods.




63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/vagrant-hp/config.rb', line 63

def merge(other)
  super.tap do |result|
    # Copy over the region specific flag. "True" is retained if either
    # has it.
    new_region_specific = other.instance_variable_get(
                                                    :@__region_specific)
    result.instance_variable_set(
      :@__region_specific, new_region_specific || @__region_specific)

    # Go through all the region configs and prepend ours onto
    # theirs.
    new_region_config = other.instance_variable_get(:@__region_config)
    @__region_config.each do |key, value|
      new_region_config[key] ||= []
      new_region_config[key] = value + new_region_config[key]
    end

    # Set it
    result.instance_variable_set(:@__region_config, new_region_config)

    # Merge in the tags
    result.tags.merge!(self.tags)
    result.tags.merge!(other.tags)
  end
end

#validate(machine) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/vagrant-hp/config.rb', line 125

def validate(machine)
  errors = []
  warnings = []
  messages = []

  # access_key: required
  errors << I18n.t('vagrant_hp.config.access_key_required') \
    if @access_key.nil?

  # secret_key: required
  errors << I18n.t('vagrant_hp.config.secret_key_required') \
    if @secret_key.nil?

  # tenant_id: required
  errors << I18n.t('vagrant_hp.config.tenant_id_required') \
    if @tenant_id.nil?

  # keypair_name: required
  errors << I18n.t('vagrant_hp.config.keypair_name_required') \
    if @keypair_name.nil?

  # image: required
  errors << I18n.t('vagrant_hp.config.image_required') \
    if @image.nil?

  # ssh_private_key_path: required
  errors << I18n.t('vagrant_hp.config.ssh_private_key_path') \
    if @ssh_private_key_path.nil?

  { 'HP Provider' => errors }
end