pairhost 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -21,6 +21,9 @@ Manage EC2 instances for remote pairing the style that Relevance prefers.
21
21
  # up will resume a down pairhost, but if none will create one
22
22
  pairhost up
23
23
 
24
+ # ssh will resume a down pairhost, then SSH to it
25
+ pairhost ssh
26
+
24
27
  # all future commands will affect the given instance
25
28
  pairhost attach instance-id
26
29
 
data/config.example.yml CHANGED
@@ -1,9 +1,18 @@
1
1
  provider: 'AWS'
2
+ # optionally specify Region for your AMI
3
+ # FOG gem defaults AWS to 'us-east-1'
4
+ # region: 'us-west-2'
5
+
2
6
  aws_access_key_id: 'YOUR_SECRET_ACCESS_KEY_ID'
3
7
  aws_secret_access_key: 'YOUR_SECRET_ACCESS_KEY'
8
+ # specify another config file for your aws credentials
9
+ # in case you want to keep them encrypted. This file
10
+ # will take presedence if access keys are defined in both
11
+ # files
12
+ # aws_credential_file: '~/YOUR_AWS_CREDENTIAL_FILE'
4
13
 
5
14
  ami_id: 'SOME-AMI'
6
15
  flavor_id: 'm1.large'
7
16
 
8
17
  key_name: 'some-key-pair'
9
- private_key_path: "~/.ssh/some-private-key.pem"
18
+ private_key_path: "~/.ssh/some-private-key.pem"
data/lib/credential.rb ADDED
@@ -0,0 +1,31 @@
1
+ class Credential
2
+ def initialize(config_file)
3
+ @config = load_yaml_file(config_file)
4
+
5
+ unless aws_credential_file.nil?
6
+ @config = load_yaml_file(File.expand_path(aws_credential_file))
7
+ end
8
+ end
9
+
10
+ def secret_access_key
11
+ @config['aws_secret_access_key']
12
+ end
13
+
14
+ def access_key_id
15
+ @config['aws_access_key_id']
16
+ end
17
+
18
+ def aws_credential_file
19
+ @config['aws_credential_file']
20
+ end
21
+
22
+ private
23
+
24
+ def load_yaml_file(file)
25
+ unless File.exists?(file)
26
+ abort "#{file} not found. First run 'pairhost init' or confirm file exists."
27
+ else
28
+ YAML.load_file(file)
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Pairhost
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/pairhost.rb CHANGED
@@ -3,6 +3,7 @@ require 'fog'
3
3
  require 'thor'
4
4
  require 'yaml'
5
5
  require 'fileutils'
6
+ require_relative 'credential'
6
7
 
7
8
  module Pairhost
8
9
  def self.config_file
@@ -14,6 +15,7 @@ module Pairhost
14
15
  unless File.exists?(config_file)
15
16
  abort "pairhost: No config found. First run 'pairhost init'."
16
17
  end
18
+ @credential = Credential.new(config_file)
17
19
  YAML.load_file(config_file)
18
20
  end
19
21
  end
@@ -35,8 +37,9 @@ module Pairhost
35
37
 
36
38
  @connection = Fog::Compute.new(
37
39
  :provider => config['provider'],
38
- :aws_secret_access_key => config['aws_secret_access_key'],
39
- :aws_access_key_id => config['aws_access_key_id'],
40
+ :region => config['region'],
41
+ :aws_secret_access_key => @credential.secret_access_key,
42
+ :aws_access_key_id => @credential.access_key_id
40
43
  )
41
44
  end
42
45
 
@@ -99,8 +102,13 @@ module Pairhost
99
102
  if File.exists?(Pairhost.config_file)
100
103
  STDERR.puts "pairhost: Already initialized."
101
104
  else
105
+ puts "Creating ~/.pairhost directory"
102
106
  FileUtils.mkdir_p File.dirname(Pairhost.config_file)
107
+
108
+ puts "Copying example.yml file to ~/.pairhost directory"
103
109
  FileUtils.cp(File.dirname(__FILE__) + '/../config.example.yml', Pairhost.config_file)
110
+
111
+ puts "Edit ~/.pairhost/config.yml to use your real EC2 & AMI settings"
104
112
  end
105
113
  end
106
114
 
@@ -150,13 +158,24 @@ module Pairhost
150
158
  server = Pairhost.fetch!
151
159
  puts "#{server.id}: #{server.tags['Name']}"
152
160
  puts "State: #{server.state}"
153
- puts server.dns_name if server.dns_name
161
+ if server.dns_name
162
+ puts server.dns_name
163
+ puts Socket.getaddrinfo(server.dns_name, "http").first[3]
164
+ end
154
165
  end
155
166
 
156
167
  desc "ssh", "SSH to your pairhost"
157
168
  def ssh
158
169
  invoke :verify
159
170
  server = Pairhost.fetch!
171
+
172
+ abort "Server is currently #{server.state}" if ["stopping"].include? server.state
173
+
174
+ if ["pending", "stopped"].include? server.state
175
+ invoke :up
176
+ server.wait_for { ready? }
177
+ end
178
+
160
179
  exec "ssh -A -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=QUIET pair@#{server.dns_name}"
161
180
  end
162
181
 
data/pairhost.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
 
18
- s.add_runtime_dependency "fog", "~> 1.3.1"
18
+ s.add_runtime_dependency "fog", "~> 1.12.1"
19
19
  s.add_runtime_dependency "thor", "~> 0.15.2"
20
20
  s.add_runtime_dependency "hirb", "~> 0.6.2"
21
21
  s.add_runtime_dependency "launchy", "~> 2.1.1"
@@ -0,0 +1,26 @@
1
+ require_relative '../lib/credential'
2
+
3
+ describe Credential do
4
+ context "given a config file" do
5
+ let(:config_file) { File.expand_path('../../config.example.yml', __FILE__) }
6
+
7
+ it 'should return a secret access key' do
8
+ credential = Credential.new(config_file)
9
+ credential.secret_access_key.should == "YOUR_SECRET_ACCESS_KEY"
10
+ end
11
+
12
+ it 'should return an access key id' do
13
+ credential = Credential.new(config_file)
14
+ credential.access_key_id.should == "YOUR_SECRET_ACCESS_KEY_ID"
15
+ end
16
+ end
17
+
18
+ context "given a config file for credentials within pairhost config file" do
19
+ let(:config_file) { File.expand_path('../data/config_with_aws_path.yml', __FILE__) }
20
+
21
+ it 'should return an access key' do
22
+ credential = Credential.new(config_file)
23
+ credential.secret_access_key.should == "YOUR_AWS_SECRET_ACCESS_KEY"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,2 @@
1
+ aws_access_key_id: 'YOUR_AWS_SECRET_ACCESS_KEY_ID'
2
+ aws_secret_access_key: 'YOUR_AWS_SECRET_ACCESS_KEY'
@@ -0,0 +1,14 @@
1
+ provider: 'AWS'
2
+ aws_access_key_id: 'YOUR_SECRET_ACCESS_KEY_ID'
3
+ aws_secret_access_key: 'YOUR_SECRET_ACCESS_KEY'
4
+ # specify another config file for your aws credentials
5
+ # in case you want to keep them encrypted. This file
6
+ # will take presedence if access keys are defined in both
7
+ # files
8
+ aws_credential_file: 'spec/data/aws_credentials.yml'
9
+
10
+ ami_id: 'SOME-AMI'
11
+ flavor_id: 'm1.large'
12
+
13
+ key_name: 'some-key-pair'
14
+ private_key_path: "~/.ssh/some-private-key.pem"
@@ -0,0 +1,18 @@
1
+ provider: 'AWS'
2
+ aws_access_key_id: 'YOUR_SECRET_ACCESS_KEY_ID'
3
+ aws_secret_access_key: 'YOUR_SECRET_ACCESS_KEY'
4
+ # optionally specify Region for your AMI
5
+ # FOG gem defaults AWS to 'us-east-1'
6
+ region: 'us-west-2'
7
+
8
+ # specify another config file for your aws credentials
9
+ # in case you want to keep them encrypted. This file
10
+ # will take presedence if access keys are defined in both
11
+ # files
12
+ aws_credential_file: 'spec/data/aws_credentials.yml'
13
+
14
+ ami_id: 'SOME-AMI'
15
+ flavor_id: 'm1.large'
16
+
17
+ key_name: 'some-key-pair'
18
+ private_key_path: "~/.ssh/some-private-key.pem"
@@ -81,6 +81,14 @@ describe Pairhost do
81
81
  end
82
82
  end
83
83
 
84
+ context "using the non default region" do
85
+ let(:config_file) {File.expand_path('../data/config_with_region.yml', __FILE__)}
86
+ it 'should return specified region' do
87
+ Pairhost.stub(:config_file).and_return(config_file)
88
+ Pairhost.connection.region.should be == 'us-west-2'
89
+ end
90
+ end
91
+
84
92
  context "when an instance has been provisioned" do
85
93
  # TODO: make sure the instance_id file exists;
86
94
  # provision an EC2 instance?
metadata CHANGED
@@ -1,178 +1,151 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pairhost
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.5
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.0.6
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Larry Karnowski
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-08 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2013-07-01 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: fog
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ~>
20
- - !ruby/object:Gem::Version
21
- version: 1.3.1
22
- type: :runtime
23
17
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
18
+ requirement: &id001 !ruby/object:Gem::Requirement
25
19
  none: false
26
- requirements:
20
+ requirements:
27
21
  - - ~>
28
- - !ruby/object:Gem::Version
29
- version: 1.3.1
30
- - !ruby/object:Gem::Dependency
31
- name: thor
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ~>
36
- - !ruby/object:Gem::Version
37
- version: 0.15.2
22
+ - !ruby/object:Gem::Version
23
+ version: 1.12.1
38
24
  type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: thor
39
28
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
29
+ requirement: &id002 !ruby/object:Gem::Requirement
41
30
  none: false
42
- requirements:
31
+ requirements:
43
32
  - - ~>
44
- - !ruby/object:Gem::Version
33
+ - !ruby/object:Gem::Version
45
34
  version: 0.15.2
46
- - !ruby/object:Gem::Dependency
47
- name: hirb
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ~>
52
- - !ruby/object:Gem::Version
53
- version: 0.6.2
54
35
  type: :runtime
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: hirb
55
39
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
40
+ requirement: &id003 !ruby/object:Gem::Requirement
57
41
  none: false
58
- requirements:
42
+ requirements:
59
43
  - - ~>
60
- - !ruby/object:Gem::Version
44
+ - !ruby/object:Gem::Version
61
45
  version: 0.6.2
62
- - !ruby/object:Gem::Dependency
63
- name: launchy
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ~>
68
- - !ruby/object:Gem::Version
69
- version: 2.1.1
70
46
  type: :runtime
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: launchy
71
50
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
51
+ requirement: &id004 !ruby/object:Gem::Requirement
73
52
  none: false
74
- requirements:
53
+ requirements:
75
54
  - - ~>
76
- - !ruby/object:Gem::Version
55
+ - !ruby/object:Gem::Version
77
56
  version: 2.1.1
78
- - !ruby/object:Gem::Dependency
57
+ type: :runtime
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
79
60
  name: rspec
80
- requirement: !ruby/object:Gem::Requirement
81
- none: false
82
- requirements:
83
- - - ~>
84
- - !ruby/object:Gem::Version
85
- version: 2.9.0
86
- type: :development
87
61
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
62
+ requirement: &id005 !ruby/object:Gem::Requirement
89
63
  none: false
90
- requirements:
64
+ requirements:
91
65
  - - ~>
92
- - !ruby/object:Gem::Version
66
+ - !ruby/object:Gem::Version
93
67
  version: 2.9.0
94
- - !ruby/object:Gem::Dependency
95
- name: bahia
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ~>
100
- - !ruby/object:Gem::Version
101
- version: 0.7.2
102
68
  type: :development
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
71
+ name: bahia
103
72
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
73
+ requirement: &id006 !ruby/object:Gem::Requirement
105
74
  none: false
106
- requirements:
75
+ requirements:
107
76
  - - ~>
108
- - !ruby/object:Gem::Version
77
+ - !ruby/object:Gem::Version
109
78
  version: 0.7.2
110
- - !ruby/object:Gem::Dependency
111
- name: rake
112
- requirement: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ~>
116
- - !ruby/object:Gem::Version
117
- version: 0.9.2.2
118
79
  type: :development
80
+ version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
82
+ name: rake
119
83
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
84
+ requirement: &id007 !ruby/object:Gem::Requirement
121
85
  none: false
122
- requirements:
86
+ requirements:
123
87
  - - ~>
124
- - !ruby/object:Gem::Version
88
+ - !ruby/object:Gem::Version
125
89
  version: 0.9.2.2
126
- description: A Vagrant-like command line interface for creating, managing, and using
127
- EC2 instances for remote pairing like we do at Relevance.
128
- email:
90
+ type: :development
91
+ version_requirements: *id007
92
+ description: A Vagrant-like command line interface for creating, managing, and using EC2 instances for remote pairing like we do at Relevance.
93
+ email:
129
94
  - larry@hickorywind.org
130
- executables:
95
+ executables:
131
96
  - pairhost
132
97
  extensions: []
98
+
133
99
  extra_rdoc_files: []
134
- files:
100
+
101
+ files:
135
102
  - .gitignore
136
103
  - Gemfile
137
104
  - README.md
138
105
  - Rakefile
139
106
  - bin/pairhost
140
107
  - config.example.yml
108
+ - lib/credential.rb
141
109
  - lib/pairhost.rb
142
110
  - lib/pairhost/version.rb
143
111
  - pairhost.gemspec
112
+ - spec/credential_spec.rb
113
+ - spec/data/aws_credentials.yml
114
+ - spec/data/config_with_aws_path.yml
115
+ - spec/data/config_with_region.yml
144
116
  - spec/pairhost_spec.rb
145
117
  - spec/spec_helper.rb
146
118
  homepage: http://www.github.com/karnowski/pairhost
147
119
  licenses: []
120
+
148
121
  post_install_message:
149
122
  rdoc_options: []
150
- require_paths:
123
+
124
+ require_paths:
151
125
  - lib
152
- required_ruby_version: !ruby/object:Gem::Requirement
126
+ required_ruby_version: !ruby/object:Gem::Requirement
153
127
  none: false
154
- requirements:
155
- - - ! '>='
156
- - !ruby/object:Gem::Version
157
- version: '0'
158
- segments:
159
- - 0
160
- hash: -1667397763441879577
161
- required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: "0"
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
162
133
  none: false
163
- requirements:
164
- - - ! '>='
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- segments:
168
- - 0
169
- hash: -1667397763441879577
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: "0"
170
138
  requirements: []
139
+
171
140
  rubyforge_project:
172
- rubygems_version: 1.8.24
141
+ rubygems_version: 1.8.23
173
142
  signing_key:
174
143
  specification_version: 3
175
144
  summary: Automate creation of Relevance-style pairhost EC2 instances.
176
- test_files:
145
+ test_files:
146
+ - spec/credential_spec.rb
147
+ - spec/data/aws_credentials.yml
148
+ - spec/data/config_with_aws_path.yml
149
+ - spec/data/config_with_region.yml
177
150
  - spec/pairhost_spec.rb
178
151
  - spec/spec_helper.rb