sistero 0.1.1 → 0.2.0
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/README.md +27 -24
- data/bin/sistero +9 -3
- data/lib/sistero/version.rb +1 -1
- data/lib/sistero.rb +52 -44
- data/sistero.gemspec +2 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bc5e43a952d3731e1d79c44cea1d2f0d2a8b4d5
|
4
|
+
data.tar.gz: 2381e2b68a59334a1c96eefe1d34e4e4db83493f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2081cd28ad7a6e7bb0ad30017fab8572e9994f62a5df90e94597612893ad42acc7e0eb8c8cf8a17d4c0ede62482d8fa3521a9b18b4711bc8edb4a9e9f62ccae3
|
7
|
+
data.tar.gz: b73a737357ad1fa3162dd7f36bf9d3516726b4004dd1e6cdee5aaff046945a87f6351fd5743608be322f2d7f2eb1edee5cbcc21b812a2b513fe53d7b7ab28c2b
|
data/README.md
CHANGED
@@ -1,36 +1,39 @@
|
|
1
1
|
# Sistero
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
sistero is a profile based tool to manage a digital ocean cluster.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'sistero'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install sistero
|
7
|
+
```gem install sistero```
|
22
8
|
|
23
9
|
## Usage
|
24
10
|
|
25
|
-
|
26
|
-
|
27
|
-
## Development
|
11
|
+
Create a config file at `.config/sistero` with something like:
|
28
12
|
|
29
|
-
|
30
|
-
|
31
|
-
|
13
|
+
```
|
14
|
+
---
|
15
|
+
defaults:
|
16
|
+
vm_name: my_default_vm_name
|
17
|
+
ssh_keys:
|
18
|
+
- 1234567
|
19
|
+
ssh_options: -D1080 -A
|
20
|
+
access_token: f788fffffffffffff8ffffffffffffffffffffff8fffffffffffffffffffffff
|
21
|
+
vm_size: 512
|
22
|
+
vm_region: nyc3
|
23
|
+
vm_image: ubuntu-14-04-x64
|
24
|
+
london:
|
25
|
+
vm_name: my_london_vm_name
|
26
|
+
vm_region: lon1
|
27
|
+
```
|
32
28
|
|
33
|
-
|
29
|
+
The `ssh_keys` is a list of the ID numbers of your ssh keys.
|
34
30
|
|
35
|
-
|
31
|
+
Then to create a VM in new york:
|
32
|
+
```
|
33
|
+
sistero create
|
34
|
+
```
|
36
35
|
|
36
|
+
Or to create a VM configured the same only in London:
|
37
|
+
```
|
38
|
+
sistero -p london create
|
39
|
+
```
|
data/bin/sistero
CHANGED
@@ -6,6 +6,8 @@ require 'optparse/subcommand'
|
|
6
6
|
|
7
7
|
module Sistero::Command
|
8
8
|
@config = OpenStruct.new
|
9
|
+
@config.profile_name = 'default'
|
10
|
+
|
9
11
|
@subcommands = []
|
10
12
|
@op = nil
|
11
13
|
|
@@ -44,6 +46,10 @@ module Sistero::Command
|
|
44
46
|
exit
|
45
47
|
end
|
46
48
|
|
49
|
+
op.on '-p val', '--profile', 'set profile' do |profile_name|
|
50
|
+
@config.profile_name = profile_name
|
51
|
+
end
|
52
|
+
|
47
53
|
subcommand 'ssh', 'ssh to vm' do |subop|
|
48
54
|
subop.on '-o val', 'add ssh options' do |ssh_options|
|
49
55
|
@config.ssh_options = ssh_options
|
@@ -67,11 +73,11 @@ module Sistero::Command
|
|
67
73
|
sistero = Sistero::Instance.new
|
68
74
|
case @config.action
|
69
75
|
when 'ssh'
|
70
|
-
sistero.ssh_to_vm(ssh_options: @config.ssh_options)
|
76
|
+
sistero.ssh_to_vm(@config.profile_name, ssh_options: @config.ssh_options)
|
71
77
|
when 'create'
|
72
|
-
sistero.create_vm()
|
78
|
+
sistero.create_vm(@config.profile_name)
|
73
79
|
when 'destroy'
|
74
|
-
sistero.destroy_vm()
|
80
|
+
sistero.destroy_vm(@config.profile_name)
|
75
81
|
when 'list'
|
76
82
|
sistero.list_vms()
|
77
83
|
end
|
data/lib/sistero/version.rb
CHANGED
data/lib/sistero.rb
CHANGED
@@ -5,57 +5,52 @@ require "droplet_kit"
|
|
5
5
|
APP_NAME = "sistero"
|
6
6
|
|
7
7
|
module Sistero
|
8
|
+
Profile = Struct.new(:access_token, :ssh_keys, :ssh_options, :vm_name, :vm_size, :vm_region, :vm_image)
|
9
|
+
# DEFAULTS = {
|
10
|
+
# :access_token => nil,
|
11
|
+
# :ssh_keys => [],
|
12
|
+
# :ssh_options => '',
|
13
|
+
# :vm_name => nil,
|
14
|
+
# :vm_size => 512,
|
15
|
+
# :vm_region => 'nyc3',
|
16
|
+
# :vm_image => 'ubuntu-14-04-x64',
|
17
|
+
# }
|
18
|
+
|
8
19
|
class Config
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
:vm_name => nil,
|
14
|
-
:vm_size => 512,
|
15
|
-
:vm_region => 'nyc3',
|
16
|
-
:vm_image => 'ubuntu-14-04-x64',
|
17
|
-
}
|
18
|
-
|
19
|
-
attr_accessor *DEFAULTS.keys
|
20
|
-
|
21
|
-
def write_yaml(path, opts)
|
22
|
-
File.open(path, 'w') { |f| f.write opts.to_yaml }
|
20
|
+
attr_accessor :defaults
|
21
|
+
|
22
|
+
def profile name
|
23
|
+
@profiles[name] || @defaults
|
23
24
|
end
|
24
25
|
|
25
26
|
def initialize(opts = {})
|
26
27
|
# read defaults from config file
|
27
28
|
cfg_file_path = "#{ENV['HOME']}/.config/#{APP_NAME}"
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
dirty = true
|
35
|
-
if default
|
36
|
-
print "#{key} [#{default}] = "
|
37
|
-
val = gets.strip
|
38
|
-
val = default if val == ''
|
39
|
-
else
|
40
|
-
print "#{key} = "
|
41
|
-
val = gets.strip
|
42
|
-
end
|
43
|
-
file_opts[key] = val
|
29
|
+
@defaults = Profile.new
|
30
|
+
@profiles = {}
|
31
|
+
|
32
|
+
cfg = YAML.load_file cfg_file_path
|
33
|
+
cfg['defaults'].each do |key, value|
|
34
|
+
@defaults[key] = value
|
44
35
|
end
|
45
|
-
write_yaml(cfg_file_path, file_opts) if dirty
|
46
36
|
|
47
|
-
|
48
|
-
|
37
|
+
cfg.each do |name, profile_cfg|
|
38
|
+
next if name == 'defaults'
|
39
|
+
profile = @profiles[name] = Profile.new *@defaults
|
40
|
+
profile_cfg.each do |key, value|
|
41
|
+
profile[key] = value
|
42
|
+
end
|
43
|
+
end
|
49
44
|
end
|
50
45
|
end
|
51
46
|
|
52
47
|
class Instance
|
53
48
|
def initialize(opts = {})
|
54
49
|
@config = Config.new(opts)
|
55
|
-
@client = DropletKit::Client.new(access_token: @config.access_token)
|
50
|
+
@client = DropletKit::Client.new(access_token: @config.defaults.access_token)
|
56
51
|
end
|
57
52
|
|
58
|
-
def find_vm(vm_name:
|
53
|
+
def find_vm(vm_name:)
|
59
54
|
@client.droplets.all.find { |vm| vm.name == vm_name }
|
60
55
|
end
|
61
56
|
|
@@ -65,13 +60,21 @@ module Sistero
|
|
65
60
|
end
|
66
61
|
end
|
67
62
|
|
68
|
-
def create_vm(vm_name:
|
63
|
+
def create_vm(profile_name, vm_name: nil)
|
64
|
+
profile = @config.profile profile_name
|
65
|
+
vm_name ||= profile.vm_name
|
66
|
+
|
69
67
|
puts "creating vm: #{vm_name}"
|
68
|
+
|
70
69
|
vm = DropletKit::Droplet.new(
|
71
|
-
name: vm_name,
|
70
|
+
name: vm_name,
|
71
|
+
region: profile.vm_region,
|
72
|
+
size: "#{profile.vm_size}mb",
|
73
|
+
image: profile.vm_image,
|
74
|
+
ssh_keys: profile.ssh_keys
|
72
75
|
)
|
73
76
|
vm = @client.droplets.create(vm)
|
74
|
-
puts "created vm: #{
|
77
|
+
puts "created vm: #{profile.to_s}"
|
75
78
|
vm
|
76
79
|
end
|
77
80
|
|
@@ -91,9 +94,12 @@ module Sistero
|
|
91
94
|
return false
|
92
95
|
end
|
93
96
|
|
94
|
-
def ssh_to_vm(vm_name:
|
95
|
-
|
96
|
-
|
97
|
+
def ssh_to_vm(profile_name, vm_name: nil, ssh_options: nil)
|
98
|
+
profile = @config.profile profile_name
|
99
|
+
vm_name ||= profile.vm_name
|
100
|
+
ssh_options ||= profile.ssh_options
|
101
|
+
|
102
|
+
vm = find_vm(vm_name: vm_name) || create_vm(profile_name, vm_name: vm_name)
|
97
103
|
public_network = vm.networks.v4.find { |network| network.type == 'public' }
|
98
104
|
until public_network
|
99
105
|
puts "no public interfaces, trying again in a second"
|
@@ -111,19 +117,21 @@ module Sistero
|
|
111
117
|
end
|
112
118
|
end
|
113
119
|
|
114
|
-
# TODO: wait for ssh port to be open
|
115
120
|
cmd = "ssh -o 'StrictHostKeyChecking no' #{ssh_options} root@#{ip}"
|
116
121
|
puts cmd
|
117
122
|
exec cmd
|
118
123
|
end
|
119
124
|
|
120
|
-
def destroy_vm(vm_name:
|
125
|
+
def destroy_vm(profile_name, vm_name: nil)
|
126
|
+
profile = @config.profile profile_name
|
127
|
+
vm_name ||= profile.vm_name
|
128
|
+
|
121
129
|
vm = find_vm(vm_name: vm_name)
|
122
130
|
if vm
|
123
131
|
puts "destroying #{vm.id}"
|
124
132
|
@client.droplets.delete(id: vm.id)
|
125
133
|
else
|
126
|
-
puts "vm not found"
|
134
|
+
puts "vm #{vm_name} not found"
|
127
135
|
end
|
128
136
|
end
|
129
137
|
end
|
data/sistero.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["James Pike"]
|
10
10
|
spec.email = ["github@chilon.net"]
|
11
11
|
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.description = %q{
|
12
|
+
spec.summary = %q{Profile based digital ocean cluster management command line tool.}
|
13
|
+
spec.description = %q{Profile based digital ocean cluster management command line tool.}
|
14
14
|
spec.homepage = "http://github.com/ohjames/sistero"
|
15
15
|
|
16
16
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
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
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Pike
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description: Profile based digital ocean cluster management command line tool.
|
84
84
|
email:
|
85
85
|
- github@chilon.net
|
86
86
|
executables:
|
@@ -125,5 +125,5 @@ rubyforge_project:
|
|
125
125
|
rubygems_version: 2.4.5.1
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
|
-
summary:
|
128
|
+
summary: Profile based digital ocean cluster management command line tool.
|
129
129
|
test_files: []
|