danarchy_sys 0.4.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/danarchy_sys/cli.rb +4 -4
- data/lib/danarchy_sys/cli/accounts.rb +34 -0
- data/lib/danarchy_sys/config_manager.rb +20 -18
- data/lib/danarchy_sys/config_manager/openstack.rb +7 -8
- data/lib/danarchy_sys/openstack/compute.rb +2 -2
- data/lib/danarchy_sys/version.rb +1 -1
- metadata +3 -3
- data/lib/danarchy_sys/cli/providers.rb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: adecf679edce8c1ee9beb96a09bb6fcc2c0aa4e5
|
4
|
+
data.tar.gz: c4dc4fab6af857af55e3df53ffdef2e801047135
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ca0a7287b20ed0e6c1f471a53c059cb65369f914a7f5c2cf48d8b7ce23550f3e9a1e4085dfe3d7290c86c2a5bc0dbfad56b2af442edc3f28f8285d68cf3e49d
|
7
|
+
data.tar.gz: 4e35702b99b60700de00d0a1ecb87bfa77f7e566dc8e94e845aedfc0a6524e1190b065b2a3bdd78a5abcf3aa1e8e2664852e214eb9ef2868fcabeb700d1c6106
|
data/lib/danarchy_sys/cli.rb
CHANGED
@@ -7,13 +7,13 @@ module DanarchySys
|
|
7
7
|
class CLI
|
8
8
|
def initialize
|
9
9
|
require_relative 'cli/menus'
|
10
|
-
require_relative 'cli/
|
10
|
+
require_relative 'cli/accounts'
|
11
11
|
require_relative 'cli/instance_manager'
|
12
12
|
require_relative 'cli/keypair_manager'
|
13
13
|
|
14
|
-
|
15
|
-
puts "OpenStack -> #{
|
16
|
-
@os_compute = DanarchySys::OpenStack::Compute.new
|
14
|
+
account = Accounts.chooser
|
15
|
+
puts "OpenStack -> #{account}"
|
16
|
+
@os_compute = DanarchySys::OpenStack::Compute.new account
|
17
17
|
console
|
18
18
|
end
|
19
19
|
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
class Accounts
|
3
|
+
def self.chooser
|
4
|
+
danarchysys_config = DanarchySys::ConfigManager::Config.new
|
5
|
+
accounts = Helpers.array_to_numhash(danarchysys_config[:accounts].keys)
|
6
|
+
account = 'nil'
|
7
|
+
|
8
|
+
if accounts.count == 1
|
9
|
+
account = accounts[1]
|
10
|
+
return account
|
11
|
+
end
|
12
|
+
|
13
|
+
fields = PrintFormats.printf_hash(accounts)
|
14
|
+
printf("#{fields}\n", 'Id', 'Account')
|
15
|
+
accounts.each do |id, account|
|
16
|
+
printf("#{fields}\n", "#{id}.", account)
|
17
|
+
end
|
18
|
+
|
19
|
+
until accounts.values.include?(account)
|
20
|
+
print 'Which account should we use? (enter \'exit\' to leave): '
|
21
|
+
account = gets.chomp
|
22
|
+
|
23
|
+
abort('Exiting') if account == 'exit'
|
24
|
+
|
25
|
+
if account =~ /^[0-9]*$/
|
26
|
+
account = accounts[account.to_i]
|
27
|
+
else
|
28
|
+
account = account.to_sym
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
account
|
33
|
+
end
|
34
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'fileutils'
|
2
|
-
require '
|
2
|
+
require 'json'
|
3
3
|
require_relative 'config_manager/openstack'
|
4
4
|
|
5
5
|
# dAnarchy_sys config management
|
@@ -8,13 +8,13 @@ module DanarchySys
|
|
8
8
|
class Config
|
9
9
|
def self.new
|
10
10
|
danarchysys_cfg_path = File.join(File.realpath(ENV['HOME']), '.danarchy_sys')
|
11
|
-
|
11
|
+
config_json = File.join(danarchysys_cfg_path, 'danarchy_sys.json')
|
12
12
|
|
13
|
-
if File.exists?(
|
14
|
-
return
|
13
|
+
if File.exists?(config_json)
|
14
|
+
return JSON.parse(File.read(config_json), symbolize_names: true)
|
15
15
|
else
|
16
16
|
puts 'No existing configuration found!'
|
17
|
-
return new_config(danarchysys_cfg_path,
|
17
|
+
return new_config(danarchysys_cfg_path, config_json)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -27,11 +27,11 @@ module DanarchySys
|
|
27
27
|
global_settings: {
|
28
28
|
ssh_key_path: nil
|
29
29
|
},
|
30
|
-
|
30
|
+
accounts: {}
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
34
|
-
def self.new_config(danarchysys_cfg_path,
|
34
|
+
def self.new_config(danarchysys_cfg_path, config_json)
|
35
35
|
config = config_template
|
36
36
|
ssh_path = File.join(danarchysys_cfg_path, 'ssh')
|
37
37
|
|
@@ -68,8 +68,8 @@ module DanarchySys
|
|
68
68
|
provider = gets.chomp
|
69
69
|
|
70
70
|
if provider =~ /^[0-9]*$/
|
71
|
-
if num_providers.keys.include?(provider)
|
72
|
-
provider = num_providers[provider]
|
71
|
+
if num_providers.keys.include?(provider.to_i)
|
72
|
+
provider = num_providers[provider.to_i]
|
73
73
|
else
|
74
74
|
print "#{provider} is not a valid Id. "
|
75
75
|
end
|
@@ -80,28 +80,30 @@ module DanarchySys
|
|
80
80
|
end
|
81
81
|
end
|
82
82
|
else
|
83
|
-
provider = providers[0]
|
83
|
+
provider = providers[0] # default to OpenStack
|
84
84
|
end
|
85
85
|
|
86
|
-
if provider == '
|
87
|
-
puts '
|
88
|
-
|
86
|
+
if provider == 'danarchy'
|
87
|
+
puts 'Need to implement setup for dAnarchy!'
|
88
|
+
elsif provider == 'openstack'
|
89
|
+
puts 'Adding a new OpenStack account!'
|
90
|
+
print 'Enter a provider name for this account: '
|
89
91
|
provider = gets.chomp
|
90
|
-
|
91
|
-
config =
|
92
|
+
cfg_openstack = DanarchySys::ConfigManager::OpenStack.new(provider, config)
|
93
|
+
config = cfg_openstack.new_account_prompt
|
92
94
|
elsif provider == 'aws'
|
93
95
|
# Placeholder
|
94
96
|
puts 'AWS not yet implemented!'
|
95
97
|
end
|
96
98
|
|
97
|
-
save(
|
98
|
-
puts "Configuration has been saved to #{
|
99
|
+
save(config_json, config)
|
100
|
+
puts "Configuration has been saved to #{config_json}"
|
99
101
|
puts "Copy any existing #{provider} SSH keys to: #{ssh_path}"
|
100
102
|
config
|
101
103
|
end
|
102
104
|
|
103
105
|
def self.save(config_file, param_hash)
|
104
|
-
File.write(config_file, param_hash
|
106
|
+
File.write(config_file, JSON.pretty_generate(param_hash))
|
105
107
|
end
|
106
108
|
|
107
109
|
|
@@ -3,11 +3,10 @@ module DanarchySys::ConfigManager
|
|
3
3
|
class OpenStack
|
4
4
|
def initialize(provider, config)
|
5
5
|
(@provider, @config) = provider, config
|
6
|
-
return
|
7
6
|
end
|
8
7
|
|
9
|
-
def
|
10
|
-
@config[:
|
8
|
+
def add_account(provider, openstack_auth_url, openstack_username, openstack_api_key, openstack_tenant)
|
9
|
+
@config[:accounts][provider.to_sym] = {
|
11
10
|
openstack_auth_url: openstack_auth_url,
|
12
11
|
openstack_username: openstack_username,
|
13
12
|
openstack_api_key: openstack_api_key,
|
@@ -15,14 +14,14 @@ module DanarchySys::ConfigManager
|
|
15
14
|
}
|
16
15
|
end
|
17
16
|
|
18
|
-
def
|
17
|
+
def delete_account
|
19
18
|
config = load
|
20
19
|
config.delete(@provider)
|
21
20
|
end
|
22
21
|
|
23
22
|
def add_setting(name, value)
|
24
23
|
config = load
|
25
|
-
|
24
|
+
config[@provider][:settings] = {} if !config[@provider][:settings]
|
26
25
|
config[@provider][:settings][name.to_sym] = value
|
27
26
|
end
|
28
27
|
|
@@ -32,11 +31,11 @@ module DanarchySys::ConfigManager
|
|
32
31
|
config[@provider][:settings].delete(name.to_sym)
|
33
32
|
end
|
34
33
|
|
35
|
-
def
|
34
|
+
def verify_account
|
36
35
|
|
37
36
|
end
|
38
37
|
|
39
|
-
def
|
38
|
+
def new_account_prompt
|
40
39
|
print "OpenStack Auth URL\t(Example: http://openstack-host.com:5000/v2.0/tokens)\nEnter URL: "
|
41
40
|
openstack_auth_url = gets.chomp
|
42
41
|
print 'OpenStack Username: '
|
@@ -46,7 +45,7 @@ module DanarchySys::ConfigManager
|
|
46
45
|
print 'OpenStack Tenant ID: '
|
47
46
|
openstack_tenant = gets.chomp
|
48
47
|
|
49
|
-
|
48
|
+
add_account(@provider, openstack_auth_url, openstack_username, openstack_api_key, openstack_tenant)
|
50
49
|
@config
|
51
50
|
end
|
52
51
|
end
|
@@ -6,9 +6,9 @@ require_relative 'compute/flavors'
|
|
6
6
|
module DanarchySys
|
7
7
|
module OpenStack
|
8
8
|
class Compute
|
9
|
-
def initialize(
|
9
|
+
def initialize(account)
|
10
10
|
danarchysys_config = DanarchySys::ConfigManager::Config.new
|
11
|
-
connection = danarchysys_config[:
|
11
|
+
connection = danarchysys_config[:accounts][account.to_sym]
|
12
12
|
@settings = danarchysys_config[:global_settings]
|
13
13
|
@compute = Fog::Compute::OpenStack.new(connection)
|
14
14
|
@instances = @compute.servers
|
data/lib/danarchy_sys/version.rb
CHANGED
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.
|
4
|
+
version: 0.5.0
|
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-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fog-openstack
|
@@ -94,13 +94,13 @@ files:
|
|
94
94
|
- danarchy_sys.gemspec
|
95
95
|
- lib/danarchy_sys.rb
|
96
96
|
- lib/danarchy_sys/cli.rb
|
97
|
+
- lib/danarchy_sys/cli/accounts.rb
|
97
98
|
- lib/danarchy_sys/cli/instance_manager.rb
|
98
99
|
- lib/danarchy_sys/cli/instance_manager/instance_status.rb
|
99
100
|
- lib/danarchy_sys/cli/instance_manager/prompts_create_instance.rb
|
100
101
|
- lib/danarchy_sys/cli/keypair_manager.rb
|
101
102
|
- lib/danarchy_sys/cli/keypair_manager/keypair_status.rb
|
102
103
|
- lib/danarchy_sys/cli/menus.rb
|
103
|
-
- lib/danarchy_sys/cli/providers.rb
|
104
104
|
- lib/danarchy_sys/config_manager.rb
|
105
105
|
- lib/danarchy_sys/config_manager/aws.rb
|
106
106
|
- lib/danarchy_sys/config_manager/openstack.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
|
2
|
-
class Providers
|
3
|
-
def self.chooser
|
4
|
-
danarchysys_config = DanarchySys::ConfigManager::Config.new
|
5
|
-
providers = Helpers.array_to_numhash(danarchysys_config[:connections].keys)
|
6
|
-
provider = 'nil'
|
7
|
-
|
8
|
-
if providers.count == 1
|
9
|
-
provider = providers[1]
|
10
|
-
return provider
|
11
|
-
end
|
12
|
-
|
13
|
-
fields = PrintFormats.printf_hash(providers)
|
14
|
-
printf("#{fields}\n", 'Id', 'Provider')
|
15
|
-
providers.each do |id, provider|
|
16
|
-
printf("#{fields}\n", "#{id}.", provider)
|
17
|
-
end
|
18
|
-
|
19
|
-
until providers.values.include?(provider)
|
20
|
-
print 'Which provider should we use? (enter \'exit\' to leave): '
|
21
|
-
provider = gets.chomp
|
22
|
-
|
23
|
-
abort('Exiting') if provider == 'exit'
|
24
|
-
|
25
|
-
if provider =~ /^[0-9]*$/
|
26
|
-
provider = providers[provider.to_i]
|
27
|
-
else
|
28
|
-
provider = provider.to_sym
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
provider
|
33
|
-
end
|
34
|
-
end
|