Class: RSpecSystem::NodeSet::Openstack
- Inherits:
-
Base
- Object
- Base
- RSpecSystem::NodeSet::Openstack
show all
- Defined in:
- lib/rspec-system/node_set/openstack.rb
Constant Summary
collapse
- PROVIDER_TYPE =
'openstack'
- CONFIG_KEYS =
[
:node_timeout,
:username,
:flavor_name,
:image_name,
:endpoint,
:keypair_name,
:network_name,
:ssh_keys,
:api_key
]
Instance Attribute Summary collapse
Attributes inherited from Base
#config, #custom_prefabs_path, #destroy, #nodes, #setname
Instance Method Summary
collapse
Methods inherited from Base
#configure, #default_node, #provider_type, #randmac, #random_string, #rcp, #run, #setup, #ssh_connect, #ssh_exec!, #tmppath
Constructor Details
#initialize(name, config, custom_prefabs_path, options) ⇒ Openstack
Returns a new instance of Openstack.
23
24
25
26
27
28
|
# File 'lib/rspec-system/node_set/openstack.rb', line 23
def initialize(name, config, custom_prefabs_path, options)
super
@vmconf = read_config
@now = Time.now.strftime '%Y%m%d-%H:%M:%S.%L'
RSpec.configuration.rs_storage[:nodes] ||= {}
end
|
Instance Attribute Details
#vmconf ⇒ Object
Returns the value of attribute vmconf.
9
10
11
|
# File 'lib/rspec-system/node_set/openstack.rb', line 9
def vmconf
@vmconf
end
|
Instance Method Details
#compute ⇒ Object
77
78
79
80
81
82
83
84
|
# File 'lib/rspec-system/node_set/openstack.rb', line 77
def compute
@compute || @compute = Fog::Compute.new({
:provider => :openstack,
:openstack_username => vmconf[:username],
:openstack_api_key => vmconf[:api_key],
:openstack_auth_url => vmconf[:endpoint],
})
end
|
#connect ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/rspec-system/node_set/openstack.rb', line 46
def connect
nodes.each do |k,v|
server = RSpec.configuration.rs_storage[:nodes][k][:server]
before = Time.new.to_i
while true
begin
server.wait_for(5) { ready? }
break
rescue ::Fog::Errors::TimeoutError
raise if Time.new.to_i - before > vmconf[:node_timeout]
log.info "Timeout connecting to instance, trying again..."
end
end
chan = ssh_connect(:host => k, :user => 'root', :net_ssh_options => {
:keys => vmconf[:ssh_keys].split(':'),
:host_name => server.addresses[vmconf[:network_name]].first['addr'],
:paranoid => false
})
RSpec.configuration.rs_storage[:nodes][k][:ssh] = chan
end
end
|
#launch ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/rspec-system/node_set/openstack.rb', line 30
def launch
nodes.each do |k,v|
storage = RSpec.configuration.rs_storage[:nodes][k] ||= {}
options = {
:flavor_ref => flavor.id,
:image_ref => image.id,
:name => "#{k}-#{@now}",
:key_name => vmconf[:keypair_name]
}
options[:nics] = [{'net_id' => nic.id}] if vmconf[:network_name]
log.info "Launching openstack instance #{k}"
result = compute.servers.create options
storage[:server] = result
end
end
|
#network ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'lib/rspec-system/node_set/openstack.rb', line 86
def network
@network || @network = Fog::Network.new({
:provider => :openstack,
:openstack_username => vmconf[:username],
:openstack_api_key => vmconf[:api_key],
:openstack_auth_url => vmconf[:endpoint],
})
end
|
#teardown ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/rspec-system/node_set/openstack.rb', line 69
def teardown
nodes.keys.each do |k|
server = RSpec.configuration.rs_storage[:nodes][k][:server]
log.info "Destroying server #{server.name}"
server.destroy
end
end
|