sistero 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/sistero +49 -28
- data/lib/sistero/config.rb +63 -0
- data/lib/sistero/version.rb +1 -1
- data/lib/sistero.rb +37 -61
- data/readme.md +49 -0
- metadata +4 -3
- data/README.md +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdd66f2da7e7ea38ca56f0d04c109514d747d438
|
4
|
+
data.tar.gz: 033a3a3595eae6e1b9d4fd1c0b3ace83b23364c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d7b12ca75bcc2b361bc68cef3d1222fe0fdeddd9950a75b4e24b62c63f370b3dad83da3fac83276f037de5f41eed70d567b7b5dd83a608ae7a0c7556dafe04cc
|
7
|
+
data.tar.gz: 2a020dbeeff2bf026266b2a57ce4fe826e107d74a58434914fd51b9aeb5853387fa63c47438e45d27127b670b8f6950ce33be5d300f48eb9808465ba0904852e
|
data/bin/sistero
CHANGED
@@ -20,13 +20,15 @@ module Sistero::Command
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.parse_opts op
|
24
|
-
|
23
|
+
def self.parse_opts op, args
|
24
|
+
args = @config.args = args.clone
|
25
|
+
op.order! args
|
26
|
+
raise "must supply subcommand" if args.empty?
|
25
27
|
|
26
|
-
action =
|
28
|
+
action = args.first
|
27
29
|
subcmd_meta = @subcommands[action]
|
28
|
-
raise "invalid subcommand #{action}" unless @subcommands.has_key? action
|
29
|
-
|
30
|
+
raise "invalid subcommand: #{action}" unless @subcommands.has_key? action
|
31
|
+
args.shift
|
30
32
|
|
31
33
|
@config.action = action
|
32
34
|
OptionParser.new do |subop|
|
@@ -34,11 +36,10 @@ module Sistero::Command
|
|
34
36
|
with_help subop
|
35
37
|
parse_cmdline = subcmd_meta[:parse_cmdline]
|
36
38
|
parse_cmdline.call(subop) if parse_cmdline
|
37
|
-
end.order!
|
38
|
-
@config.action_arg = ARGV[0]
|
39
|
+
end.order! args
|
39
40
|
end
|
40
41
|
|
41
|
-
def self.run
|
42
|
+
def self.run args
|
42
43
|
OptionParser.new do |op|
|
43
44
|
@op = op
|
44
45
|
|
@@ -56,6 +57,10 @@ module Sistero::Command
|
|
56
57
|
exit
|
57
58
|
end
|
58
59
|
|
60
|
+
op.on '-c', '--config file', 'override path to config file' do |cfg_file_path|
|
61
|
+
@config.cfg_file_path = cfg_file_path
|
62
|
+
end
|
63
|
+
|
59
64
|
subcommand 'ssh', 'ssh to vm' do |subop|
|
60
65
|
subop.on '-o val', 'add ssh options' do |ssh_options|
|
61
66
|
@config.ssh_options = ssh_options
|
@@ -70,7 +75,15 @@ module Sistero::Command
|
|
70
75
|
|
71
76
|
subcommand 'show-config', 'show configuration'
|
72
77
|
|
73
|
-
|
78
|
+
subcommand 'ssh-keys', 'show ssh keys'
|
79
|
+
|
80
|
+
subcommand 'sizes', 'show possible sizes'
|
81
|
+
|
82
|
+
subcommand 'regions', 'show possible regions'
|
83
|
+
|
84
|
+
subcommand 'images', 'show images'
|
85
|
+
|
86
|
+
parse_opts op, args
|
74
87
|
end
|
75
88
|
|
76
89
|
unless @config.action
|
@@ -78,26 +91,34 @@ module Sistero::Command
|
|
78
91
|
exit
|
79
92
|
end
|
80
93
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
94
|
+
sistero = Sistero::Instance.new({ cfg_file_path: @config.cfg_file_path })
|
95
|
+
case @config.action
|
96
|
+
when 'ssh'
|
97
|
+
vm_name, *ssh_args = @config.args
|
98
|
+
# TODO: pass ssh_args
|
99
|
+
sistero.ssh_to_vm(vm_name, ssh_options: @config.ssh_options)
|
100
|
+
when 'create'
|
101
|
+
vms = @config.args.empty? ? [nil] : @config.args
|
102
|
+
vms.each { |vm_name| sistero.create_vm(vm_name) }
|
103
|
+
when 'destroy'
|
104
|
+
vms = @config.args.empty? ? [nil] : @config.args
|
105
|
+
vms.each { |vm_name| sistero.destroy_vm(vm_name) }
|
106
|
+
when 'list'
|
107
|
+
sistero.list_vms()
|
108
|
+
when 'show-config'
|
109
|
+
sistero.show_config()
|
110
|
+
when 'ssh-keys'
|
111
|
+
sistero.show_ssh_keys()
|
112
|
+
when 'sizes'
|
113
|
+
sistero.show_sizes()
|
114
|
+
when 'regions'
|
115
|
+
sistero.show_regions()
|
116
|
+
when 'images'
|
117
|
+
sistero.show_images()
|
99
118
|
end
|
119
|
+
rescue RuntimeError => e
|
120
|
+
puts e.to_s
|
100
121
|
end
|
101
122
|
end
|
102
123
|
|
103
|
-
Sistero::Command::run
|
124
|
+
Sistero::Command::run ARGV.clone if __FILE__ == $0
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require "yaml"
|
2
|
+
APP_NAME = "sistero"
|
3
|
+
|
4
|
+
module Sistero
|
5
|
+
PROFILE_KEYS = [:vm_name, :vm_size, :vm_region, :vm_image, :access_token, :ssh_keys, :ssh_options]
|
6
|
+
|
7
|
+
Profile = Struct.new(*PROFILE_KEYS) do
|
8
|
+
def to_s
|
9
|
+
"vm #{vm_name}\n" + PROFILE_KEYS.map do |key|
|
10
|
+
val = self[key]
|
11
|
+
if val and key != :vm_name
|
12
|
+
" #{key} #{val}\n"
|
13
|
+
else
|
14
|
+
""
|
15
|
+
end
|
16
|
+
end.join
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Config
|
21
|
+
attr_accessor :defaults, :profiles
|
22
|
+
|
23
|
+
def profile vm_name
|
24
|
+
if @defaults['vm_name'] and vm_name.nil?
|
25
|
+
profile = @defaults
|
26
|
+
else
|
27
|
+
# TODO: also handle wildcards
|
28
|
+
profile = @profiles.find do |profile|
|
29
|
+
profile.vm_name == vm_name
|
30
|
+
end
|
31
|
+
raise "could not find profile for #{vm_name}" unless profile
|
32
|
+
end
|
33
|
+
profile
|
34
|
+
end
|
35
|
+
|
36
|
+
def initialize(opts = {})
|
37
|
+
# read defaults from config file
|
38
|
+
cfg_file_path = opts[:cfg_file_path] || "#{ENV['HOME']}/.config/#{APP_NAME}"
|
39
|
+
|
40
|
+
@defaults = Profile.new
|
41
|
+
@profiles = []
|
42
|
+
|
43
|
+
cfg = YAML.load_file cfg_file_path
|
44
|
+
cfg['defaults'].each do |key, value|
|
45
|
+
@defaults[key] = value
|
46
|
+
end
|
47
|
+
|
48
|
+
@profiles = cfg['profiles'].map do |profile_cfg|
|
49
|
+
profile = Profile.new *@defaults
|
50
|
+
profile_cfg.each do |key, value|
|
51
|
+
profile[key] = value
|
52
|
+
end
|
53
|
+
profile
|
54
|
+
end
|
55
|
+
|
56
|
+
@profiles.push(@defaults) if @defaults.vm_name
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_s
|
60
|
+
@profiles.map(&:to_s).join "\n"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/sistero/version.rb
CHANGED
data/lib/sistero.rb
CHANGED
@@ -1,68 +1,8 @@
|
|
1
1
|
require "sistero/version"
|
2
|
-
require "
|
2
|
+
require "sistero/config"
|
3
3
|
require "droplet_kit"
|
4
4
|
|
5
|
-
APP_NAME = "sistero"
|
6
|
-
|
7
5
|
module Sistero
|
8
|
-
PROFILE_KEYS = [:vm_name, :vm_size, :vm_region, :vm_image, :access_token, :ssh_keys, :ssh_options]
|
9
|
-
|
10
|
-
Profile = Struct.new(*PROFILE_KEYS) do
|
11
|
-
def to_s
|
12
|
-
"vm #{vm_name}\n" + PROFILE_KEYS.map do |key|
|
13
|
-
val = self[key]
|
14
|
-
if val and key != :vm_name
|
15
|
-
" #{key} #{val}\n"
|
16
|
-
else
|
17
|
-
""
|
18
|
-
end
|
19
|
-
end.join
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
class Config
|
24
|
-
attr_accessor :defaults, :profiles
|
25
|
-
|
26
|
-
def profile vm_name
|
27
|
-
if @defaults['vm_name'] and vm_name.nil?
|
28
|
-
profile = @defaults
|
29
|
-
else
|
30
|
-
# TODO: also handle wildcards
|
31
|
-
profile = @profiles.find do |profile|
|
32
|
-
profile.vm_name == vm_name
|
33
|
-
end
|
34
|
-
raise "could not find profile for #{vm_name}" unless profile
|
35
|
-
end
|
36
|
-
profile
|
37
|
-
end
|
38
|
-
|
39
|
-
def initialize(opts = {})
|
40
|
-
# read defaults from config file
|
41
|
-
cfg_file_path = "#{ENV['HOME']}/.config/#{APP_NAME}"
|
42
|
-
@defaults = Profile.new
|
43
|
-
@profiles = []
|
44
|
-
|
45
|
-
cfg = YAML.load_file cfg_file_path
|
46
|
-
cfg['defaults'].each do |key, value|
|
47
|
-
@defaults[key] = value
|
48
|
-
end
|
49
|
-
|
50
|
-
@profiles = cfg['profiles'].map do |profile_cfg|
|
51
|
-
profile = Profile.new *@defaults
|
52
|
-
profile_cfg.each do |key, value|
|
53
|
-
profile[key] = value
|
54
|
-
end
|
55
|
-
profile
|
56
|
-
end
|
57
|
-
|
58
|
-
@profiles.push(@defaults) if @defaults['vm_name']
|
59
|
-
end
|
60
|
-
|
61
|
-
def to_s
|
62
|
-
@profiles.map(&:to_s).join "\n"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
6
|
class Instance
|
67
7
|
def initialize(opts = {})
|
68
8
|
@config = Config.new(opts)
|
@@ -159,5 +99,41 @@ module Sistero
|
|
159
99
|
def show_config
|
160
100
|
puts @config.to_s
|
161
101
|
end
|
102
|
+
|
103
|
+
def show_ssh_keys
|
104
|
+
@client.ssh_keys.all().each do |key|
|
105
|
+
puts "#{key.name}: #{key.id}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def show_sizes
|
110
|
+
@client.sizes.all().each do |size|
|
111
|
+
puts "size #{size.slug}"
|
112
|
+
puts " regions #{size.regions.join ', '}"
|
113
|
+
puts " available #{size.available}"
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def show_regions
|
118
|
+
@client.regions.all().each do |region|
|
119
|
+
puts "region #{region.slug}" + (region.available ? '' : ' (unavailable)')
|
120
|
+
puts " name #{region.name}"
|
121
|
+
if region.available
|
122
|
+
puts " sizes #{region.sizes.join ', '}"
|
123
|
+
puts " features #{region.features.join ', '}"
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def show_images
|
129
|
+
@client.images.all().each do |image|
|
130
|
+
puts "image #{image.slug}"
|
131
|
+
puts " name #{image.name}"
|
132
|
+
puts " distribution #{image.distribution}"
|
133
|
+
puts " public #{image.public}"
|
134
|
+
puts " type #{image.type}"
|
135
|
+
puts " regions #{image.regions.join ', '}"
|
136
|
+
end
|
137
|
+
end
|
162
138
|
end
|
163
139
|
end
|
data/readme.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Sistero
|
2
|
+
|
3
|
+
sistero is a profile based tool to manage a digital ocean cluster.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```gem install sistero```
|
8
|
+
|
9
|
+
## Configuration
|
10
|
+
|
11
|
+
The configuration file lives at `.config/sistero`, an example looks like this:
|
12
|
+
|
13
|
+
```
|
14
|
+
defaults:
|
15
|
+
vm_name: default-vm
|
16
|
+
ssh_keys:
|
17
|
+
- 1234567
|
18
|
+
ssh_options: -D1080 -A
|
19
|
+
access_token: f788fffffffffffff8ffffffffffffffffffffff8fffffffffffffffffffffff
|
20
|
+
vm_size: 512mb
|
21
|
+
vm_region: nyc3
|
22
|
+
vm_image: ubuntu-14-04-x64
|
23
|
+
profiles:
|
24
|
+
-
|
25
|
+
vm_name: london-vm
|
26
|
+
vm_region: lon1
|
27
|
+
-
|
28
|
+
vm_name: london-bigger-vm
|
29
|
+
vm_region: lon1
|
30
|
+
vm_size: 1gb
|
31
|
+
```
|
32
|
+
|
33
|
+
Any values not specified in a profile are taken from `defaults`. If the `defaults` entry specifies a `vm_name` then it becomes the default VM for the `create`, `ssh` and `destroy` commands.
|
34
|
+
|
35
|
+
The `ssh_keys` is a list of ID numbers (rather than names) of ssh keys, these can be found by running `sistero ssh-keys`.
|
36
|
+
|
37
|
+
The valid options for `region`, `vm_size` and `vm_image` can be found by running `sistero regions`, `sistero sizes` and `sistero images` respectively.
|
38
|
+
|
39
|
+
## Running
|
40
|
+
|
41
|
+
Assuming the previous config file, to create a VM in new york called default-vm:
|
42
|
+
```
|
43
|
+
sistero create
|
44
|
+
```
|
45
|
+
|
46
|
+
Or to create a VM called `london-vm` in london:
|
47
|
+
```
|
48
|
+
sistero create london-vm
|
49
|
+
```
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sistero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Pike
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,13 +80,14 @@ files:
|
|
80
80
|
- ".rspec"
|
81
81
|
- ".travis.yml"
|
82
82
|
- Gemfile
|
83
|
-
- README.md
|
84
83
|
- Rakefile
|
85
84
|
- bin/console
|
86
85
|
- bin/setup
|
87
86
|
- bin/sistero
|
88
87
|
- lib/sistero.rb
|
88
|
+
- lib/sistero/config.rb
|
89
89
|
- lib/sistero/version.rb
|
90
|
+
- readme.md
|
90
91
|
- sistero.gemspec
|
91
92
|
homepage: http://github.com/ohjames/sistero
|
92
93
|
licenses: []
|
data/README.md
DELETED
@@ -1,44 +0,0 @@
|
|
1
|
-
# Sistero
|
2
|
-
|
3
|
-
sistero is a profile based tool to manage a digital ocean cluster.
|
4
|
-
|
5
|
-
## Installation
|
6
|
-
|
7
|
-
```gem install sistero```
|
8
|
-
|
9
|
-
## Usage
|
10
|
-
|
11
|
-
Create a config file at `.config/sistero` with something like:
|
12
|
-
|
13
|
-
```
|
14
|
-
---
|
15
|
-
defaults:
|
16
|
-
vm_name: default-vm
|
17
|
-
ssh_keys:
|
18
|
-
- 1234567
|
19
|
-
ssh_options: -D1080 -A
|
20
|
-
access_token: f788fffffffffffff8ffffffffffffffffffffff8fffffffffffffffffffffff
|
21
|
-
vm_size: 512mb
|
22
|
-
vm_region: nyc3
|
23
|
-
vm_image: ubuntu-14-04-x64
|
24
|
-
profiles:
|
25
|
-
-
|
26
|
-
vm_name: london-vm
|
27
|
-
vm_region: lon1
|
28
|
-
-
|
29
|
-
vm_name: london-bigger-vm
|
30
|
-
vm_region: lon1
|
31
|
-
vm_size: 1gb
|
32
|
-
```
|
33
|
-
|
34
|
-
The `ssh_keys` is a list of the ID numbers of your ssh keys.
|
35
|
-
|
36
|
-
Then to create a VM in new york called default-vm:
|
37
|
-
```
|
38
|
-
sistero create
|
39
|
-
```
|
40
|
-
|
41
|
-
Or to create a VM called `london-vm` in london:
|
42
|
-
```
|
43
|
-
sistero create london
|
44
|
-
```
|