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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7169883de6150a292655a7a630d7d641cf864721
4
- data.tar.gz: 6e984359031fb537c92d67688c752a25675b8dd9
3
+ metadata.gz: 0bc5e43a952d3731e1d79c44cea1d2f0d2a8b4d5
4
+ data.tar.gz: 2381e2b68a59334a1c96eefe1d34e4e4db83493f
5
5
  SHA512:
6
- metadata.gz: ba7d79891159a85f01f3925c5158aecfdb50f4d0db9dd71facc7bd80c887e09abfe0bc2e953d3735d1e7f010dc5ca23882d9aa49bf01871fdb649e645d4ddbd6
7
- data.tar.gz: 973fc678d514e0f2b489a4811fb188b20684d81748c50b73ed53e4e3fe7cc30830418a476466676410137e41be18474e49fd126cc6f3f889acb18bddb15a7dd0
6
+ metadata.gz: 2081cd28ad7a6e7bb0ad30017fab8572e9994f62a5df90e94597612893ad42acc7e0eb8c8cf8a17d4c0ede62482d8fa3521a9b18b4711bc8edb4a9e9f62ccae3
7
+ data.tar.gz: b73a737357ad1fa3162dd7f36bf9d3516726b4004dd1e6cdee5aaff046945a87f6351fd5743608be322f2d7f2eb1edee5cbcc21b812a2b513fe53d7b7ab28c2b
data/README.md CHANGED
@@ -1,36 +1,39 @@
1
1
  # Sistero
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sistero`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- Add this line to your application's Gemfile:
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
- TODO: Write usage instructions here
26
-
27
- ## Development
11
+ Create a config file at `.config/sistero` with something like:
28
12
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
- ## Contributing
29
+ The `ssh_keys` is a list of the ID numbers of your ssh keys.
34
30
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sistero.
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
@@ -1,3 +1,3 @@
1
1
  module Sistero
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
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
- 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
-
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
- file_opts = {}
29
- file_opts = YAML.load_file cfg_file_path if File.exists? cfg_file_path
30
-
31
- dirty = false
32
- DEFAULTS.each do |key, default|
33
- next if file_opts[key]
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
- file_opts.merge! opts
48
- file_opts.each { |k, v| send("#{k}=", v) }
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: @config.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: @config.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, region: @config.vm_region, size: "#{@config.vm_size}mb", image: @config.vm_image, ssh_keys: @config.ssh_keys
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: #{vm_name}"
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: @config.vm_name, ssh_options: @config.ssh_options)
95
- ssh_options = @config.ssh_options if ssh_options == nil
96
- vm = find_vm(vm_name: vm_name) || create_vm(vm_name: vm_name)
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: @config.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{DigitalOcean developer tools.}
13
- spec.description = %q{Commands for dealing with temporary digital ocean VMs.}
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.1.1
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-30 00:00:00.000000000 Z
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: Commands for dealing with temporary digital ocean VMs.
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: DigitalOcean developer tools.
128
+ summary: Profile based digital ocean cluster management command line tool.
129
129
  test_files: []