sistero 0.6.0 → 0.7.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: 96adaad8acc04fa6b38ed622150d5a993fb9279d
4
- data.tar.gz: 49a8eefc611b198779728ad4ade3fa91fa82ec81
3
+ metadata.gz: 3c05a40e7cbaf966250545adca8bedcaeab750a7
4
+ data.tar.gz: 28d77522246e1e102e90bb25919fedd756bd8fe9
5
5
  SHA512:
6
- metadata.gz: c64efc4ecbfd6b30302a19805331b876facb979c5b3e50d2e18aff4c20e7c4d3c62f5e619458b2934a7cc8212c9ff3ab3769f8cae50976dad12437a2cad5968f
7
- data.tar.gz: d7fd78c6b1605887013c5032e6c2bf0e10ac773019c70b3824ab551fdbb9572d52730e00d11617033ac377caeaeecee9fdcfe86f5af6fe37a47016b2ba9b3581
6
+ metadata.gz: 2eadc9dcdc499285f719f8798e6fbcb64192eb816cd778f01df49097ee11f5b4d2ce5bde18f8bfbda735268ff68ba1dfc5af5fab19186319338a18d83e08f2a6
7
+ data.tar.gz: 40c4a034b59468d9dc3201f0b69abe04a0239d884749c967311bb310fe5349e0c335d3c6a390e85f03d09e78f4a40bee85d0a18297ba519ed9728027cfce7409
data/bin/sistero CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'bundler/setup'
4
4
  require 'sistero'
5
+ require 'sistero/version'
5
6
  require 'moister'
6
7
 
7
8
  module Sistero::Command
@@ -10,7 +11,8 @@ module Sistero::Command
10
11
  command = nil
11
12
 
12
13
  Moister::SubcommandOptionParser.new do |op|
13
- op.banner = 'usage: sistero [global options] command [command options]'
14
+ op.banner = "sistero #{Sistero::VERSION}\nusage: sistero [global options] command [command options]"
15
+ op.version = Sistero::VERSION
14
16
 
15
17
  op.for_all do |op|
16
18
  op.on_tail '-h', '--help', 'show this help message' do
@@ -26,7 +28,7 @@ module Sistero::Command
26
28
  end
27
29
 
28
30
  op.subcommand 'create [*vms]', 'create vm'
29
- op.subcommand 'create-all', 'create all vms in profile'
31
+ op.subcommand 'create-all', 'create all vms in config'
30
32
  op.subcommand 'destroy [*vms]', 'destroy vm'
31
33
  op.subcommand 'list', 'list vms'
32
34
  op.subcommand 'show-config', 'show configuration'
@@ -2,14 +2,14 @@ require "yaml"
2
2
  APP_NAME = "sistero"
3
3
 
4
4
  module Sistero
5
- PROFILE_KEYS = [:vm_name, :vm_size, :vm_region, :vm_image, :access_token, :ssh_user,
6
- :ssh_keys, :ssh_options, :user_data, :private_networking]
5
+ VM_KEYS = [:name, :size, :region, :image, :access_token, :user_data, :private_networking,
6
+ :ssh_keys, :ssh_options, :ssh_user ]
7
7
 
8
- Profile = Struct.new(*PROFILE_KEYS) do
8
+ VM = Struct.new(*VM_KEYS) do
9
9
  def to_s
10
- "vm #{vm_name}\n" + PROFILE_KEYS.map do |key|
10
+ "vm #{name}\n" + VM_KEYS.map do |key|
11
11
  val = self[key]
12
- if val and key != :vm_name
12
+ if val and key != :name
13
13
  " #{key} #{val}\n"
14
14
  else
15
15
  ""
@@ -19,17 +19,17 @@ module Sistero
19
19
  end
20
20
 
21
21
  class Config
22
- attr_accessor :defaults, :profiles
22
+ attr_accessor :defaults, :vms
23
23
 
24
- def profile vm_name
25
- vm_name ||= @defaults['vm_name']
26
- raise "must set a default vm_name or specify one" unless vm_name
24
+ def vm name
25
+ name ||= @defaults['name']
26
+ raise "must set a default name or specify one" unless name
27
27
  # TODO: also handle wildcards
28
- profile = @profiles.find do |profile|
29
- profile.vm_name == vm_name
28
+ vm = @vms.find do |vm|
29
+ vm.name == name
30
30
  end
31
- raise "could not find profile for #{vm_name}" unless profile
32
- profile
31
+ raise "could not find vm for #{name}" unless vm
32
+ vm
33
33
  end
34
34
 
35
35
  def initialize(opts = {})
@@ -40,8 +40,8 @@ module Sistero
40
40
  @cfg_file_path = "#{ENV['HOME']}/.config/#{APP_NAME}" unless File.exists? @cfg_file_path
41
41
  end
42
42
 
43
- @defaults = Profile.new
44
- @profiles = []
43
+ @defaults = VM.new
44
+ @vms = []
45
45
 
46
46
  cfg = YAML.load_file @cfg_file_path
47
47
  postprocess_cfg cfg
@@ -50,30 +50,30 @@ module Sistero
50
50
  @defaults[key] = value
51
51
  end
52
52
 
53
- @profiles = cfg['profiles'].map do |profile_cfg|
54
- profile = Profile.new *@defaults
55
- profile.vm_name = nil
53
+ @vms = cfg['vms'].map do |vm_cfg|
54
+ vm = VM.new *@defaults
55
+ vm.name = nil
56
56
 
57
- profile_cfg.each do |key, value|
58
- profile[key] = value
57
+ vm_cfg.each do |key, value|
58
+ vm[key] = value
59
59
  end
60
- unless profile.user_data.nil?
61
- user_data = profile.user_data.dup
62
- PROFILE_KEYS.each do |key|
63
- value = profile[key]
60
+ unless vm.user_data.nil?
61
+ user_data = vm.user_data.dup
62
+ VM_KEYS.each do |key|
63
+ value = vm[key]
64
64
  if value.is_a? String
65
65
  user_data.gsub! "\#{#{key}}", value
66
66
  end
67
67
  end
68
- profile.user_data = user_data
68
+ vm.user_data = user_data
69
69
  end
70
- raise "every profile must have a vm_name field" unless profile.vm_name
71
- profile
70
+ raise "every vm must have a name field" unless vm.name
71
+ vm
72
72
  end
73
73
  end
74
74
 
75
75
  def to_s
76
- @profiles.map(&:to_s).join "\n"
76
+ @vms.map(&:to_s).join "\n"
77
77
  end
78
78
 
79
79
  private
@@ -1,3 +1,3 @@
1
1
  module Sistero
2
- VERSION = '0.6.0'
2
+ VERSION = '0.7.0'
3
3
  end
data/lib/sistero.rb CHANGED
@@ -9,8 +9,8 @@ module Sistero
9
9
  @client = DropletKit::Client.new(access_token: @config.defaults.access_token)
10
10
  end
11
11
 
12
- def find_vm(vm_name)
13
- @client.droplets.all.find { |vm| vm.name == vm_name }
12
+ def find_droplet(name)
13
+ @client.droplets.all.find { |vm| vm.name == name }
14
14
  end
15
15
 
16
16
  def list_vms()
@@ -19,33 +19,33 @@ module Sistero
19
19
  end
20
20
  end
21
21
 
22
- def get_profile vm_name
23
- profile = @config.profile vm_name
24
- vm_name = profile.vm_name if vm_name.nil?
25
- [ profile, vm_name ]
22
+ def get_vm name
23
+ vm = @config.vm name
24
+ name = vm.name if name.nil?
25
+ [ vm, name ]
26
26
  end
27
27
 
28
- def create_vm(vm_name)
29
- profile, vm_name = get_profile vm_name
30
- puts "creating vm: #{vm_name}"
31
-
32
- vm = DropletKit::Droplet.new(
33
- name: vm_name,
34
- region: profile.vm_region,
35
- size: profile.vm_size,
36
- image: profile.vm_image,
37
- ssh_keys: profile.ssh_keys,
38
- user_data: profile.user_data,
39
- private_networking: profile.private_networking
28
+ def create_droplet_from_vm(name)
29
+ vm, name = get_vm name
30
+ puts "creating vm: #{name}"
31
+
32
+ droplet = DropletKit::Droplet.new(
33
+ name: name,
34
+ region: vm.region,
35
+ size: vm.size,
36
+ image: vm.image,
37
+ ssh_keys: vm.ssh_keys,
38
+ user_data: vm.user_data,
39
+ private_networking: vm.private_networking
40
40
  )
41
- vm = @client.droplets.create(vm)
42
- puts "created: #{profile.to_s}"
43
- vm
41
+ droplet = @client.droplets.create(droplet)
42
+ puts "created: #{vm.to_s}"
43
+ droplet
44
44
  end
45
45
 
46
46
  def create_all
47
- @config.profiles.each do |profile|
48
- create_vm profile.vm_name
47
+ @config.vms.each do |vm|
48
+ create_droplet_from_vm vm.name
49
49
  end
50
50
  end
51
51
 
@@ -65,17 +65,17 @@ module Sistero
65
65
  return false
66
66
  end
67
67
 
68
- def ssh_to_vm(vm_name, ssh_options: nil)
69
- profile, vm_name = get_profile vm_name
70
- ssh_options ||= profile.ssh_options
68
+ def ssh_to_vm(name, ssh_options: nil)
69
+ vm, name = get_vm name
70
+ ssh_options ||= vm.ssh_options
71
71
 
72
- vm = find_vm(vm_name) || create_vm(vm_name)
73
- public_network = vm.networks.v4.find { |network| network.type == 'public' }
72
+ droplet = find_droplet(name) || create_droplet_from_vm(name)
73
+ public_network = droplet.networks.v4.find { |network| network.type == 'public' }
74
74
  until public_network
75
75
  puts "no public interfaces, trying again in a second"
76
76
  sleep 1
77
- vm = find_vm(vm_name)
78
- public_network = vm.networks.v4.find { |network| network.type == 'public' }
77
+ droplet = find_droplet(name)
78
+ public_network = droplet.networks.v4.find { |network| network.type == 'public' }
79
79
  end
80
80
  ip = public_network.ip_address
81
81
 
@@ -87,20 +87,20 @@ module Sistero
87
87
  end
88
88
  end
89
89
 
90
- cmd = "ssh -o 'StrictHostKeyChecking no' #{ssh_options} #{profile.ssh_user || 'root'}@#{ip}"
90
+ cmd = "ssh -o 'StrictHostKeyChecking no' #{ssh_options} #{vm.ssh_user || 'root'}@#{ip}"
91
91
  puts cmd
92
92
  exec cmd
93
93
  end
94
94
 
95
- def destroy_vm(vm_name)
96
- profile, vm_name = get_profile vm_name
95
+ def destroy_vm(name)
96
+ vm, name = get_vm name
97
97
 
98
- vm = find_vm(vm_name)
99
- if vm
100
- puts "destroying #{vm.id}"
101
- @client.droplets.delete(id: vm.id)
98
+ droplet = find_droplet(name)
99
+ if droplet
100
+ puts "destroying #{droplet.id}"
101
+ @client.droplets.delete(id: droplet.id)
102
102
  else
103
- puts "vm #{vm_name} not found"
103
+ puts "vm #{name} not found"
104
104
  end
105
105
  end
106
106
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sistero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Pike