danarchy_sys 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +2 -1
- data/danarchy_sys.gemspec +3 -5
- data/lib/danarchy_sys/cli/accounts.rb +1 -2
- data/lib/danarchy_sys/cli/instance_manager/prompts_create_instance.rb +72 -29
- data/lib/danarchy_sys/cli/instance_manager.rb +26 -22
- data/lib/danarchy_sys/cli.rb +6 -19
- data/lib/danarchy_sys/config_manager.rb +3 -3
- data/lib/danarchy_sys/openstack/compute/instances.rb +5 -5
- data/lib/danarchy_sys/openstack/compute.rb +9 -9
- data/lib/danarchy_sys/version.rb +1 -1
- metadata +4 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a5c3ad8faf86550ad951bf1bb6b8f4e25220264628373ba1da95fe0b1fac942f
|
4
|
+
data.tar.gz: 78d4d8bebebd00e899aa25840a6ce96b6d70f0bef9e3a8cd0611dddc90e396c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f8e7e628ac733cf73a28295f73e821541e8f2ce1769351b6151abf2327e4a575809abe0bb1af33b755afc2b72deac7570a2972303e3869b3bda174a9d3ad5f0
|
7
|
+
data.tar.gz: 6de2f4c30e92333830e293a5b5e0f08f7602561f9e540c7457c0a4201549b37104bedc1a6c175596f264dc18278ee3e7e0f1cab022d71aa0c1bdbb41223a774b
|
data/Gemfile
CHANGED
data/danarchy_sys.gemspec
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
4
|
require 'danarchy_sys/version'
|
@@ -7,15 +7,13 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "danarchy_sys"
|
8
8
|
spec.version = DanarchySys::VERSION
|
9
9
|
spec.authors = ["Dan James"]
|
10
|
-
spec.email = ["
|
10
|
+
spec.email = ["dan@danarchy.me"]
|
11
11
|
|
12
12
|
spec.summary = %q{Facilitates the deployment and management of OpenStack.}
|
13
13
|
spec.description = %q{dAnarchy Sys is intended to be a platform for the management of cloud compute instances from initial setup through to the deployment of end-user software.}
|
14
14
|
spec.homepage = "https://github.com/danarchy85/danarchy_sys"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
17
|
if spec.respond_to?(:metadata)
|
20
18
|
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
19
|
else
|
@@ -30,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
30
28
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
31
29
|
spec.require_paths = ["lib"]
|
32
30
|
|
33
|
-
spec.add_dependency "fog-openstack", "~> 0.1
|
31
|
+
spec.add_dependency "fog-openstack", "~> 0.1.20"
|
34
32
|
|
35
33
|
spec.add_development_dependency "bundler", "~> 1.13"
|
36
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -1,12 +1,12 @@
|
|
1
1
|
|
2
2
|
# CLI Prompt to create a new instance
|
3
3
|
class PromptsCreateInstance
|
4
|
-
def
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
comp_keys = os_compute.keypairs
|
4
|
+
def initialize(os_compute, settings)
|
5
|
+
@os_compute = os_compute
|
6
|
+
@settings = settings
|
7
|
+
end
|
9
8
|
|
9
|
+
def create_instance(instance_name)
|
10
10
|
# Prompt for and check that instance_name is unused
|
11
11
|
if instance_name == nil
|
12
12
|
print "\nWhat should we name the instance?: "
|
@@ -14,7 +14,7 @@ class PromptsCreateInstance
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# Make sure instance_name isn't already in use
|
17
|
-
until
|
17
|
+
until @os_compute.instances.check_instance(instance_name) == false
|
18
18
|
print "\n#{instance_name} already exists! Try another name: "
|
19
19
|
instance_name = gets.chomp
|
20
20
|
end
|
@@ -23,46 +23,56 @@ class PromptsCreateInstance
|
|
23
23
|
|
24
24
|
# Prompt for image
|
25
25
|
puts "\nSelect an image (operating system) for #{instance_name}"
|
26
|
-
image =
|
26
|
+
image = self.image
|
27
27
|
|
28
28
|
# Prompt for flavor
|
29
29
|
puts "\nSelect a flavor (instance size) for #{instance_name}"
|
30
|
-
flavor =
|
30
|
+
flavor = self.flavor
|
31
31
|
|
32
32
|
# Prompt for keypair
|
33
33
|
puts "\nSelect a keypair (SSH key) for #{instance_name}"
|
34
|
-
keypair =
|
34
|
+
keypair = self.keypair
|
35
|
+
|
36
|
+
# Prompt for userdata
|
37
|
+
print "\nEnter a path to userdata for #{instance_name} or leave blank for no userdata: "
|
38
|
+
file, userdata = self.userdata
|
35
39
|
|
36
40
|
# Print summary and prompt to continue
|
41
|
+
puts "\n================= Instance Summary ==================="
|
37
42
|
puts "\nInstance Name: #{instance_name}"
|
38
43
|
puts " Linux: #{image.name}"
|
39
44
|
puts "Instance Size: #{flavor.name}"
|
40
45
|
puts " Keypair: #{keypair.name}"
|
41
|
-
|
46
|
+
puts " UserData: #{file}"
|
47
|
+
puts "\n --- UserData --- \n#{userdata}\n --- End UserData ---\n" if userdata
|
48
|
+
puts "\n=============== End Instance Summary ================="
|
42
49
|
print 'Should we continue with creating the instance? (Y/N): '
|
43
50
|
instance = nil
|
44
51
|
continue = gets.chomp
|
45
52
|
|
46
53
|
if continue =~ /^y(es)?$/i
|
47
54
|
puts "Creating instance: #{instance_name}"
|
48
|
-
instance =
|
55
|
+
instance = @os_compute.instances.create_instance(instance_name, image.id, flavor.id, keypair.name, userdata)
|
49
56
|
else
|
50
|
-
puts "Abandoning creation of #{instance_name}"
|
51
|
-
|
57
|
+
puts "Abandoning creation of #{instance_name}! Returning to chooser."
|
58
|
+
instance = nil
|
52
59
|
end
|
53
60
|
|
54
|
-
instance_check =
|
55
|
-
|
56
|
-
|
61
|
+
instance_check = instance ? @os_compute.instances.check_instance(instance_name) : false
|
62
|
+
if !instance
|
63
|
+
return false
|
64
|
+
elsif instance_check == true
|
57
65
|
puts "Instance #{instance.name} is ready!"
|
58
66
|
return instance
|
59
|
-
|
60
|
-
|
67
|
+
elsif instance_check == false
|
68
|
+
puts "Error: Could not create instance: #{instance_name}"
|
61
69
|
end
|
70
|
+
|
71
|
+
instance
|
62
72
|
end
|
63
73
|
|
64
|
-
def
|
65
|
-
images_numbered = Helpers.array_to_numhash(
|
74
|
+
def image
|
75
|
+
images_numbered = Helpers.array_to_numhash(@os_compute.images.all_images)
|
66
76
|
|
67
77
|
# List available images in a numbered hash.
|
68
78
|
puts "\nAvailable Images:"
|
@@ -74,11 +84,11 @@ class PromptsCreateInstance
|
|
74
84
|
|
75
85
|
image_name = item_chooser(images_numbered, 'image')
|
76
86
|
print "Image Name: #{image_name}\n"
|
77
|
-
|
87
|
+
@os_compute.images.get_image_by_name(image_name)
|
78
88
|
end
|
79
89
|
|
80
|
-
def
|
81
|
-
flavors_numbered = Helpers.array_to_numhash(
|
90
|
+
def flavor
|
91
|
+
flavors_numbered = Helpers.array_to_numhash(@os_compute.flavors.all_flavors.sort_by(&:ram))
|
82
92
|
|
83
93
|
puts "\nAvailable Instance Flavors:"
|
84
94
|
puts sprintf("%0s %-15s %-10s %-10s %0s", 'Id', 'Name', 'RAM', 'VCPUs', 'Disk')
|
@@ -89,11 +99,11 @@ class PromptsCreateInstance
|
|
89
99
|
|
90
100
|
flavor_name = item_chooser(flavors_numbered, 'flavor')
|
91
101
|
print "Flavor Name: #{flavor_name.split('.')[1]}\n"
|
92
|
-
|
102
|
+
@os_compute.flavors.get_flavor_by_name(flavor_name)
|
93
103
|
end
|
94
104
|
|
95
|
-
def
|
96
|
-
keypairs = Helpers.objects_to_numhash(
|
105
|
+
def keypair
|
106
|
+
keypairs = Helpers.objects_to_numhash(@os_compute.keypairs.all_keypairs)
|
97
107
|
keypair_name = nil
|
98
108
|
|
99
109
|
# List available keypairs
|
@@ -130,18 +140,40 @@ Should we create a new keypair named #{keypair_name}? (Y/N): "
|
|
130
140
|
|
131
141
|
if gets.chomp =~ /^y(es)?$/i
|
132
142
|
puts "Creating keypair: #{keypair_name}!"
|
133
|
-
return
|
143
|
+
return @os_compute.keypairs.create_keypair(keypair_name)
|
134
144
|
else
|
135
145
|
print 'Please enter an option from above: '
|
136
146
|
end
|
137
147
|
end
|
138
148
|
end
|
139
149
|
|
140
|
-
|
150
|
+
@os_compute.keypairs.get_keypair(keypair_name)
|
151
|
+
end
|
152
|
+
|
153
|
+
def userdata
|
154
|
+
userdata = nil
|
155
|
+
file = gets.chomp
|
156
|
+
|
157
|
+
return ['-- no userdata --', nil] if file.empty?
|
158
|
+
file = File.expand_path(file)
|
159
|
+
userdata = File.exist?(file) ? File.read(file) : ''
|
160
|
+
if userdata.empty?
|
161
|
+
print 'File is empty!'
|
162
|
+
userdata = editor(file)
|
163
|
+
else
|
164
|
+
puts userdata + "\n\n"
|
165
|
+
print "Do any changes need to be made to '#{file}'? (Y/N): "
|
166
|
+
|
167
|
+
if gets.chomp =~ /^y(es)?$/i
|
168
|
+
userdata = editor(file)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
return [file, userdata]
|
141
173
|
end
|
142
174
|
|
143
175
|
private
|
144
|
-
def
|
176
|
+
def item_chooser(items_numbered, item)
|
145
177
|
# Loop input until existing object is selected
|
146
178
|
item_name = nil
|
147
179
|
print "Which #{item} should we use for this instance?: "
|
@@ -163,4 +195,15 @@ Should we create a new keypair named #{keypair_name}? (Y/N): "
|
|
163
195
|
end
|
164
196
|
item_name
|
165
197
|
end
|
198
|
+
|
199
|
+
def editor(file)
|
200
|
+
require 'fileutils'
|
201
|
+
FileUtils.cp(file, "#{file}.bkp")
|
202
|
+
editor = ENV['EDITOR'] || '/bin/nano'
|
203
|
+
puts "Opening #{file} in #{File.basename(editor)}"
|
204
|
+
sleep(2)
|
205
|
+
system("#{editor} #{file}")
|
206
|
+
puts "Backed up #{file} to #{file}.bkp"
|
207
|
+
File.read(file)
|
208
|
+
end
|
166
209
|
end
|
@@ -2,15 +2,18 @@ require_relative 'instance_manager/prompts_create_instance'
|
|
2
2
|
require_relative 'instance_manager/instance_status'
|
3
3
|
|
4
4
|
class InstanceManager
|
5
|
-
def self.manager(os_compute)
|
6
|
-
|
5
|
+
def self.manager(os_compute, settings)
|
6
|
+
@os_compute = os_compute
|
7
|
+
@settings = settings
|
8
|
+
@prompts_create_instance = PromptsCreateInstance.new(@os_compute, @settings)
|
7
9
|
puts 'Instance Manager: enter \'help\' to view available commands or \'main\' for the main menu.'
|
8
10
|
menu = Menus.numbered_menu('instance')
|
9
11
|
instance = false
|
10
12
|
|
11
13
|
loop do
|
14
|
+
trap('SIGINT') { print "\nEnter an instance to manage or enter a name for a new instance: " }
|
12
15
|
while instance == false
|
13
|
-
instance = chooser
|
16
|
+
instance = chooser
|
14
17
|
return Menus.print_menu('main') if instance == 'main'
|
15
18
|
end
|
16
19
|
|
@@ -29,20 +32,20 @@ class InstanceManager
|
|
29
32
|
elsif cmd == 'main'
|
30
33
|
return Menus.print_menu('main')
|
31
34
|
elsif cmd == 'chooser'
|
32
|
-
instance = chooser
|
35
|
+
instance = chooser
|
33
36
|
elsif cmd == 'create'
|
34
|
-
|
35
|
-
instance = chooser(os_compute)
|
37
|
+
instance = @prompts_create_instance.create_instance(nil)
|
36
38
|
elsif cmd == 'delete'
|
37
39
|
print "Are you sure you wish to delete instance: #{instance.name}? (this is permanent!) (Y/N): "
|
38
|
-
delete =
|
40
|
+
delete = @os_compute.instances.delete_instance(instance.name) if gets.chomp =~ /^y(es)?$/i
|
39
41
|
if delete == true
|
40
42
|
puts "#{instance.name} has been deleted! Returning to the instance chooser."
|
41
|
-
instance = chooser
|
43
|
+
instance = chooser
|
42
44
|
else
|
43
45
|
puts "#{instance.name} was not deleted!"
|
44
46
|
end
|
45
47
|
elsif cmd == 'status'
|
48
|
+
instance = @os_compute.instances.get_instance(instance.name)
|
46
49
|
printf("%#{instance.name.size}s %0s %0s\n", instance.name, ' => ', instance.state)
|
47
50
|
elsif %w(pause unpause suspend resume start stop).include?(cmd.to_s)
|
48
51
|
status = instance.state
|
@@ -53,32 +56,33 @@ class InstanceManager
|
|
53
56
|
print "#{cmd}ing #{instance.name} ."
|
54
57
|
end
|
55
58
|
|
56
|
-
response =
|
59
|
+
response = @os_compute.instances.send(cmd.to_s, instance.name.to_s)
|
57
60
|
if response == false
|
58
61
|
puts "\nInvalid action for #{instance.name}'s current status!"
|
59
62
|
next
|
60
63
|
end
|
61
64
|
|
62
65
|
until status != instance.state
|
63
|
-
instance = os_compute.instances.get_instance(instance.name)
|
66
|
+
instance = @os_compute.instances.get_instance(instance.name)
|
64
67
|
sleep(3)
|
65
68
|
print ' .'
|
66
69
|
end
|
67
70
|
|
68
71
|
printf("\n%#{instance.name.size}s %0s %0s\n", instance.name, ' => ', instance.state)
|
69
72
|
elsif cmd == 'rebuild'
|
70
|
-
image =
|
73
|
+
image = @prompts_create_instance.image
|
71
74
|
print "Should we rebuild #{instance.name} with image: #{image.name}? (Y/N): "
|
72
75
|
if gets.chomp =~ /^y(es)?$/i
|
73
76
|
puts "Rebuilding #{instance.name} with #{image.name}"
|
74
|
-
|
75
|
-
|
77
|
+
@os_compute.instances.rebuild_instance(instance, image)
|
78
|
+
instance = @os_compute.instances.get_instance(instance.name)
|
79
|
+
puts "\nRebuild in progress!"
|
76
80
|
else
|
77
81
|
puts "Not rebuilding #{instance.name} at this time."
|
78
82
|
end
|
79
83
|
elsif cmd == 'connect'
|
80
84
|
if instance.state == 'ACTIVE'
|
81
|
-
os_compute.ssh(instance.name)
|
85
|
+
@os_compute.ssh(instance.name)
|
82
86
|
else
|
83
87
|
puts "Unable to connect: #{instance.name} is not running!"
|
84
88
|
end
|
@@ -91,8 +95,8 @@ class InstanceManager
|
|
91
95
|
end
|
92
96
|
end
|
93
97
|
|
94
|
-
def self.chooser
|
95
|
-
instances_numhash = Helpers.objects_to_numhash(os_compute.instances.all_instances)
|
98
|
+
def self.chooser
|
99
|
+
instances_numhash = Helpers.objects_to_numhash(@os_compute.instances.all_instances)
|
96
100
|
instance_name = nil
|
97
101
|
instance = nil
|
98
102
|
|
@@ -100,19 +104,19 @@ class InstanceManager
|
|
100
104
|
if instances_numhash.empty?
|
101
105
|
print 'No existing instances were found. Should we create a new one? (Y/N): '
|
102
106
|
abort('Exiting!') unless gets.chomp =~ /^y(es)?$/i
|
103
|
-
instance =
|
107
|
+
instance = @prompts_create_instance.create_instance(nil)
|
104
108
|
puts "Working with: #{instance.name}\tStatus: #{instance.state}"
|
105
109
|
return instance
|
106
110
|
end
|
107
111
|
|
108
112
|
puts 'Available instances:'
|
109
|
-
istatus = InstanceStatus.new(os_compute)
|
113
|
+
istatus = InstanceStatus.new(@os_compute)
|
110
114
|
istatus.all_instances(instances_numhash)
|
111
115
|
|
112
116
|
# Loop input until an existing instance is selected
|
113
117
|
print 'Enter an instance to manage or enter a name for a new instance: '
|
114
118
|
|
115
|
-
until instances_numhash.values.collect{|i| i[:name]}.include?(instance_name)
|
119
|
+
until instances_numhash.values.collect{|i| i[:name]}.include?(instance_name)
|
116
120
|
instance_name = gets.chomp
|
117
121
|
|
118
122
|
until instance_name.empty? == false
|
@@ -133,12 +137,12 @@ class InstanceManager
|
|
133
137
|
instance_name = instances_numhash[instance_name.to_i][:name].to_s
|
134
138
|
end
|
135
139
|
|
136
|
-
unless instances_numhash.values.collect{|i| i[:name]}.include?(instance_name)
|
140
|
+
unless instances_numhash.values.collect{|i| i[:name]}.include?(instance_name)
|
137
141
|
print "#{instance_name} is not a valid instance.
|
138
142
|
Should we create a new instance named #{instance_name}? (Y/N): "
|
139
143
|
|
140
144
|
if gets.chomp =~ /^y(es)?$/i
|
141
|
-
instance =
|
145
|
+
instance = @prompts_create_instance.create_instance(instance_name)
|
142
146
|
return instance
|
143
147
|
else
|
144
148
|
puts "Not creating new instance: #{instance_name}."
|
@@ -147,7 +151,7 @@ Should we create a new instance named #{instance_name}? (Y/N): "
|
|
147
151
|
end
|
148
152
|
end
|
149
153
|
|
150
|
-
instance = os_compute.instances.get_instance(instance_name)
|
154
|
+
instance = @os_compute.instances.get_instance(instance_name)
|
151
155
|
Menus.print_menu('instance')
|
152
156
|
puts "Managing instance: #{instance_name}\tStatus: #{instance.state}"
|
153
157
|
instance
|
data/lib/danarchy_sys/cli.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
|
2
|
-
require 'optparse'
|
3
|
-
require 'fog/openstack'
|
4
2
|
require_relative '../danarchy_sys'
|
5
3
|
|
6
4
|
module DanarchySys
|
@@ -11,26 +9,15 @@ module DanarchySys
|
|
11
9
|
require_relative 'cli/instance_manager'
|
12
10
|
require_relative 'cli/keypair_manager'
|
13
11
|
|
14
|
-
|
12
|
+
danarchysys_config = DanarchySys::ConfigManager::Config.new
|
13
|
+
account = Accounts.chooser(danarchysys_config)
|
14
|
+
connection = danarchysys_config[:accounts][account]
|
15
15
|
puts "OpenStack -> #{account}"
|
16
|
-
@
|
16
|
+
@settings = danarchysys_config[:global_settings]
|
17
|
+
@os_compute = DanarchySys::OpenStack::Compute.new(connection, @settings)
|
17
18
|
console
|
18
19
|
end
|
19
20
|
|
20
|
-
def instance_chooser
|
21
|
-
inst_mgr = InstanceManager.new(@os_compute)
|
22
|
-
instance = inst_mgr.chooser(@os_compute)
|
23
|
-
|
24
|
-
until instance != false
|
25
|
-
puts "\nReturning to Instance Chooser"
|
26
|
-
instance = inst_mgr.chooser(@os_compute)
|
27
|
-
end
|
28
|
-
|
29
|
-
menus('main')
|
30
|
-
puts "\nWorking with: #{instance.name}\tStatus: #{instance.state}"
|
31
|
-
console(instance.name)
|
32
|
-
end
|
33
|
-
|
34
21
|
def console
|
35
22
|
menu = Menus.numbered_menu('main')
|
36
23
|
Menus.print_menu('main')
|
@@ -45,7 +32,7 @@ module DanarchySys
|
|
45
32
|
end
|
46
33
|
|
47
34
|
if cmd == 'instance'
|
48
|
-
InstanceManager.manager(@os_compute)
|
35
|
+
InstanceManager.manager(@os_compute, @settings)
|
49
36
|
elsif cmd == 'keypair'
|
50
37
|
KeypairManager.manager(@os_compute)
|
51
38
|
elsif cmd == 'help'
|
@@ -1,13 +1,13 @@
|
|
1
|
+
require_relative 'config_manager/openstack'
|
1
2
|
require 'fileutils'
|
2
3
|
require 'json'
|
3
|
-
require_relative 'config_manager/openstack'
|
4
4
|
|
5
5
|
# dAnarchy_sys config management
|
6
6
|
module DanarchySys
|
7
7
|
module ConfigManager
|
8
8
|
class Config
|
9
9
|
def self.new
|
10
|
-
danarchysys_cfg_path = File.join(File.realpath(ENV['HOME']), '.danarchy_sys')
|
10
|
+
danarchysys_cfg_path = File.join(File.realpath(ENV['HOME']), '.danarchy', 'danarchy_sys')
|
11
11
|
config_json = File.join(danarchysys_cfg_path, 'danarchy_sys.json')
|
12
12
|
|
13
13
|
if File.exists?(config_json)
|
@@ -19,7 +19,7 @@ module DanarchySys
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.providers
|
22
|
-
['openstack'] # , 'aws']
|
22
|
+
['openstack', 'danarchy'] # , 'aws']
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.config_template
|
@@ -91,8 +91,8 @@ class ComputeInstances
|
|
91
91
|
instance.stop
|
92
92
|
end
|
93
93
|
|
94
|
-
def create_instance(instance_name, image_id, flavor_id, keypair_name, *
|
95
|
-
user_data =
|
94
|
+
def create_instance(instance_name, image_id, flavor_id, keypair_name, *userdata)
|
95
|
+
user_data = userdata ? userdata.first : nil
|
96
96
|
|
97
97
|
instance = @compute.servers.create(name: instance_name,
|
98
98
|
image_ref: image_id,
|
@@ -116,9 +116,9 @@ class ComputeInstances
|
|
116
116
|
instance.rebuild(image.id, instance.name)
|
117
117
|
addrs = [get_public_addresses(instance),
|
118
118
|
get_private_addresses(instance)].flatten.compact!
|
119
|
-
addrs.each { |addr| system("ssh-keygen -R #{addr}") }
|
119
|
+
addrs.each { |addr| system("ssh-keygen -R #{addr} &>/dev/null") }
|
120
120
|
|
121
|
-
instance.wait_for { ready? }
|
121
|
+
# instance.wait_for { ready? }
|
122
122
|
instance
|
123
123
|
end
|
124
124
|
|
@@ -138,7 +138,7 @@ class ComputeInstances
|
|
138
138
|
|
139
139
|
addrs = [get_public_addresses(instance),
|
140
140
|
get_private_addresses(instance)].flatten.compact!
|
141
|
-
addrs.each { |addr| system("ssh-keygen -R #{addr}") }
|
141
|
+
addrs.each { |addr| system("ssh-keygen -R #{addr} &>/dev/null") }
|
142
142
|
|
143
143
|
return true
|
144
144
|
end
|
@@ -6,10 +6,8 @@ require_relative 'compute/flavors'
|
|
6
6
|
module DanarchySys
|
7
7
|
module OpenStack
|
8
8
|
class Compute
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
connection = danarchysys_config[:accounts][account.to_sym]
|
12
|
-
@settings = danarchysys_config[:global_settings]
|
9
|
+
def initialize(connection, settings)
|
10
|
+
@settings = settings
|
13
11
|
@compute = Fog::Compute::OpenStack.new(connection)
|
14
12
|
@instances = @compute.servers
|
15
13
|
@images = @compute.images(filters: {'status' => ['ACTIVE']})
|
@@ -53,6 +51,7 @@ module DanarchySys
|
|
53
51
|
ssh, user = nil
|
54
52
|
if image == nil
|
55
53
|
puts "Image not found for #{instance.name}! This instance needs to be rebuild with a current image."
|
54
|
+
puts "Attempting to determine the correct username and log in..."
|
56
55
|
ssh, user = fallback_ssh(ipv4, pemfile)
|
57
56
|
else
|
58
57
|
user = 'ubuntu' if image.name =~ /ubuntu/i
|
@@ -64,25 +63,26 @@ module DanarchySys
|
|
64
63
|
|
65
64
|
return if !user
|
66
65
|
|
67
|
-
|
68
|
-
connect = "/usr/bin/ssh -i '#{pemfile}' #{user}@#{ipv4}"
|
66
|
+
print "Connecting as user: #{user} @ #{ipv4} " + cmd + "\n"
|
67
|
+
connect = "/usr/bin/ssh -o ConnectTimeout=15 -o StrictHostKeyChecking=no -o PasswordAuthentication=no -i '#{pemfile}' #{user}@#{ipv4}"
|
69
68
|
system(connect)
|
70
69
|
end
|
71
70
|
|
72
71
|
def fallback_ssh(ipv4, pemfile)
|
73
|
-
users = %w[
|
72
|
+
users = %w[debian ubuntu centos fedora core]
|
74
73
|
ssh, user = nil
|
75
74
|
|
76
75
|
users.each do |username|
|
77
76
|
print "Attempting connection as user: #{username} @ #{ipv4} => "
|
78
|
-
connect = "/usr/bin/ssh -i '#{pemfile}' #{username}@#{ipv4}"
|
77
|
+
connect = "/usr/bin/ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -o PasswordAuthentication=no -i '#{pemfile}' #{username}@#{ipv4}"
|
79
78
|
ssh = system("#{connect} 'uptime' &>/dev/null")
|
80
|
-
puts 'failed' if ssh ==false
|
81
79
|
|
82
80
|
if ssh == true
|
83
81
|
puts 'success'
|
84
82
|
user = username
|
85
83
|
break
|
84
|
+
else
|
85
|
+
puts 'failed'
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
data/lib/danarchy_sys/version.rb
CHANGED
metadata
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: danarchy_sys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan James
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-openstack
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0.1'
|
20
|
-
- - ">="
|
21
18
|
- !ruby/object:Gem::Version
|
22
19
|
version: 0.1.20
|
23
20
|
type: :runtime
|
@@ -25,9 +22,6 @@ dependencies:
|
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - "~>"
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0.1'
|
30
|
-
- - ">="
|
31
25
|
- !ruby/object:Gem::Version
|
32
26
|
version: 0.1.20
|
33
27
|
- !ruby/object:Gem::Dependency
|
@@ -75,7 +69,7 @@ dependencies:
|
|
75
69
|
description: dAnarchy Sys is intended to be a platform for the management of cloud
|
76
70
|
compute instances from initial setup through to the deployment of end-user software.
|
77
71
|
email:
|
78
|
-
-
|
72
|
+
- dan@danarchy.me
|
79
73
|
executables:
|
80
74
|
- console
|
81
75
|
- danarchy_sys
|
@@ -142,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
136
|
version: '0'
|
143
137
|
requirements: []
|
144
138
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.6
|
139
|
+
rubygems_version: 2.7.6
|
146
140
|
signing_key:
|
147
141
|
specification_version: 4
|
148
142
|
summary: Facilitates the deployment and management of OpenStack.
|