sistero 0.7.1 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e493aa279919d567e6a6eb2d0980dcd3ec412374
4
- data.tar.gz: f222d218205101e767a903382b34928636e3a5cd
2
+ SHA256:
3
+ metadata.gz: f235e9d54734e98384ab4f4cc22e09c6b90db8b9cd788da9a240448245c5fc98
4
+ data.tar.gz: a435ca3f77f729d317e44e029d6f2c7df0857b5374b38ee948410a7a939229e8
5
5
  SHA512:
6
- metadata.gz: 04e07114fafb07c5ca60ec829c9c7664cab53c6d7783bd4fecd38a8da8e79334cbf4c32569f34daad8b7f08b363cda31f1ae4b3dcb450054403381966d37dc0f
7
- data.tar.gz: 16799fcaa0100ae937347ca44eb52d4d6cc5a76ae9a952acb04eba4711e24320a8fa891fbbe2c8ab40ebb91d6515e2b0d87e1e121ea4ddeb424397e3551da630
6
+ metadata.gz: 21a7e25013fac34584e0bfabd3f0ffd3e24e11f26d61744b7ef3c30f3971f3b8a799a99a8cf4f727a03867e3e13045465e893386ddfb5013d3eff57c9ab379d1
7
+ data.tar.gz: c37a09b748bc6b9c38e78e817b60e8f5bc0e2ca87d9fcaa1af51c82c398e12c69200167b5d63a59f1fb6b294e7e46be8f49be6bc25eebe20993e4b18eac4cd7a
@@ -24,10 +24,12 @@ module Sistero::Command
24
24
  op.on '-c', '--config file', 'override path to config file', 'cfg_file_path'
25
25
  op.on '-d', '--directory dir', 'set working dir', 'directory'
26
26
 
27
- op.subcommand 'ssh [vm]', 'ssh to vm' do |subop|
27
+ op.subcommand 'ssh [vm] [*run]', 'ssh to vm' do |subop|
28
28
  subop.on '-o val', 'add ssh options', 'ssh_options'
29
29
  end
30
30
 
31
+ op.subcommand 'rsync vm *cmd', 'rsync files to/from vm'
32
+
31
33
  op.subcommand 'create [*vms]', 'create vm'
32
34
  op.subcommand 'create-all', 'create all vms in config'
33
35
  op.subcommand 'destroy [*vms]', 'destroy vm'
@@ -56,12 +58,13 @@ module Sistero::Command
56
58
 
57
59
  case command
58
60
  when 'ssh'
59
- # TODO: pass ssh_args
60
- sistero.ssh_to_vm(command_cfg.vm, ssh_options: command_cfg.ssh_options)
61
+ sistero.ssh_to_vm(command_cfg.vm, ssh_options: command_cfg.ssh_options, run: command_cfg.run)
62
+ when 'rsync'
63
+ sistero.rsync(command_cfg.vm, cmd: command_cfg.cmd)
61
64
  when 'create'
62
65
  vms = command_cfg.vms
63
66
  vms.push nil if vms.empty?
64
- vms.each &sistero.method(:create_vm)
67
+ vms.each &sistero.method(:create_droplet_from_vm)
65
68
  when 'create-all'
66
69
  sistero.create_all()
67
70
  when 'destroy'
@@ -10,12 +10,12 @@ module Sistero
10
10
  end
11
11
 
12
12
  def find_droplet(name)
13
- @client.droplets.all.find { |vm| vm.name == name }
13
+ @client.droplets.all.find { |droplet| droplet.name == name }
14
14
  end
15
15
 
16
16
  def list_vms()
17
- @client.droplets.all.each do |vm|
18
- puts "#{vm.name} - #{vm.networks[0][0].ip_address}"
17
+ @client.droplets.all.each do |droplet|
18
+ puts "#{droplet.name} - #{get_public_ip droplet}"
19
19
  end
20
20
  end
21
21
 
@@ -65,33 +65,33 @@ module Sistero
65
65
  return false
66
66
  end
67
67
 
68
- def ssh_to_vm(name, ssh_options: nil)
68
+ def ssh_to_vm(name, ssh_options: nil, run: nil)
69
69
  vm, name = get_vm name
70
70
  ssh_options ||= vm.ssh_options
71
71
 
72
72
  droplet = find_droplet(name) || create_droplet_from_vm(name)
73
- public_network = droplet.networks.v4.find { |network| network.type == 'public' }
74
- until public_network
75
- puts "no public interfaces, trying again in a second"
76
- sleep 1
77
- droplet = find_droplet(name)
78
- public_network = droplet.networks.v4.find { |network| network.type == 'public' }
79
- end
80
- ip = public_network.ip_address
73
+ public_ip = get_public_ip droplet
74
+ wait_for_ssh_port public_ip
81
75
 
82
- unless is_port_open? ip, 22
83
- puts "waiting for ssh port to open"
84
- sleep 1
85
- until is_port_open? ip, 22 do
86
- sleep 1
87
- end
76
+ cmd = "ssh -o 'StrictHostKeyChecking no' #{ssh_options} #{vm.ssh_user || 'root'}@#{public_ip}"
77
+ unless run.empty?
78
+ cmd += ' ' + run.join(' ')
88
79
  end
89
80
 
90
- cmd = "ssh -o 'StrictHostKeyChecking no' #{ssh_options} #{vm.ssh_user || 'root'}@#{ip}"
91
- puts cmd
81
+ # puts cmd
92
82
  exec cmd
93
83
  end
94
84
 
85
+ def rsync(name, cmd: nil)
86
+ vm, name = get_vm name
87
+ droplet = find_droplet(name) || create_droplet_from_vm(name)
88
+ public_ip = get_public_ip droplet
89
+ wait_for_ssh_port public_ip
90
+
91
+ cmd_str = 'rsync ' + cmd.join(' ').gsub('vm:', "#{vm.ssh_user || 'root'}@#{public_ip}:")
92
+ exec cmd_str
93
+ end
94
+
95
95
  def destroy_vm(name)
96
96
  vm, name = get_vm name
97
97
 
@@ -143,5 +143,32 @@ module Sistero
143
143
  puts " regions #{image.regions.join ', '}"
144
144
  end
145
145
  end
146
+
147
+ private
148
+ def find_public_network droplet
149
+ droplet&.networks.v4.find { |network| network.type == 'public' }
150
+ end
151
+
152
+ private
153
+ def get_public_ip droplet
154
+ public_network = find_public_network droplet
155
+ until public_network
156
+ puts "no public interfaces, trying again in a second"
157
+ sleep 1
158
+ droplet = find_droplet(droplet.name)
159
+ public_network = find_public_network droplet
160
+ end
161
+ public_network.ip_address
162
+ end
163
+
164
+ def wait_for_ssh_port public_ip
165
+ unless is_port_open? public_ip, 22
166
+ puts "waiting for ssh port to open"
167
+ sleep 1
168
+ until is_port_open? public_ip, 22 do
169
+ sleep 1
170
+ end
171
+ end
172
+ end
146
173
  end
147
174
  end
@@ -46,7 +46,7 @@ module Sistero
46
46
  @cfg_file_path = cfg_file_path
47
47
  break
48
48
  end
49
- directory = File.dirname directory
49
+ directory = File.expand_path '..', directory
50
50
  break if directory == '/'
51
51
  end
52
52
 
@@ -1,3 +1,3 @@
1
1
  module Sistero
2
- VERSION = '0.7.1'
2
+ VERSION = '0.8.1'
3
3
  end
data/readme.md CHANGED
@@ -8,33 +8,35 @@ sistero is a profile based tool to manage a digital ocean cluster.
8
8
 
9
9
  ## Configuration
10
10
 
11
- The configuration file lives at `.config/sistero`, an example looks like this:
11
+ First sistero looks for a file called `sistero.yaml` in the current directory or a parent of the current directory. If it is not found the default configuration is loaded from `.config/sistero`. Here is an example:
12
12
 
13
13
  ```
14
14
  defaults:
15
- vm_name: default-vm
15
+ name: default-vm
16
16
  ssh_keys:
17
17
  - 1234567
18
18
  ssh_options: -D1080 -A
19
19
  access_token: f788fffffffffffff8ffffffffffffffffffffff8fffffffffffffffffffffff
20
- vm_size: 512mb
21
- vm_region: nyc3
22
- vm_image: ubuntu-14-04-x64
23
- profiles:
20
+ size: 512mb
21
+ region: nyc3
22
+ image: ubuntu-14-04-x64
23
+ vms:
24
24
  -
25
- vm_name: london-vm
26
- vm_region: lon1
25
+ name: default-vm
27
26
  -
28
- vm_name: london-bigger-vm
29
- vm_region: lon1
30
- vm_size: 1gb
27
+ name: london-vm
28
+ region: lon1
29
+ -
30
+ name: london-bigger-vm
31
+ region: lon1
32
+ size: 1gb
31
33
  ```
32
34
 
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.
35
+ Any values not specified in a profile are taken from `defaults`. If the `defaults` entry specifies a `name` then it becomes the default VM for the `create`, `ssh` and `destroy` commands but is not inherited by vm configuration items.
34
36
 
35
37
  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
38
 
37
- The valid options for `region`, `vm_size` and `vm_image` can be found by running `sistero regions`, `sistero sizes` and `sistero images` respectively.
39
+ The valid options for `region`, `size` and `image` can be found by running `sistero regions`, `sistero sizes` and `sistero images` respectively.
38
40
 
39
41
  ## Running
40
42
 
@@ -47,3 +49,58 @@ Or to create a VM called `london-vm` in london:
47
49
  ```
48
50
  sistero create london-vm
49
51
  ```
52
+
53
+ The command `sistero create-all` can be used to create all VMs listed in the configuration file.
54
+
55
+ ## More advanced configurations
56
+
57
+ This config that shows how to create a CoreOS cluster:
58
+
59
+ ```
60
+ defaults:
61
+ ssh_user: core
62
+ ssh_keys:
63
+ - 1234567
64
+ - 1234568
65
+ ssh_options: -D1080 -A
66
+ access_token:
67
+ file: ./secrets/digital-ocean.access-token
68
+ region: lon1
69
+ image: coreos-stable
70
+ name: vm1
71
+ private_networking: true
72
+ user_data: |
73
+ #cloud-config
74
+ coreos:
75
+ etcd2:
76
+ # y$@" :r !curl -s -w "\n" "https://discovery.etcd.io/new?size=2"
77
+ discovery: https://discovery.etcd.io/af66d811fc9b5b9b0989009f849cc37a
78
+ # use $public_ipv4 for multi-cloud/region:
79
+ advertise-client-urls: http://$private_ipv4:2379
80
+ initial-advertise-peer-urls: http://$private_ipv4:2380
81
+ listen-client-urls: http://0.0.0.0:2379
82
+ listen-peer-urls: http://$private_ipv4:2380
83
+ fleet:
84
+ public-ip: $private_ipv4 # used for fleetctl ssh command
85
+ metadata: "size=#{size},name=#{name}"
86
+ units:
87
+ - name: etcd2.service
88
+ command: start
89
+ - name: fleet.service
90
+ command: start
91
+ vms:
92
+ -
93
+ name: vm1
94
+ size: 1gb
95
+ -
96
+ name: vm2
97
+ size: 512mb
98
+ -
99
+ name: vm3
100
+ size: 512mb
101
+ ```
102
+
103
+ This demonstrates a few more things:
104
+
105
+ 1. The config can be split over multiple files using `file:`, in this config file the digital ocean access token is specified in a different file.
106
+ 2. In `user_data` vm configuration variables can be substituted, see `#{size}` and `#{name}` in the metadata.
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.name
27
27
  spec.require_paths = ["lib"]
28
28
 
29
- spec.add_development_dependency "bundler", "~> 1.10"
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
30
  spec.add_development_dependency "rake", "~> 10.0"
31
31
  spec.add_development_dependency "rspec"
32
32
 
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.7.1
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Pike
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-18 00:00:00.000000000 Z
11
+ date: 2020-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.10'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.10'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -105,7 +105,7 @@ homepage: http://github.com/ohjames/sistero
105
105
  licenses: []
106
106
  metadata:
107
107
  allowed_push_host: https://rubygems.org
108
- post_install_message:
108
+ post_install_message:
109
109
  rdoc_options: []
110
110
  require_paths:
111
111
  - lib
@@ -120,9 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.5.1
125
- signing_key:
123
+ rubygems_version: 3.1.4
124
+ signing_key:
126
125
  specification_version: 4
127
126
  summary: Profile based digital ocean cluster management command line tool.
128
127
  test_files: []