stem 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -7,6 +7,22 @@ Stem is a thin, light-weight EC2 instance management library which abstracts the
7
7
 
8
8
  Stem is named after the model it encourages -- simple AMIs created on demand with many running copies derived from that.
9
9
 
10
+ ##Configuration
11
+
12
+ Stem relies on the Swirl library, which needs to be passed your AWS credentials to do its magic. There are two ways to set these.
13
+
14
+ In your environment:
15
+
16
+ export AWS_ACCESS_KEY_ID=my_access_key
17
+ export AWS_SECRET_ACCESS_KEY=my_secret_key
18
+
19
+ or in ~/.swirl:
20
+
21
+ ---
22
+ :default:
23
+ :aws_access_key_id: my_access_key
24
+ :aws_secret_access_key: my_secret_key
25
+
10
26
  ##Usage
11
27
 
12
28
  You can use Stem to manage your instances either from the commandline or directly via the library. You should create an instance which will serve as your "stem" and be converted into an AMI. Once you have tested this instance, create a snapshot of the instance, then use it by name to launch new instances with their own individual configuration.
@@ -0,0 +1,52 @@
1
+ module Stem
2
+ module KeyPair
3
+ include Util
4
+ extend self
5
+
6
+ def create(name)
7
+ swirl.call('CreateKeyPair', 'KeyName' => name)
8
+ true
9
+ rescue Swirl::InvalidRequest => e
10
+ raise e unless e.message =~ /The keypair '\S+' already exists/
11
+ false
12
+ end
13
+
14
+ def destroy(name)
15
+ destroy!(name)
16
+ true
17
+ rescue Swirl::InvalidRequest => e
18
+ puts "===> #{e.class}"
19
+ puts "===> #{e.message}"
20
+ puts "#{e.backtrace.join("\n")}"
21
+ false
22
+ end
23
+
24
+ def destroy!(name)
25
+ swirl.call('DeleteKeyPair', 'KeyName' => name)
26
+ end
27
+
28
+ def describe(names)
29
+ swirl.call('DescribeKeyPairs', 'KeyName' => names)
30
+ end
31
+
32
+ def exists?(name)
33
+ true if describe(name)
34
+ rescue Swirl::InvalidRequest => e
35
+ raise e unless e.message.match(/does not exist$/)
36
+ false
37
+ end
38
+
39
+ def import(name, key_string)
40
+ require 'base64'
41
+ swirl.call('ImportKeyPair', {
42
+ 'KeyName' => name,
43
+ 'PublicKeyMaterial' => Base64.encode64(key_string)
44
+ })
45
+ true
46
+ rescue Swirl::InvalidRequest => e
47
+ raise e unless e.message =~ /The keypair '\S+' already exists/
48
+ false
49
+ end
50
+
51
+ end
52
+ end
data/lib/stem/util.rb CHANGED
@@ -12,7 +12,13 @@ module Stem
12
12
  }
13
13
  else
14
14
  account = account.to_sym
15
- data = YAML.load_file(etc)
15
+
16
+ if File.exists?(etc)
17
+ data = YAML.load_file(etc)
18
+ else
19
+ abort("I was expecting to find a .swirl file in your home directory.")
20
+ end
21
+
16
22
  if data.key?(account)
17
23
  data[account]
18
24
  else
data/lib/stem.rb CHANGED
@@ -11,5 +11,6 @@ require 'stem/instance'
11
11
  require 'stem/instance_types'
12
12
  require 'stem/image'
13
13
  require 'stem/ip'
14
+ require 'stem/key_pair'
14
15
  require 'stem/tag'
15
16
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stem
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 5
10
- version: 0.4.5
9
+ - 6
10
+ version: 0.4.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Peter van Hardenberg
@@ -54,6 +54,7 @@ files:
54
54
  - lib/stem/instance.rb
55
55
  - lib/stem/instance_types.rb
56
56
  - lib/stem/ip.rb
57
+ - lib/stem/key_pair.rb
57
58
  - lib/stem/tag.rb
58
59
  - lib/stem/userdata.rb
59
60
  - lib/stem/util.rb