danarchy_sys 0.2.12 → 0.2.14

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
  SHA1:
3
- metadata.gz: 8c3d93b8a4b5dc2e84ea69b279f9cfa3a1d86768
4
- data.tar.gz: c8a4a4278e5f6dada0b10fb7a49731e7392594ad
3
+ metadata.gz: 2eb2359dc35e6ad315efe1e66f82c7e9341c1b72
4
+ data.tar.gz: 0876ad89c05d969f6768b173fe1245f22cdeaf15
5
5
  SHA512:
6
- metadata.gz: 3f13481bf821158438c740efb0c6e36719a3bd0a8cf09d3fef172c8fcaf506a44bea1ad63daae5a4102ae0888a8c4808666d63fda5fe456ad007fc03a5179fe9
7
- data.tar.gz: 78082c565241160b920d766334d9f1c01ef60265e2501074a53fbdb2a408dc736e35c4ea3506e83de99ec8b7f3dcfc4660899ad188a87a63503ba05588ab5f92
6
+ metadata.gz: 2b7c28329ad67c2c1553b7d20a22eb581bdf7437675352402605abe6225b714998ca8307da3a4a9add757324abd84484eaf4cd284ff494890c045a550a2d077f
7
+ data.tar.gz: f2a4c861f6157f9837d4b01a154100bc77e98101fef32bb0af51941005f22742735b7905a7f34539bcefbfb4493ce6f007de312e243ee070e5cef0c84f7132a4
@@ -4,13 +4,14 @@ require_relative 'instance_manager/instance_status'
4
4
  class InstanceManager
5
5
  def self.manager(os_compute)
6
6
  comp_inst = os_compute.compute_instances
7
- puts 'Instance Manager: enter \'chooser\' to select an instance, \'help\' to view available commands or \'main\' for the main menu.'
7
+ puts 'Instance Manager: enter \'help\' to view available commands or \'main\' for the main menu.'
8
8
  menu = Menus.numbered_menu('instance')
9
9
  instance = false
10
10
 
11
11
  loop do
12
12
  while instance == false
13
13
  instance = chooser(os_compute)
14
+ return Menus.print_menu('main') if instance == 'main'
14
15
  end
15
16
 
16
17
  print "#{instance.name} ~: "
@@ -75,6 +76,8 @@ class InstanceManager
75
76
  Menus.print_menu('instance')
76
77
  puts "\nCommand \'#{cmd}\' not available. Enter a command from above."
77
78
  end
79
+
80
+ return Menus.print_menu('main') if instance == 'main'
78
81
  end
79
82
  end
80
83
 
@@ -112,6 +115,7 @@ class InstanceManager
112
115
  end
113
116
 
114
117
  abort('Exiting') if instance_name == 'exit'
118
+ return 'main' if instance_name == 'main'
115
119
 
116
120
  # Accept instance Id as an entry
117
121
  if instance_name =~ /^[0-9]*$/
@@ -0,0 +1,153 @@
1
+ require_relative './menus'
2
+
3
+ class KeypairManager
4
+ def self.manager(os_compute)
5
+ comp_kp = os_compute.compute_keypairs
6
+ puts 'Keypair Manager: enter \'help\' to view available commands or \'main\' for the main menu.'
7
+ menu = Menus.numbered_menu('keypair')
8
+ keypair = false
9
+
10
+ loop do
11
+ while keypair == false
12
+ keypair = chooser(os_compute)
13
+ return Menus.print_menu('main') if keypair == 'main'
14
+ end
15
+
16
+ print "#{keypair.name} ~: " if keypair
17
+ cmd = gets.chomp
18
+
19
+ next if cmd.empty?
20
+ abort('Exiting!') if cmd == 'exit'
21
+
22
+ if cmd =~ /^[0-9]*$/
23
+ menu[cmd.to_i].map { |k, v| cmd = k } if menu.keys.include? cmd.to_i
24
+ end
25
+
26
+ if cmd == 'help'
27
+ Menus.print_menu('keypair')
28
+ elsif cmd == 'main'
29
+ return Menus.print_menu('main')
30
+ elsif cmd == 'chooser'
31
+ keypair = chooser(os_compute)
32
+ elsif cmd == 'create'
33
+ print 'Enter a new keypair name: '
34
+ keypair_name = gets.chomp
35
+ keypair = comp_kp.create_keypair(keypair_name)
36
+ puts "Keypair: #{keypair_name} created!"
37
+ Menus.print_menu('keypair')
38
+ puts "Managing keypair: #{keypair_name}"
39
+ elsif cmd == 'delete'
40
+ print "Are you sure you wish to delete keypair: #{keypair.name}? (this is permanent!) (Y/N): "
41
+ delete = comp_kp.delete_keypair(keypair.name) if gets.chomp =~ /^y(es)?$/i
42
+ if delete == true
43
+ puts "#{keypair.name} has been deleted! Returning to the keypair chooser."
44
+ keypair = chooser(os_compute)
45
+ else
46
+ puts "#{keypair.name} was not deleted!"
47
+ end
48
+ elsif cmd == 'status'
49
+ printf("%#{keypair.name.size}s %0s %0s\n", keypair.name, ' => ', keypair.state)
50
+ elsif %w(pause unpause suspend resume start stop).include?(cmd.to_s)
51
+ status = keypair.state
52
+
53
+ if cmd =~ /e$/
54
+ print "#{cmd.gsub(/e$/, 'ing')} #{keypair.name} ."
55
+ else
56
+ print "#{cmd}ing #{keypair.name} ."
57
+ end
58
+
59
+ response = comp_kp.send(cmd.to_s, keypair.name.to_s)
60
+ if response == false
61
+ puts "\nInvalid action for #{keypair.name}'s current status!"
62
+ next
63
+ end
64
+
65
+ until status != keypair.state
66
+ keypair = os_compute.compute_keypairs.get_keypair(keypair.name)
67
+ sleep(3)
68
+ print ' .'
69
+ end
70
+
71
+ printf("\n%#{keypair.name.size}s %0s %0s\n", keypair.name, ' => ', keypair.state)
72
+ elsif cmd == 'connect'
73
+ if keypair.state == 'ACTIVE'
74
+ os_compute.compute_ssh(keypair.name.to_s)
75
+ else
76
+ puts "Unable to connect: #{keypair.name} is not running!"
77
+ end
78
+ else
79
+ Menus.print_menu('keypair')
80
+ puts "\nCommand \'#{cmd}\' not available. Enter a command from above."
81
+ end
82
+
83
+ return Menus.print_menu('main') if keypair == 'main'
84
+ end
85
+ end
86
+
87
+ def self.chooser(os_compute)
88
+ comp_kp = os_compute.compute_keypairs
89
+ keypairs = comp_kp.list_keypairs
90
+ keypair_numhash = Helpers.array_to_numhash(keypairs)
91
+ keypair_name = 'nil'
92
+ keypair = 'nil'
93
+
94
+ # Create a new keypairs if none exist
95
+ if keypair_numhash.empty?
96
+ print 'No existing keypairs were found. Should we create a new one? (Y/N): '
97
+ abort('Exiting!') unless gets.chomp =~ /^y(es)?$/i
98
+ keypair = PromptsCreateKeypair.create_keypair(os_compute, 'nil')
99
+ puts "Working with: #{keypair.name}\tStatus: #{keypair.state}"
100
+ return keypair
101
+ end
102
+
103
+ puts 'Available keypairs:'
104
+ fields = PrintFormats.printf_hash(keypair_numhash)
105
+ keypair_numhash.each do |k, v|
106
+ printf("#{fields}\n", "#{k}.", v)
107
+ end
108
+
109
+ # Loop input until an existing keypair is selected
110
+ print 'Enter an keypair to manage or enter a name for a new keypair: '
111
+
112
+ until keypairs.include?(keypair_name)
113
+ keypair_name = gets.chomp
114
+
115
+ until keypair_name.empty? == false
116
+ print 'Input was blank! Enter an keypair or Id from above: '
117
+ keypair_name = gets.chomp
118
+ end
119
+
120
+ abort('Exiting') if keypair_name == 'exit'
121
+ return 'main' if keypair_name == 'main'
122
+
123
+ # Accept keypair Id as an entry
124
+ if keypair_name =~ /^[0-9]*$/
125
+ until keypair_numhash.keys.include?(keypair_name.to_i)
126
+ print "#{keypair_name} is not a valid Id. Enter an Id from above: "
127
+ keypair_name = gets.chomp
128
+ end
129
+
130
+ keypair_name = keypair_numhash[keypair_name.to_i]
131
+ end
132
+
133
+ if comp_kp.check_keypair(keypair_name) == false
134
+ print "#{keypair_name} is not a valid keypair.
135
+ Should we create a new keypair named #{keypair_name}? (Y/N): "
136
+
137
+ if gets.chomp =~ /^y(es)?$/i
138
+ comp_kp.create_keypair(keypair_name)
139
+ else
140
+ puts "Not creating new keypair: #{keypair_name}."
141
+ return false
142
+ end
143
+ end
144
+
145
+ keypairs = comp_kp.list_keypairs
146
+ end
147
+
148
+ keypair = comp_kp.get_keypair(keypair_name)
149
+ Menus.print_menu('keypair')
150
+ puts "Managing keypair: #{keypair_name}"
151
+ keypair
152
+ end
153
+ end
@@ -2,9 +2,10 @@
2
2
  class Menus
3
3
  def self.get_menu(menu)
4
4
  menus = { 'main' => { 'instance' => 'Instance Manager',
5
- 'keypair' => 'Keypair Manager (Not yet implemented!)',
5
+ 'keypair' => 'Keypair Manager',
6
6
  'help' => 'Outputs commands for current the menu level',
7
- 'exit' => 'Exit dAnarchy_sys'},
7
+ 'exit' => 'Exit dAnarchy_sys'
8
+ },
8
9
  'instance' => { 'status' => 'Current running status of instance',
9
10
  'connect' => 'Connect to instance through SSH',
10
11
  'start' => 'Start a currently stopped instance',
@@ -14,7 +15,11 @@ class Menus
14
15
  'suspend' => 'Suspend Instance (to disk)',
15
16
  'resume' => 'Resume instance from suspended state',
16
17
  'create' => 'Create a new instance',
17
- 'delete' => 'Delete this instance'}
18
+ 'delete' => 'Delete this instance'
19
+ },
20
+ 'keypair' => { 'create' => 'Create a new keypair',
21
+ 'delete' => 'Delete an existing keypair'
22
+ }
18
23
  }
19
24
 
20
25
  menus[menu]
@@ -31,13 +36,12 @@ class Menus
31
36
  # print_menu(menu)
32
37
  elsif menu == 'instance'
33
38
  puts 'Instance Manager commands: '
34
- puts 'Enter \'help\' to view available commands or \'main\' for the main menu.'
39
+ puts 'Enter enter \'chooser\' to select an instance, \'help\' to view available commands or \'main\' for the main menu.'
35
40
  # print_menu(menu)
36
41
  elsif menu == 'keypair'
37
42
  puts 'Keypair Manager commands: '
38
- puts 'Not yet implemented!'
39
- return
40
- # print_menu(menu)
43
+ puts 'Enter enter \'chooser\' to select a keypair, \'help\' to view available commands or \'main\' for the main menu.'
44
+ # print_menu(menu)
41
45
  elsif menu == 'storage'
42
46
  puts 'Storage Manager commands: '
43
47
  puts 'Not yet implemented!'
@@ -22,8 +22,10 @@ class Providers
22
22
 
23
23
  abort('Exiting') if provider == 'exit'
24
24
 
25
- if provider =~ /^[0-9]*$/ # select by Id
26
- provider = providers[provider.to_s]
25
+ if provider =~ /^[0-9]*$/
26
+ provider = providers[provider.to_i]
27
+ else
28
+ provider = provider.to_sym
27
29
  end
28
30
  end
29
31
 
@@ -9,7 +9,7 @@ module DanarchySys
9
9
  require_relative 'cli/menus'
10
10
  require_relative 'cli/providers'
11
11
  require_relative 'cli/instance_manager'
12
- # require_relative 'cli/keypair_manager'
12
+ require_relative 'cli/keypair_manager'
13
13
 
14
14
  provider = Providers.chooser
15
15
  puts "OpenStack -> #{provider}"
@@ -47,8 +47,7 @@ module DanarchySys
47
47
  if cmd == 'instance'
48
48
  InstanceManager.manager(@os_compute)
49
49
  elsif cmd == 'keypair'
50
- puts 'Keypair Manager not yet implemented!'
51
- # Keypair.manager(@os_compute)
50
+ KeypairManager.manager(@os_compute)
52
51
  elsif cmd == 'help'
53
52
  Menus.print_menu('main')
54
53
  elsif cmd == 'exit'
@@ -6,7 +6,7 @@ class Helpers
6
6
 
7
7
  count = 1
8
8
  array.sort.each do |item|
9
- numbered_hash[count.to_s] = item
9
+ numbered_hash[count] = item
10
10
  count += 1
11
11
  end
12
12
 
@@ -80,5 +80,8 @@ class ComputeKeypairs
80
80
 
81
81
  @compute.delete_key_pair(keypair_name) if kp_check == true
82
82
  File.delete(pemfile) if pem_check == true
83
+
84
+ return true if check_keypair(keypair_name) == false
85
+ false
83
86
  end
84
87
  end
@@ -1,3 +1,3 @@
1
1
  module DanarchySys
2
- VERSION = "0.2.12"
2
+ VERSION = "0.2.14"
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.2.12
4
+ version: 0.2.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan James
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-15 00:00:00.000000000 Z
11
+ date: 2017-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-openstack
@@ -100,6 +100,7 @@ files:
100
100
  - lib/danarchy_sys/cli/instance_manager.rb
101
101
  - lib/danarchy_sys/cli/instance_manager/instance_status.rb
102
102
  - lib/danarchy_sys/cli/instance_manager/prompts_create_instance.rb
103
+ - lib/danarchy_sys/cli/keypair_manager.rb
103
104
  - lib/danarchy_sys/cli/menus.rb
104
105
  - lib/danarchy_sys/cli/providers.rb
105
106
  - lib/danarchy_sys/config_manager.rb