danarchy_sys 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/README.txt +86 -0
- data/Rakefile +6 -0
- data/bin/console +6 -0
- data/bin/danarchy_sys +4 -0
- data/bin/setup +18 -0
- data/bin/setup.rb +86 -0
- data/danarchy_sys.gemspec +38 -0
- data/lib/danarchy_sys.rb +16 -0
- data/lib/danarchy_sys/aws.rb +9 -0
- data/lib/danarchy_sys/aws/compute.rb +13 -0
- data/lib/danarchy_sys/cli.rb +63 -0
- data/lib/danarchy_sys/cli/instance_manager.rb +130 -0
- data/lib/danarchy_sys/cli/instance_manager/instance_status.rb +50 -0
- data/lib/danarchy_sys/cli/instance_manager/prompts_create_instance.rb +182 -0
- data/lib/danarchy_sys/cli/menus.rb +60 -0
- data/lib/danarchy_sys/cli/providers.rb +33 -0
- data/lib/danarchy_sys/config.rb +66 -0
- data/lib/danarchy_sys/helpers.rb +61 -0
- data/lib/danarchy_sys/openstack.rb +9 -0
- data/lib/danarchy_sys/openstack/compute.rb +59 -0
- data/lib/danarchy_sys/openstack/compute/flavors.rb +47 -0
- data/lib/danarchy_sys/openstack/compute/images.rb +52 -0
- data/lib/danarchy_sys/openstack/compute/instances.rb +120 -0
- data/lib/danarchy_sys/openstack/compute/keypairs.rb +84 -0
- data/lib/danarchy_sys/openstack/compute/tests/answer_yes.rb +7 -0
- data/lib/danarchy_sys/openstack/compute/tests/flavors_test.rb +10 -0
- data/lib/danarchy_sys/openstack/compute/tests/images_test.rb +14 -0
- data/lib/danarchy_sys/openstack/compute/tests/instance_create_test.rb +14 -0
- data/lib/danarchy_sys/openstack/compute/tests/instance_manage_test.rb +24 -0
- data/lib/danarchy_sys/openstack/compute/tests/keypairs_prompt_test.rb +12 -0
- data/lib/danarchy_sys/openstack/compute/tests/keypairs_test.rb +38 -0
- data/lib/danarchy_sys/openstack/compute/tests/manage_test.rb +16 -0
- data/lib/danarchy_sys/printformats.rb +49 -0
- data/lib/danarchy_sys/version.rb +3 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4971d607e81fc1716c7f5840dde2a638f859c461
|
4
|
+
data.tar.gz: 4a7daa5ca4fa3613cc8a7309a9b6a4c9615f9593
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a32d4ad9c820ef04a5f36c93670e9d1a2248586c23023502cb523b5b33be73b4c07eb88a9eba934e4540a88072377eeb1e43861fcc9110b91b7c5eac7eac13e8
|
7
|
+
data.tar.gz: e41daf8bb24a1b8484f68ad3c633fb55add7439c90e04b61056f523b6f2a5d2170f2dfbb16e19ad6f23c092200e9e4f1f82ab413fac1de6eba982b28a50874ab
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.txt
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# DanarchySys
|
2
|
+
|
3
|
+
Welcome to dAnarchy Systems! This gem will assist you in easing the setup of OpenStack instances for use of hosting various web applications.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Requires bundler to be installed already: 'gem install bundler'
|
8
|
+
|
9
|
+
Download danarchy_sys, 'cd' into its directory, then run 'sh bin/setup'.
|
10
|
+
This will run bundler and install the required gems. It will then prompt for a new OpenStack setup.
|
11
|
+
|
12
|
+
dAnarchySys config setup will be located at danarchy_sys/config/danarchysys.yml in YAML format like this:
|
13
|
+
|
14
|
+
:connections:
|
15
|
+
:your_connection:
|
16
|
+
:openstack_auth_url: http://openstack-provider.com:5000/v2.0/tokens
|
17
|
+
:openstack_username: openstack_username
|
18
|
+
:openstack_api_key: openstack_api_key
|
19
|
+
:openstack_tenant: openstack_tenant
|
20
|
+
:settings:
|
21
|
+
:ssh_key_path: PATH_TO_SSH_KEYS
|
22
|
+
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Id Provider
|
27
|
+
1. os_dreamcompute
|
28
|
+
Which provider should we use? (enter 'exit' to leave): 1
|
29
|
+
OpenStack -> os_dreamcompute
|
30
|
+
dAnarchy_sys main menu commands:
|
31
|
+
Enter 'help' to view available commands or 'exit' to leave.
|
32
|
+
1. instance: Instance Manager
|
33
|
+
2. keypair: Keypair Manager (Not yet implemented!)
|
34
|
+
3. help: Outputs commands for current the menu level
|
35
|
+
4. exit: Exit dAnarchy_sys
|
36
|
+
command ~: instance
|
37
|
+
Instance Manager: enter 'help' to view available commands or 'main' for the main menu.
|
38
|
+
Available instances:
|
39
|
+
Id Name State Image VCPUS RAM Disk KeyPair
|
40
|
+
1. danarchysys_debian ACTIVE Debian-8 1 512 80 danarchy_sys
|
41
|
+
2. cephmnt1 SHUTOFF Debian-8 2 4096 80 danarchy_sys
|
42
|
+
Enter an instance to manage or enter a name for a new instance: 1
|
43
|
+
Instance Manager commands:
|
44
|
+
Enter 'help' to view available commands or 'back' for the main menu.
|
45
|
+
1. status: Current running status of instance
|
46
|
+
2. connect: Connect to instance through SSH
|
47
|
+
3. start: Start a currently stopped instance
|
48
|
+
4. stop: Stop a currently running instance
|
49
|
+
5. pause: Pause instance (to RAM)
|
50
|
+
6. unpause: Unpause instance from paused state
|
51
|
+
7. suspend: Suspend Instance (to disk)
|
52
|
+
8. resume: Resume instance from suspended state
|
53
|
+
9. create: Create a new instance
|
54
|
+
10. delete: Delete this instance
|
55
|
+
Managing instance: danarchysys_debian Status: ACTIVE
|
56
|
+
danarchysys_debian ~: connect
|
57
|
+
|
58
|
+
The programs included with the Debian GNU/Linux system are free software;
|
59
|
+
the exact distribution terms for each program are described in the
|
60
|
+
individual files in /usr/share/doc/*/copyright.
|
61
|
+
|
62
|
+
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
|
63
|
+
permitted by applicable law.
|
64
|
+
debian@danarchysys-debian:~$ lsb_release -a
|
65
|
+
No LSB modules are available.
|
66
|
+
Distributor ID: Debian
|
67
|
+
Description: Debian GNU/Linux 8.8 (jessie)
|
68
|
+
Release: 8.8
|
69
|
+
Codename: jessie
|
70
|
+
|
71
|
+
debian@danarchysys-debian:~$ exit
|
72
|
+
logout
|
73
|
+
Connection to 208.113.165.181 closed.
|
74
|
+
danarchysys_debian ~: exit
|
75
|
+
Exiting!
|
76
|
+
|
77
|
+
|
78
|
+
## Contributing
|
79
|
+
|
80
|
+
Bug reports are welcome on GitHub at https://github.com/danarchy85/danarchy_sys.
|
81
|
+
|
82
|
+
|
83
|
+
## License
|
84
|
+
|
85
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
86
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/danarchy_sys
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
# Do any other automated setup that you need to do here
|
9
|
+
PATH=$(pwd)
|
10
|
+
|
11
|
+
if [[ $PATH =~ danarchy_sys/bin$ ]]; then
|
12
|
+
/usr/bin/ruby $PATH/setup.rb
|
13
|
+
elif [[ $PATH =~ danarchy_sys$ ]]; then
|
14
|
+
/usr/bin/ruby $PATH/bin/setup.rb
|
15
|
+
else
|
16
|
+
echo "Unable to find danarchy_sys/bin/setup.rb!"
|
17
|
+
echo "Please run it manually: /usr/bin/ruby danarchy_sys/bin/setup.rb"
|
18
|
+
fi
|
data/bin/setup.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'fileutils'
|
3
|
+
require_relative '../lib/danarchy_sys'
|
4
|
+
|
5
|
+
# dAanarchySys config file setup
|
6
|
+
class DanarchySysConfig
|
7
|
+
def initialize
|
8
|
+
@config_mgr = ConfigMgr.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_config
|
12
|
+
@config_mgr.load
|
13
|
+
end
|
14
|
+
|
15
|
+
def ssh_key_path
|
16
|
+
danarchysys_config = load_config
|
17
|
+
|
18
|
+
ssh_key_path = "#{File.expand_path('..', File.dirname(__FILE__))}/config/ssh"
|
19
|
+
FileUtils.mkdir_p(ssh_key_path) unless Dir.exist?(ssh_key_path)
|
20
|
+
danarchysys_config[:settings][:ssh_key_path] = ssh_key_path
|
21
|
+
|
22
|
+
@config_mgr.save(danarchysys_config)
|
23
|
+
end
|
24
|
+
|
25
|
+
def new_connection
|
26
|
+
danarchysys_config = load_config
|
27
|
+
|
28
|
+
if danarchysys_config[:connections].count.zero?
|
29
|
+
puts 'Creating a new configuration.'
|
30
|
+
else
|
31
|
+
puts 'Adding a new OpenStack connection to existing configuration.'
|
32
|
+
end
|
33
|
+
|
34
|
+
print 'Provider name: '
|
35
|
+
provider_name = gets.chomp
|
36
|
+
print "OpenStack Auth URL\t(Example: http://openstack-host.com:5000/v2.0/tokens)\nEnter URL: "
|
37
|
+
openstack_auth_url = gets.chomp
|
38
|
+
print 'OpenStack Username: '
|
39
|
+
openstack_username = gets.chomp
|
40
|
+
print 'OpenStack API Key: '
|
41
|
+
openstack_api_key = gets.chomp
|
42
|
+
print 'OpenStack Tenant ID: '
|
43
|
+
openstack_tenant = gets.chomp
|
44
|
+
|
45
|
+
danarchysys_config[:connections][provider_name.to_sym] = {
|
46
|
+
openstack_auth_url: openstack_auth_url,
|
47
|
+
openstack_username: openstack_username,
|
48
|
+
openstack_api_key: openstack_api_key,
|
49
|
+
openstack_tenant: openstack_tenant
|
50
|
+
}
|
51
|
+
|
52
|
+
@config_mgr.save(danarchysys_config)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
config = DanarchySysConfig.new
|
57
|
+
danarchysys_config = config.load_config
|
58
|
+
puts 'Beginning danarchysys configuration setup.'
|
59
|
+
|
60
|
+
if danarchysys_config[:connections].count.zero?
|
61
|
+
config.new_connection
|
62
|
+
else
|
63
|
+
puts 'Available OpenStack Connections: '
|
64
|
+
danarchysys_config[:connections].each_key { |k| puts k }
|
65
|
+
end
|
66
|
+
|
67
|
+
continue = false
|
68
|
+
until continue == true
|
69
|
+
print 'Should we add another connection? (Y/N): '
|
70
|
+
|
71
|
+
if gets.chomp =~ /^y(es)?$/i
|
72
|
+
config.new_connection
|
73
|
+
else
|
74
|
+
continue = true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
config.ssh_key_path
|
79
|
+
|
80
|
+
danarchysys_config = config.load_config
|
81
|
+
|
82
|
+
puts 'Available OpenStack Connections: '
|
83
|
+
danarchysys_config[:connections].each_key { |k| puts k }
|
84
|
+
puts "SSH key location: #{danarchysys_config[:settings][:ssh_key_path]}"
|
85
|
+
puts "Config saved to: #{File.expand_path('..', File.dirname(__FILE__))}/config/danarchysys.yml"
|
86
|
+
puts "dAnarchySys setup is finished. Run \'/usr/bin/ruby danarchy_sys/bin/danarchy_sys\' to begin!"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'danarchy_sys/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "danarchy_sys"
|
8
|
+
spec.version = DanarchySys::VERSION
|
9
|
+
spec.authors = ["Dan James"]
|
10
|
+
spec.email = ["danheneise@me.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Facilitates the deployment and management of OpenStack.}
|
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
|
+
spec.homepage = "https://github.com/danarchy85/danarchy_sys"
|
15
|
+
spec.license = "MIT"
|
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
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
spec.bindir = "bin"
|
30
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
31
|
+
spec.require_paths = ["lib"]
|
32
|
+
|
33
|
+
spec.add_dependency "fog-openstack", "~> 0.1", ">=0.1.20"
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
end
|
data/lib/danarchy_sys.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
require 'fog/openstack'
|
3
|
+
require_relative 'danarchy_sys/version'
|
4
|
+
require_relative 'danarchy_sys/helpers'
|
5
|
+
require_relative 'danarchy_sys/config'
|
6
|
+
require_relative 'danarchy_sys/printformats'
|
7
|
+
|
8
|
+
module DanarchySys
|
9
|
+
module OpenStack
|
10
|
+
require_relative 'danarchy_sys/openstack'
|
11
|
+
end
|
12
|
+
|
13
|
+
module AWS
|
14
|
+
# Not yet implemented!
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module DanarchySys
|
2
|
+
module AWS
|
3
|
+
class Compute
|
4
|
+
def initialize(provider)
|
5
|
+
config = ConfigMgr.new
|
6
|
+
danarchysys_config = config.load
|
7
|
+
connection = danarchysys_config[:connections][provider]
|
8
|
+
@settings = danarchysys_config[:settings]
|
9
|
+
@compute = Fog::Compute::AWS.new(connection)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
|
2
|
+
require 'optparse'
|
3
|
+
require 'fog/openstack'
|
4
|
+
require_relative '../danarchy_sys'
|
5
|
+
|
6
|
+
module DanarchySys
|
7
|
+
class CLI
|
8
|
+
def initialize
|
9
|
+
require_relative 'cli/menus'
|
10
|
+
require_relative 'cli/providers'
|
11
|
+
require_relative 'cli/instance_manager'
|
12
|
+
# require_relative 'cli/keypair_manager'
|
13
|
+
|
14
|
+
provider = Providers.chooser
|
15
|
+
puts "OpenStack -> #{provider}"
|
16
|
+
@os_compute = DanarchySys::OpenStack::Compute.new provider
|
17
|
+
console
|
18
|
+
end
|
19
|
+
|
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
|
+
def console
|
35
|
+
menu = Menus.numbered_menu('main')
|
36
|
+
Menus.print_menu('main')
|
37
|
+
|
38
|
+
loop do
|
39
|
+
print 'command ~: '
|
40
|
+
cmd = gets.chomp
|
41
|
+
|
42
|
+
next if cmd.empty?
|
43
|
+
if cmd =~ /^[0-9]*$/
|
44
|
+
menu[cmd.to_i].map { |k, v| cmd = k } if menu.keys.include? cmd.to_i
|
45
|
+
end
|
46
|
+
|
47
|
+
if cmd == 'instance'
|
48
|
+
InstanceManager.manager(@os_compute)
|
49
|
+
elsif cmd == 'keypair'
|
50
|
+
puts 'Keypair Manager not yet implemented!'
|
51
|
+
# Keypair.manager(@os_compute)
|
52
|
+
elsif cmd == 'help'
|
53
|
+
Menus.print_menu('main')
|
54
|
+
elsif cmd == 'exit'
|
55
|
+
abort('Exiting!')
|
56
|
+
else
|
57
|
+
Menus.print_menu('main')
|
58
|
+
puts "\nCommand \'#{cmd}\' not available. Enter a command from above."
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
require_relative 'instance_manager/prompts_create_instance'
|
2
|
+
require_relative 'instance_manager/instance_status'
|
3
|
+
|
4
|
+
class InstanceManager
|
5
|
+
def self.manager(os_compute)
|
6
|
+
comp_inst = os_compute.compute_instances
|
7
|
+
puts 'Instance Manager: enter \'help\' to view available commands or \'main\' for the main menu.'
|
8
|
+
menu = Menus.numbered_menu('instance')
|
9
|
+
instance = false
|
10
|
+
|
11
|
+
loop do
|
12
|
+
while instance == false
|
13
|
+
instance = chooser(os_compute)
|
14
|
+
end
|
15
|
+
|
16
|
+
print "#{instance.name} ~: "
|
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('instance')
|
28
|
+
elsif cmd == 'main'
|
29
|
+
return Menus.print_menu('main')
|
30
|
+
elsif cmd == 'chooser'
|
31
|
+
instance = chooser(os_compute)
|
32
|
+
elsif cmd == 'create'
|
33
|
+
PromptsCreateInstance.create_instance(os_compute, 'nil')
|
34
|
+
instance = chooser(os_compute)
|
35
|
+
elsif cmd == 'delete'
|
36
|
+
print "Are you sure you wish to delete instance: #{instance.name}? (this is permanent!) (Y/N): "
|
37
|
+
delete = comp_inst.delete_instance(instance.name) if gets.chomp =~ /^y(es)?$/i
|
38
|
+
if delete == true
|
39
|
+
puts "#{instance.name} has been deleted! Returning to the instance chooser."
|
40
|
+
instance = chooser(os_compute)
|
41
|
+
else
|
42
|
+
puts "#{instance.name} was not deleted!"
|
43
|
+
end
|
44
|
+
elsif cmd == 'status'
|
45
|
+
printf("%#{instance.name.size}s %0s %0s\n", instance.name, ' => ', instance.state)
|
46
|
+
elsif %w(connect pause unpause suspend resume start stop).include?(cmd.to_s)
|
47
|
+
if cmd == 'connect'
|
48
|
+
if instance.state == 'ACTIVE'
|
49
|
+
os_compute.compute_ssh(instance.name.to_s)
|
50
|
+
else
|
51
|
+
puts "Unable to connect: #{instance.name} is not running!"
|
52
|
+
end
|
53
|
+
else
|
54
|
+
response = comp_inst.send(cmd.to_s, instance.name.to_s)
|
55
|
+
# Need to recheck/wait for status update
|
56
|
+
printf("%#{instance.name.size}s %0s %0s\n", instance.name, ' => ', instance.state)
|
57
|
+
end
|
58
|
+
else
|
59
|
+
Menus.print_menu('instance')
|
60
|
+
puts "\nCommand \'#{cmd}\' not available. Enter a command from above."
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.chooser(os_compute)
|
66
|
+
comp_inst = os_compute.compute_instances
|
67
|
+
instances = comp_inst.all_instances
|
68
|
+
instances_numhash = Helpers.objects_to_numhash(instances)
|
69
|
+
instance_name = 'nil'
|
70
|
+
instance = 'nil'
|
71
|
+
|
72
|
+
# Create a new instances if none exist
|
73
|
+
if instances_numhash.empty?
|
74
|
+
print 'No existing instances were found. Should we create a new one? (Y/N): '
|
75
|
+
abort('Exiting!') unless gets.chomp =~ /^y(es)?$/i
|
76
|
+
instance = PromptsCreateInstance.create_instance(os_compute, 'nil')
|
77
|
+
puts "Working with: #{instance.name}\tStatus: #{instance.state}"
|
78
|
+
return instance
|
79
|
+
end
|
80
|
+
|
81
|
+
# Display existing instances in numbered hash
|
82
|
+
fields = PrintFormats.printf_numhash_values(instances_numhash, [:name, :state])
|
83
|
+
|
84
|
+
puts 'Available instances:'
|
85
|
+
InstanceStatus.all_instances(os_compute, instances)
|
86
|
+
|
87
|
+
# Loop input until an existing instance is selected
|
88
|
+
print 'Enter an instance to manage or enter a name for a new instance: '
|
89
|
+
|
90
|
+
until Helpers.check_nested_hash_value(instances_numhash, :name, instance_name) == true
|
91
|
+
instance_name = gets.chomp
|
92
|
+
|
93
|
+
until instance_name.empty? == false
|
94
|
+
print 'Input was blank! Enter an instance or Id from above: '
|
95
|
+
instance_name = gets.chomp
|
96
|
+
end
|
97
|
+
|
98
|
+
abort('Exiting') if instance_name == 'exit'
|
99
|
+
|
100
|
+
# Accept instance Id as an entry
|
101
|
+
if instance_name =~ /^[0-9]*$/
|
102
|
+
until instances_numhash.keys.include?(instance_name.to_i)
|
103
|
+
print "#{instance_name} is not a valid Id. Enter an Id from above: "
|
104
|
+
instance_name = gets.chomp
|
105
|
+
end
|
106
|
+
|
107
|
+
instance_name = instances_numhash[instance_name.to_i][:name].to_s
|
108
|
+
end
|
109
|
+
|
110
|
+
unless Helpers.check_nested_hash_value(instances_numhash, :name, instance_name) == true
|
111
|
+
print "#{instance_name} is not a valid instance.
|
112
|
+
Should we create a new instance named #{instance_name}? (Y/N): "
|
113
|
+
|
114
|
+
if gets.chomp =~ /^y(es)?$/i
|
115
|
+
PromptsCreateInstance.create_instance(os_compute, instance_name)
|
116
|
+
instances_numhash = Helpers.objects_to_numhash(comp_inst.all_instances)
|
117
|
+
else
|
118
|
+
puts "Not creating new instance: #{instance_name}."
|
119
|
+
return false
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
instance = comp_inst.get_instance(instance_name)
|
125
|
+
status = instance.state
|
126
|
+
Menus.print_menu('instance')
|
127
|
+
puts "Managing instance: #{instance_name}\tStatus: #{status}"
|
128
|
+
instance
|
129
|
+
end
|
130
|
+
end
|