Class: Cifrado::Plugins::Saio
- Inherits:
-
Thor
- Object
- Thor
- Cifrado::Plugins::Saio
show all
- Includes:
- Utils
- Defined in:
- lib/cifrado/cli/saio/base.rb,
lib/cifrado/cli/saio/images.rb,
lib/cifrado/cli/saio/destroy.rb,
lib/cifrado/cli/saio/flavors.rb,
lib/cifrado/cli/saio/regions.rb,
lib/cifrado/cli/saio/bootstrap.rb
Instance Method Summary
collapse
Methods included from Utils
#calculate_chunks, #clean_object_name, #decrypt_filename, #encrypt_filename, #humanize_bytes, #mime_type, #prettify_backtrace, #unix_time
Instance Method Details
#bootstrap ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
88
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
|
# File 'lib/cifrado/cli/saio/bootstrap.rb', line 26
def bootstrap
require 'shexy'
Log.level = Logger::DEBUG if options[:bootstrap_debug]
begin
available_keys = service.list_ssh_keys.body['ssh_keys']
key = available_keys.find { |k| k['name'] == options[:ssh_key_name] }
unless key
raise "SSH key #{options[:ssh_key_name]} not available."
end
server_name = options[:server_name]
server = service.servers.find { |s| s.name == server_name }
if server
raise "Server #{server_name} is currently running."
end
flavor = service.flavors.find { |f| f.name == options[:flavor] }
image = service.images.find { |i| i.name == options[:image] }
region = service.regions.find { |r| r.name == options[:region] }
unless image and flavor and region
raise "The specified image, flavor or region was not found"
end
Log.info "Creating server #{server_name}..."
server = service.servers.create :name => options[:server_name],
:image_id => image.id,
:flavor_id => flavor.id,
:region_id => region.id,
:ssh_key_ids => key['id']
Log.info "Server provisioned, waiting for IP..."
server.wait_for(120) { ip_address }
Log.info "Server IP: #{server.ip_address}"
Shexy.host = server.ip_address
Shexy.user = 'root'
Shexy.flags = { :paranoid => false }
Log.info 'Waiting for SSH...'
Shexy.wait_for_ssh(90)
Log.info 'Bootstraping Swift All-In-One (this may take a while)...'
if RUBY_VERSION >= '1.9'
secure_random = SecureRandom.hex.encode('UTF-8')
user_password = SecureRandom.hex.encode('UTF-8')
else
user_password = SecureRandom.hex
secure_random = SecureRandom.hex
end
script = bootstrap_script(user_password, options[:disk_size])
Shexy.copy_to script, '/root/saio.sh'
Shexy.exe '/bin/bash /root/saio.sh' do |out, err|
out.each_line { |l| Log.debug l }
end
config = {
:auth_url => "https://#{server.ip_address}:5000/v2.0/tokens",
:username => 'admin',
:tenant => 'admin',
:password => user_password,
:secure_random => secure_random
}
Log.info
Log.info 'Swift is ready. Login details:'
Log.info
Log.info "---"
Log.info ":auth_url: https://#{server.ip_address}:5000/v2.0/tokens"
Log.info ":username: admin"
Log.info ":tenant: admin"
Log.info ":password: #{user_password}"
Log.info ":secure_random: #{secure_random}"
Log.info
save_settings(config) if options[:save_settings]
rescue Excon::Errors::Found => e
raise "Authentication failed"
end
server
end
|
#destroy ⇒ Object
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/cifrado/cli/saio/destroy.rb', line 7
def destroy
s = service.servers.find {|s| s.name == options[:server_name] }
if s
Log.info "Destroying server #{options[:server_name]}."
s.destroy
true
else
false
end
end
|
#flavors ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/cifrado/cli/saio/flavors.rb', line 6
def flavors
flavors = service.flavors.all
flavors.each do |f|
Log.info "[#{f.id}]".ljust(5) + " #{f.name}"
end
flavors
end
|
#images ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/cifrado/cli/saio/images.rb', line 6
def images
images = service.images.all
images.each do |i|
Log.info "[#{i.id}]".ljust(10) + " #{i.name}"
end
images
end
|
#regions ⇒ Object
6
7
8
9
10
11
12
|
# File 'lib/cifrado/cli/saio/regions.rb', line 6
def regions
regions = service.regions.all
service.regions.each do |r|
Log.info "[#{r.id}]".ljust(10) + " #{r.name}"
end
regions
end
|