danarchy_sys 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 425cdec809b087727a5dd9c9f6f4bf6752d1e23f29021921f5350c22201f8e46
4
- data.tar.gz: a0a09bd3bca283330e9597d3ebbb1e1b753dff3d5e956ae14f3e427c5bc395ec
3
+ metadata.gz: 37afb4c44981ca4c353940933cf1b6edcb8653d2294fb783382a5554d7870321
4
+ data.tar.gz: e9e460d13686dde0a882425e719f7c7629f19d8e244d3edee68142bfc107611a
5
5
  SHA512:
6
- metadata.gz: 04a1a995b50c94b7237aabdcae302767835282189cf94c95c703442f4cc8a6f4e97d6f29a448d4521a63544ef4eae9b5b5200eb24c026cf3e7bd5ab56c1b6522
7
- data.tar.gz: c2f02632a979e7b6381103fa6c191e6c6ccb3e53d0bc87a8d1f95908095ebf1f5fa7b5e29638d360e2765de5fed3773038e945575c00c330e06e75738fffef0b
6
+ metadata.gz: 82fa8db40aa5f030b99faa0a16588a472d8993e8a1624213393eaf6e12ba2d30b062f2dbb965cc508885dc0b36c1ff78bfa3ba8bf197bca72b45bd48e0e03b72
7
+ data.tar.gz: bab5de7dd8fc27351574591cc65e04ce4658fd9a842955845a8b486f3c3311cad493c45379b432bb009d57f30510f769495069d68b028e6cc541fe4ef6eea70c
@@ -21,9 +21,9 @@ module DanarchySys
21
21
 
22
22
  loop do
23
23
  print 'command ~: '
24
- cmd = gets.chomp
24
+ cmd = gets
25
+ cmd = cmd ? cmd.chomp : abort('Exiting!')
25
26
 
26
- next if cmd.empty?
27
27
  if cmd =~ /^[0-9]*$/
28
28
  menu[cmd.to_i].map { |k, v| cmd = k } if menu.keys.include? cmd.to_i
29
29
  end
@@ -17,9 +17,8 @@ class Accounts
17
17
 
18
18
  until accounts.values.include?(account)
19
19
  print 'Which account should we use? (enter \'exit\' to leave): '
20
- account = gets.chomp
21
-
22
- abort('Exiting') if account == 'exit'
20
+ account = gets
21
+ account = account ? account.chomp : abort('Exiting!')
23
22
 
24
23
  if account =~ /^[0-9]*$/
25
24
  account = accounts[account.to_i]
@@ -18,9 +18,8 @@ class InstanceManager
18
18
  end
19
19
 
20
20
  print "#{instance.name} ~: " if instance
21
- cmd = gets.chomp
22
-
23
- next if cmd.empty?
21
+ cmd = gets
22
+ cmd = cmd ? cmd.chomp : abort('Exiting!')
24
23
  abort('Exiting!') if cmd == 'exit'
25
24
 
26
25
  if cmd =~ /^[0-9]*$/
@@ -46,7 +45,8 @@ class InstanceManager
46
45
  end
47
46
  elsif cmd == 'status'
48
47
  instance = @os_compute.instances.get_instance(instance.name)
49
- if instance.state == 'ACTIVE' && @os_compute.ssh(instance, 'uptime')[:stderr]
48
+ uptime_result = @os_compute.ssh(instance, 'uptime')
49
+ if instance.state == 'ACTIVE' && uptime_result[:stderr]
50
50
  printf("%#{instance.name.size}s %0s %0s\n", instance.name, ' => ', 'WAITING')
51
51
  else
52
52
  printf("%#{instance.name.size}s %0s %0s\n", instance.name, ' => ', instance.state)
@@ -120,13 +120,14 @@ class InstanceManager
120
120
  print 'Enter an instance to manage or enter a name for a new instance: '
121
121
 
122
122
  until instances_numhash.values.collect{|i| i[:name]}.include?(instance_name)
123
- instance_name = gets.chomp
123
+ instance_name = gets
124
124
 
125
125
  until instance_name.empty? == false
126
126
  print 'Input was blank! Enter an instance or Id from above: '
127
127
  instance_name = gets.chomp
128
128
  end
129
129
 
130
+ instance_name = instance_name ? instance_name.chomp : abort('Exiting!')
130
131
  abort('Exiting') if instance_name == 'exit'
131
132
  return 'main' if instance_name == 'main'
132
133
 
@@ -37,64 +37,55 @@ module DanarchySys
37
37
 
38
38
  def ssh(instance, *cmd)
39
39
  instance = instances.get_instance(instance) if instance.class == String
40
- opts = { quiet: true }
41
- opts[:command] = cmd ? cmd.shift : nil
42
40
  pemfile = keypairs.pemfile_path(instance.key_name)
43
41
  addrs = instances.get_public_addresses(instance)
44
- # (instances, keypairs, images) = instances, keypairs, images
45
- # instance = instances.get_instance(instance)
46
42
 
43
+ opts = { quiet: true }
44
+ opts[:command] = cmd ? cmd.shift : nil
45
+ connector = { ipv4: addrs.grep(/\./).first,
46
+ ipv6: addrs.grep(/:/).first,
47
+ ssh_key: pemfile,
48
+ ssh_user: nil }
47
49
  # Define user by image_id
48
50
  image = images.get_image_by_id(instance.image['id'])
49
-
50
- ssh, user = nil
51
51
  if image == nil
52
52
  puts "Image not found for #{instance.name}! This instance needs to be rebuild with a current image."
53
53
  puts "Attempting to determine the correct username and log in..."
54
- ssh, user = fallback_ssh(ipv4, pemfile)
54
+ connector = fallback_ssh(connector)
55
55
  else
56
- user = 'ubuntu' if image.name =~ /ubuntu/i
57
- user = 'debian' if image.name =~ /debian/i
58
- user = 'centos' if image.name =~ /centos/i
59
- user = 'fedora' if image.name =~ /fedora/i
60
- user = 'core' if image.name =~ /coreos/i
56
+ connector[:ssh_user] = 'gentoo' if image.name =~ /gentoo/i
57
+ connector[:ssh_user] = 'ubuntu' if image.name =~ /ubuntu/i
58
+ connector[:ssh_user] = 'debian' if image.name =~ /debian/i
59
+ connector[:ssh_user] = 'centos' if image.name =~ /centos/i
60
+ connector[:ssh_user] = 'fedora' if image.name =~ /fedora/i
61
+ connector[:ssh_user] = 'core' if image.name =~ /coreos/i
61
62
  end
62
63
 
63
- return if !user
64
-
65
- connector = { ipv4: addrs.grep(/\./).first,
66
- ipv6: addrs.grep(/:/).first,
67
- ssh_user: user,
68
- ssh_key: pemfile }
69
-
64
+ return if ! connector[:ssh_user]
70
65
  SSH.new(connector, opts)
71
66
  end
72
67
 
73
- def fallback_ssh(ipv4, pemfile)
74
- # This needs some updating to utilize the SSH module as above.
75
- users = %w[debian ubuntu centos fedora core]
76
- ssh, user = nil
68
+ def fallback_ssh(connector)
69
+ users = %w[gentoo debian ubuntu centos fedora core]
70
+ fb_opts = { quiet: true, command: 'uptime' }
77
71
 
78
72
  users.each do |username|
79
- print "Attempting connection as user: #{username} @ #{ipv4} => "
80
- connect = "/usr/bin/ssh -o ConnectTimeout=5 -o StrictHostKeyChecking=no -o PasswordAuthentication=no -i '#{pemfile}' #{username}@#{ipv4}"
81
- ssh = system("#{connect} 'uptime' &>/dev/null")
73
+ connector[:ssh_user] = username
74
+ print 'Attempting connection as user: '
75
+ print connector[:ssh_user], ' @ ', connector[:ipv4], ' => '
76
+ fallback_result = SSH.new(connector, fb_opts)
82
77
 
83
- if ssh == true
78
+ if fallback_result[:stdout]
84
79
  puts 'success'
85
- user = username
86
80
  break
87
81
  else
88
82
  puts 'failed'
83
+ connector[:ssh_user] = nil
89
84
  end
90
85
  end
91
86
 
92
- if ssh == false
93
- puts 'Unable to connect! User unknown or SSHd is not running on the instance.'
94
- return ssh, nil
95
- else
96
- return [ssh, user]
97
- end
87
+ puts 'Unable to determine user or SSHd is not running!' if ! connector[:ssh_user]
88
+ connector
98
89
  end
99
90
  end
100
91
  end
@@ -1,3 +1,3 @@
1
1
  module DanarchySys
2
- VERSION = '0.5.3'
2
+ VERSION = '0.5.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danarchy_sys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
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-09-23 00:00:00.000000000 Z
11
+ date: 2018-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-openstack