danarchy_sys 0.2.11 → 0.2.12

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: 4b9f0bdc147340301c4e38a0e7a0ac6e21e460f3
4
- data.tar.gz: 6a76190f6fb70a06e2b1a523e790f6b4ae98ed4d
3
+ metadata.gz: 8c3d93b8a4b5dc2e84ea69b279f9cfa3a1d86768
4
+ data.tar.gz: c8a4a4278e5f6dada0b10fb7a49731e7392594ad
5
5
  SHA512:
6
- metadata.gz: 538b80212290cd02a4af1acbf27fb070c2538d455704ed3bd58e2edee7c0b0de42d4f721886f0eceb948f2fb751b94190329c03ec08900ac4ec620d0308edabf
7
- data.tar.gz: c44a7faf9216d2d8051295f2bc55819f4eb205a5e6d7b86bf2cb0d2ac91e65e16ad6dca05623f1b4ec835c9d7cbea2c80bd8780b545195954f9d408a1f8bdb87
6
+ metadata.gz: 3f13481bf821158438c740efb0c6e36719a3bd0a8cf09d3fef172c8fcaf506a44bea1ad63daae5a4102ae0888a8c4808666d63fda5fe456ad007fc03a5179fe9
7
+ data.tar.gz: 78082c565241160b920d766334d9f1c01ef60265e2501074a53fbdb2a408dc736e35c4ea3506e83de99ec8b7f3dcfc4660899ad188a87a63503ba05588ab5f92
data/.gitignore CHANGED
@@ -1,3 +1,9 @@
1
+ *~
2
+ *#
3
+ .#*
4
+ \#*#
5
+ .*.sw[a-z]
6
+ *.un~
1
7
  /.bundle/
2
8
  /.yardoc
3
9
  /Gemfile.lock
data/README.txt CHANGED
@@ -4,12 +4,22 @@ Welcome to dAnarchy Systems! This gem will assist you in easing the setup of Ope
4
4
 
5
5
  ## Installation
6
6
 
7
- Requires bundler to be installed already: 'gem install bundler'
7
+ # Pull the gem from RubyGems.org
8
+ gem install danarchy_sys
8
9
 
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.
10
+ # Run 'danarchy_sys' and a first-time setup will prompt you for your connection settings.
11
+ ~ $ danarchy_sys
12
+ No existing configuration found!
13
+ Creating a new OpenStack connection!
14
+ OpenStack Auth URL (Example: http://openstack-host.com:5000/v2.0/tokens)
15
+ Enter URL: http://your_openstack_host.com:5000/v2.0/tokens
16
+ OpenStack Username: your_openstack_username
17
+ OpenStack API Key: your_openstack_api_key
18
+ OpenStack Tenant ID: your_openstack_tenant_id
19
+ Configuration has been saved!
11
20
 
12
- dAnarchySys config setup will be located at danarchy_sys/config/danarchysys.yml in YAML format like this:
21
+
22
+ dAnarchySys config file follows a YAML format like this:
13
23
 
14
24
  :connections:
15
25
  :your_connection:
@@ -17,15 +27,14 @@ dAnarchySys config setup will be located at danarchy_sys/config/danarchysys.yml
17
27
  :openstack_username: openstack_username
18
28
  :openstack_api_key: openstack_api_key
19
29
  :openstack_tenant: openstack_tenant
20
- :settings:
21
- :ssh_key_path: PATH_TO_SSH_KEYS
30
+ :general_settings:
31
+ :ssh_key_path: PATH_TO_SSH_KEYS (this is filled in by default)
22
32
 
33
+ # Once configuration finishes you will enter the main CLI for dAnarchy_sys.
23
34
 
24
35
  ## Usage
25
36
 
26
- Id Provider
27
- 1. os_dreamcompute
28
- Which provider should we use? (enter 'exit' to leave): 1
37
+ ~ $ danarchy_sys
29
38
  OpenStack -> os_dreamcompute
30
39
  dAnarchy_sys main menu commands:
31
40
  Enter 'help' to view available commands or 'exit' to leave.
@@ -2,7 +2,7 @@ module DanarchySys
2
2
  module AWS
3
3
  class Compute
4
4
  def initialize(provider)
5
- config = ConfigMgr.new
5
+ config = ConfigManager.new
6
6
  danarchysys_config = config.load
7
7
  connection = danarchysys_config[:connections][provider]
8
8
  @settings = danarchysys_config[:settings]
@@ -4,7 +4,7 @@ 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 \'help\' to view available commands or \'main\' for the main menu.'
7
+ puts 'Instance Manager: enter \'chooser\' to select an instance, \'help\' to view available commands or \'main\' for the main menu.'
8
8
  menu = Menus.numbered_menu('instance')
9
9
  instance = false
10
10
 
@@ -43,17 +43,33 @@ class InstanceManager
43
43
  end
44
44
  elsif cmd == 'status'
45
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
46
+ elsif %w(pause unpause suspend resume start stop).include?(cmd.to_s)
47
+ status = instance.state
48
+
49
+ if cmd =~ /e$/
50
+ print "#{cmd.gsub(/e$/, 'ing')} #{instance.name} ."
51
+ else
52
+ print "#{cmd}ing #{instance.name} ."
53
+ end
54
+
55
+ response = comp_inst.send(cmd.to_s, instance.name.to_s)
56
+ if response == false
57
+ puts "\nInvalid action for #{instance.name}'s current status!"
58
+ next
59
+ end
60
+
61
+ until status != instance.state
62
+ instance = os_compute.compute_instances.get_instance(instance.name)
63
+ sleep(3)
64
+ print ' .'
65
+ end
66
+
67
+ printf("\n%#{instance.name.size}s %0s %0s\n", instance.name, ' => ', instance.state)
68
+ elsif cmd == 'connect'
69
+ if instance.state == 'ACTIVE'
70
+ os_compute.compute_ssh(instance.name.to_s)
53
71
  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)
72
+ puts "Unable to connect: #{instance.name} is not running!"
57
73
  end
58
74
  else
59
75
  Menus.print_menu('instance')
@@ -31,7 +31,7 @@ class Menus
31
31
  # print_menu(menu)
32
32
  elsif menu == 'instance'
33
33
  puts 'Instance Manager commands: '
34
- puts 'Enter \'help\' to view available commands or \'back\' for the main menu.'
34
+ puts 'Enter \'help\' to view available commands or \'main\' for the main menu.'
35
35
  # print_menu(menu)
36
36
  elsif menu == 'keypair'
37
37
  puts 'Keypair Manager commands: '
@@ -1,8 +1,7 @@
1
1
 
2
2
  class Providers
3
3
  def self.chooser
4
- config = ConfigMgr.new
5
- danarchysys_config = config.load
4
+ danarchysys_config = DanarchySys::ConfigManager::Config.new
6
5
  providers = Helpers.array_to_numhash(danarchysys_config[:connections].keys)
7
6
  provider = 'nil'
8
7
 
@@ -0,0 +1,22 @@
1
+
2
+ module DanarchySys::ConfigManagerNew
3
+ class AWS
4
+ def initialize(provider)
5
+ @provider = provider.to_sym
6
+ end
7
+
8
+ def add_connection(provider, aws_access_key_id, aws_secret_access_key)
9
+ # config = load
10
+
11
+ # config[:connections][provider.to_sym] = {
12
+ # aws_access_key_id: aws_access_key_id,
13
+ # aws_secret_access_key: aws_secret_access_key
14
+ }
15
+ end
16
+
17
+ def delete_connection(provider)
18
+ # config = load
19
+ # config[:connections].delete(provider.to_sym)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,53 @@
1
+
2
+ module DanarchySys::ConfigManager
3
+ class OpenStack
4
+ def initialize(provider, config)
5
+ (@provider, @config) = provider, config
6
+ return
7
+ end
8
+
9
+ def add_connection(provider, openstack_auth_url, openstack_username, openstack_api_key, openstack_tenant)
10
+ @config[:connections][provider.to_sym] = {
11
+ openstack_auth_url: openstack_auth_url,
12
+ openstack_username: openstack_username,
13
+ openstack_api_key: openstack_api_key,
14
+ openstack_tenant: openstack_tenant,
15
+ }
16
+ end
17
+
18
+ def delete_connection
19
+ config = load
20
+ config.delete(@provider)
21
+ end
22
+
23
+ def add_setting(name, value)
24
+ config = load
25
+ # probably need to check if :settings exist first
26
+ config[@provider][:settings][name.to_sym] = value
27
+ end
28
+
29
+ def delete_setting(name)
30
+ config = load
31
+ # check if name exists
32
+ config[@provider][:settings].delete(name.to_sym)
33
+ end
34
+
35
+ def verify_connection
36
+
37
+ end
38
+
39
+ def new_connection_prompt
40
+ print "OpenStack Auth URL\t(Example: http://openstack-host.com:5000/v2.0/tokens)\nEnter URL: "
41
+ openstack_auth_url = gets.chomp
42
+ print 'OpenStack Username: '
43
+ openstack_username = gets.chomp
44
+ print 'OpenStack API Key: '
45
+ openstack_api_key = gets.chomp
46
+ print 'OpenStack Tenant ID: '
47
+ openstack_tenant = gets.chomp
48
+
49
+ add_connection(@provider, openstack_auth_url, openstack_username, openstack_api_key, openstack_tenant)
50
+ @config
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,99 @@
1
+ require 'yaml'
2
+ require_relative 'config_manager/openstack'
3
+
4
+ # dAnarchy_sys config management
5
+ module DanarchySys
6
+ module ConfigManager
7
+ class Config
8
+ def self.new
9
+ @danarchysys_path = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
10
+ @config_file = File.join(@danarchysys_path, 'config', 'danarchysys.yml')
11
+
12
+ if File.exists?(@config_file)
13
+ return YAML.load_file(@config_file)
14
+ else
15
+ puts 'No existing configuration found!'
16
+ return new_config
17
+ end
18
+ end
19
+
20
+ def self.providers
21
+ ['openstack'] # , 'aws']
22
+ end
23
+
24
+ def self.config_template
25
+ config_template = {
26
+ global_settings: {
27
+ ssh_key_path: "#{@danarchysys_path}/config/ssh"
28
+ },
29
+ connections: {}
30
+ }
31
+ end
32
+
33
+ def self.new_config
34
+ config = config_template
35
+
36
+ provider = nil
37
+ if providers.count > 1
38
+ num_providers = Helpers.array_to_numhash(providers)
39
+ fields = PrintFormats.printf_hash(num_providers)
40
+
41
+ printf("#{fields}\n", 'Id', 'Provider')
42
+ num_providers.each do |k, v|
43
+ printf("#{fields}\n", "#{k}.", v)
44
+ end
45
+
46
+ provider = nil
47
+ until providers.include?(provider)
48
+ print 'Please choose a provider: '
49
+ provider = gets.chomp
50
+
51
+ if provider =~ /^[0-9]*$/
52
+ if num_providers.keys.include?(provider)
53
+ provider = num_providers[provider]
54
+ else
55
+ print "#{provider} is not a valid Id. "
56
+ end
57
+ end
58
+
59
+ if provider.empty? || providers.include?(provider) == false
60
+ print 'Invalid input! '
61
+ end
62
+ end
63
+ else
64
+ provider = providers[0]
65
+ end
66
+
67
+ if provider == 'openstack'
68
+ puts 'Creating a new OpenStack connection!'
69
+ print 'Enter a provider name for this connection: '
70
+ provider = gets.chomp
71
+ cfg_os = DanarchySys::ConfigManager::OpenStack.new(provider, config)
72
+ config = cfg_os.new_connection_prompt
73
+ elsif provider == 'aws'
74
+ # Placeholder
75
+ puts 'AWS not yet implemented!'
76
+ end
77
+
78
+ save(config)
79
+ puts 'Configuration has been saved!'
80
+ config
81
+ end
82
+
83
+ def self.save(param_hash)
84
+ File.write(@config_file, param_hash.to_yaml)
85
+ end
86
+
87
+
88
+ def self.global_setting_add(name, value)
89
+ config = load
90
+ config[:global_settings][name.to_sym] = value
91
+ end
92
+
93
+ def self.global_setting_delete(name)
94
+ config = load
95
+ config[:global_settings].delete(name.to_sym)
96
+ end
97
+ end
98
+ end
99
+ end
@@ -48,9 +48,15 @@ class ComputeInstances
48
48
 
49
49
  def get_addresses(instance_name)
50
50
  instance = get_instance(instance_name)
51
+ (ipv6, ipv4) = nil, nil
52
+ addresses = instance.addresses['public']
51
53
 
52
- addresses = instance.addresses['public']
53
- ipv6, ipv4 = addresses[0], addresses[1]
54
+ addresses.each do |i|
55
+ ipv4 = i['addr'] if i['addr'].include?('.')
56
+ ipv6 = i['addr'] if i['addr'].include?(':')
57
+ end
58
+
59
+ return ipv4, ipv6
54
60
  end
55
61
 
56
62
  def pause(instance_name)
@@ -3,7 +3,7 @@ require 'fog/openstack'
3
3
  require_relative '../../../../danarchy_sys'
4
4
 
5
5
  provider = 'os_dreamcompute'.to_sym
6
- config = ConfigMgr.new
6
+ config = ConfigManager.new
7
7
  danarchysys_config = config.load
8
8
 
9
9
  connection = danarchysys_config[:connections][provider]
@@ -7,10 +7,9 @@ module DanarchySys
7
7
  module OpenStack
8
8
  class Compute
9
9
  def initialize(provider)
10
- config = ConfigMgr.new
11
- danarchysys_config = config.load
12
- connection = danarchysys_config[:connections][provider]
13
- @settings = danarchysys_config[:settings]
10
+ danarchysys_config = DanarchySys::ConfigManager::Config.new
11
+ connection = danarchysys_config[:connections][provider.to_sym]
12
+ @settings = danarchysys_config[:global_settings]
14
13
  @compute = Fog::Compute::OpenStack.new(connection)
15
14
  end
16
15
 
@@ -49,7 +48,7 @@ module DanarchySys
49
48
  user = image.name.downcase.split('-')[0]
50
49
  end
51
50
 
52
- ipv4 = comp_inst.get_addresses(instance_name)[1]['addr']
51
+ ipv4, ipv6 = comp_inst.get_addresses(instance_name)
53
52
 
54
53
  ssh = "ssh #{user}@#{ipv4} -i '#{pemfile}'"
55
54
  system(ssh)
@@ -1,3 +1,3 @@
1
1
  module DanarchySys
2
- VERSION = "0.2.11"
2
+ VERSION = "0.2.12"
3
3
  end
data/lib/danarchy_sys.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'fog/openstack'
3
3
  require_relative 'danarchy_sys/version'
4
4
  require_relative 'danarchy_sys/helpers'
5
- require_relative 'danarchy_sys/config'
5
+ require_relative 'danarchy_sys/config_manager'
6
6
  require_relative 'danarchy_sys/printformats'
7
7
 
8
8
  module DanarchySys
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.11
4
+ version: 0.2.12
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-04 00:00:00.000000000 Z
11
+ date: 2017-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog-openstack
@@ -79,8 +79,6 @@ email:
79
79
  executables:
80
80
  - console
81
81
  - danarchy_sys
82
- - setup
83
- - setup.rb
84
82
  extensions: []
85
83
  extra_rdoc_files: []
86
84
  files:
@@ -93,8 +91,6 @@ files:
93
91
  - Rakefile
94
92
  - bin/console
95
93
  - bin/danarchy_sys
96
- - bin/setup
97
- - bin/setup.rb
98
94
  - config/.gitignore
99
95
  - danarchy_sys.gemspec
100
96
  - lib/danarchy_sys.rb
@@ -106,7 +102,9 @@ files:
106
102
  - lib/danarchy_sys/cli/instance_manager/prompts_create_instance.rb
107
103
  - lib/danarchy_sys/cli/menus.rb
108
104
  - lib/danarchy_sys/cli/providers.rb
109
- - lib/danarchy_sys/config.rb
105
+ - lib/danarchy_sys/config_manager.rb
106
+ - lib/danarchy_sys/config_manager/aws.rb
107
+ - lib/danarchy_sys/config_manager/openstack.rb
110
108
  - lib/danarchy_sys/helpers.rb
111
109
  - lib/danarchy_sys/openstack.rb
112
110
  - lib/danarchy_sys/openstack/compute.rb
data/bin/setup DELETED
@@ -1,18 +0,0 @@
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 DELETED
@@ -1,86 +0,0 @@
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!"
@@ -1,66 +0,0 @@
1
-
2
- require 'yaml'
3
-
4
- # dAnarchy_sys config management
5
- class ConfigMgr
6
- def initialize
7
- @danarchysys_path = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
8
- @config_file = File.join(@danarchysys_path, 'config', 'danarchysys.yml')
9
- end
10
-
11
- def config_template
12
- config_template = {
13
- :connections => {},
14
- :settings => {}
15
- }
16
- end
17
-
18
- def load
19
- if File.exists?(@config_file)
20
- return YAML.load_file(@config_file)
21
- else
22
- return config_template
23
- end
24
- end
25
-
26
- def save(param_hash)
27
- File.write(@config_file, param_hash.to_yaml)
28
- end
29
-
30
- def connection_add(provider, openstack_auth_url, openstack_username, openstack_api_key, openstack_tenant)
31
- danarchysys_config = load
32
-
33
- danarchysys_config[:connections][provider.to_sym] = {
34
- openstack_auth_url: openstack_auth_url,
35
- openstack_username: openstack_username,
36
- openstack_api_key: openstack_api_key,
37
- openstack_tenant: openstack_tenant
38
- }
39
-
40
- danarchysys_config
41
- end
42
-
43
- def connection_delete(provider)
44
- danarchysys_config = load
45
-
46
- danarchysys_config[:connections].delete(provider.to_sym)
47
-
48
- danarchysys_config
49
- end
50
-
51
- def setting_add(name, value)
52
- danarchysys_config = load
53
-
54
- danarchysys_config[:settings][name.to_sym] = value
55
-
56
- danarchysys_config
57
- end
58
-
59
- def setting_delete(name)
60
- danarchysys_config = load
61
-
62
- danarchysys_config[:settings].delete(name.to_sym)
63
-
64
- danarchysys_config
65
- end
66
- end