pairus 0.0.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.
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pairus.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Craig Israel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Pairus
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pairus'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pairus
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/pairus/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,109 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ # Issues:
4
+ # investigate pkill to kill reverse tunnel
5
+ # use pbcopy to automatically put ssh command in buffer when pair is started
6
+ # get subdomain to work instead of using instance ips
7
+ command = ARGV[0] || "status"
8
+
9
+ require 'aws'
10
+ require 'yaml'
11
+
12
+ config = YAML.load_file(File.dirname(File.expand_path(__FILE__)) + "/pair.yml")
13
+ aws_config = config["aws"]
14
+
15
+ AWS.config(:access_key_id => aws_config["access_key_id"], :secret_access_key => aws_config["secret_access_key"])
16
+ ec2 = AWS::EC2.new
17
+ instance = ec2.instances[aws_config["instance_id"]]
18
+
19
+ $stdout.sync = true
20
+
21
+ class InstanceController
22
+ attr_reader :instance
23
+ def initialize(instance, config)
24
+ @instance = instance
25
+ @config = config
26
+ end
27
+
28
+ def config
29
+ @config
30
+ end
31
+
32
+ def start
33
+ puts "waiting for instance to start"
34
+ instance.start
35
+ while instance.status == :pending
36
+ print "."
37
+ sleep 5
38
+ end
39
+ puts
40
+ puts "Started instance #{instance.dns_name}"
41
+ end
42
+
43
+ def stop
44
+ puts "stopping instance"
45
+ instance.stop
46
+ while instance.status != :stopped
47
+ print "."
48
+ sleep 5
49
+ end
50
+ puts
51
+ puts "instance has stopped"
52
+ end
53
+
54
+ def pair
55
+ start unless instance.status == :running
56
+ command = "ssh "
57
+ command = command + "-i #{config["identity_file"]} " if config["identity_file"]
58
+ command = command + "ec2-user@#{instance.dns_name} -R #{config["tunnel_port"]}:localhost:22 -N -f -v"
59
+ puts "Opening ssh tunnel"
60
+ puts command
61
+ system(command)
62
+ puts "\n\nPair can connect with 'ssh tmux@#{instance.dns_name}'\n\n"
63
+ end
64
+
65
+ def ssh
66
+ system("ssh -i ~/.ssh/onlife.pem ec2-user@#{instance.dns_name} -v")
67
+
68
+ end
69
+
70
+ def close_pair
71
+ pid = %x{ps aux | grep '19999:localhost:22' | grep -v grep | tr -s ' ' | cut -d ' ' -f 2}.chomp
72
+ system("kill #{pid}") unless pid.empty?
73
+ end
74
+ end
75
+
76
+ controller = InstanceController.new(instance, aws_config)
77
+ case command
78
+ when "status"
79
+ puts "Current status: #{instance.status}"
80
+ puts "Instance DNS: #{instance.dns_name}"
81
+ when "start"
82
+ if instance.status == :running
83
+ puts "Instance is already running. Current status is #{instance.status}"
84
+ else
85
+ controller.start
86
+ end
87
+ when "stop"
88
+ if instance.status != :running
89
+ puts "Instance is not running. Current status is #{instance.status}"
90
+ else
91
+ controller.stop
92
+ end
93
+ when "pair"
94
+ controller.pair
95
+ when "close_pair"
96
+ controller.close_pair
97
+ when "ssh"
98
+ controller.ssh
99
+ when 'attach'
100
+ `tmux -S /tmp/pair attach`
101
+ else
102
+ pair = config["pairs"][command]
103
+ if pair
104
+ system("switch_pair #{pair["path"]}")
105
+ else
106
+ puts "Invalid command '#{command}'"
107
+ end
108
+ end
109
+
@@ -0,0 +1,5 @@
1
+ aws:
2
+ access_key_id: <access_key_id>
3
+ secret_access_key: <secret_access_key>
4
+ instance_id: <instance_id>
5
+ tunnel_port: 19999
@@ -0,0 +1,5 @@
1
+ require "pairus/version"
2
+
3
+ module Pairus
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,3 @@
1
+ module Pairus
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pairus/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pairus"
8
+ spec.version = Pairus::VERSION
9
+ spec.authors = ["Craig Israel"]
10
+ spec.email = ["craig_israel@onlifehealth.com"]
11
+ spec.summary = "Script for managing remote pairing"
12
+ spec.description = "Script for managing remote pairing"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pairus
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Craig Israel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-09-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ description: Script for managing remote pairing
47
+ email:
48
+ - craig_israel@onlifehealth.com
49
+ executables:
50
+ - pair
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/pair
60
+ - lib/pair.sample.yml
61
+ - lib/pairus.rb
62
+ - lib/pairus/version.rb
63
+ - pairus.gemspec
64
+ homepage: ''
65
+ licenses:
66
+ - MIT
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.23
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Script for managing remote pairing
89
+ test_files: []