instant_ec2 0.1.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 +7 -0
- checksums.yaml.gz.sig +0 -0
- data/lib/instant_ec2.rb +113 -0
- data.tar.gz.sig +0 -0
- metadata +87 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 73d849bb6b5614cceddcdb42507e205d62db20c2
|
4
|
+
data.tar.gz: 310876d9dbe8088f169329d3e6dd9bcefa8212f4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a932aee73fb96aee99650408738b6a5506292fab620738e5973fdc21516e443c2c740d6adbe9a9e7162cbb7afdb871b643eadcd89c6f158a8c4e316621956ee7
|
7
|
+
data.tar.gz: fd2d533ecf671566de3eef0428e244a94fa431d145fa46e68d11c715e95a15f36cc42696bb2cd2ebfa342f0665b0bd5e0cb8b3ef3a10d9bdfe510f9c987467b5
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data/lib/instant_ec2.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: instant_ec2.rb
|
4
|
+
|
5
|
+
require 'aws-sdk'
|
6
|
+
|
7
|
+
|
8
|
+
class EC2Instance < Hash
|
9
|
+
|
10
|
+
def initialize(h, ec2=nil)
|
11
|
+
|
12
|
+
@ec2 = ec2
|
13
|
+
super().merge!(h)
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def start()
|
18
|
+
|
19
|
+
@ec2.start_instances instance_ids: [self[:instance_id]]
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class InstantEC2
|
25
|
+
|
26
|
+
attr_reader :images
|
27
|
+
|
28
|
+
def initialize(credentials: [], region: 'us-east-1')
|
29
|
+
|
30
|
+
@ec2 = Aws::EC2::Client.new(region: region,
|
31
|
+
credentials: Aws::Credentials.new(*credentials))
|
32
|
+
|
33
|
+
r = @ec2.describe_instances.reservations
|
34
|
+
image_ids = r.map{|x| x[:instances][0][:image_id] }
|
35
|
+
image_names = @ec2.describe_images(image_ids: image_ids).images.\
|
36
|
+
map{|x| x.name }
|
37
|
+
instance_ids = r.map{|x| x.instances[0].instance_id}
|
38
|
+
|
39
|
+
@images = image_names.zip(instance_ids).inject([]) do |r, x|
|
40
|
+
|
41
|
+
name, id = x
|
42
|
+
r << EC2Instance.new({image_name: name, instance_id: id}, @ec2)
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def find_image(s)
|
49
|
+
@images.find {|x| x[:image_name][/#{s}/i]}
|
50
|
+
end
|
51
|
+
|
52
|
+
def find_running()
|
53
|
+
|
54
|
+
r = @ec2.describe_instances.reservations.detect do |x|
|
55
|
+
x.instances[0].state.name != 'stopped'
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
def ip()
|
61
|
+
r = self.find_running
|
62
|
+
r.instances[0].public_ip_address if r
|
63
|
+
end
|
64
|
+
|
65
|
+
def on_running()
|
66
|
+
|
67
|
+
# timeout after 30 seconds
|
68
|
+
t1 = Time.now
|
69
|
+
sleep 1; ip = self.ip until ip or Time.now > t1 + 30
|
70
|
+
|
71
|
+
if ip then
|
72
|
+
yield(ip)
|
73
|
+
else
|
74
|
+
puts 'on_running timedout'
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
alias running find_running
|
80
|
+
|
81
|
+
def start(s)
|
82
|
+
self.find_image(s).start
|
83
|
+
end
|
84
|
+
|
85
|
+
def stop
|
86
|
+
|
87
|
+
r = self.find_running()
|
88
|
+
|
89
|
+
if r then
|
90
|
+
|
91
|
+
puts 'stopping ...'
|
92
|
+
instance_id = r.instances[0].instance_id
|
93
|
+
@ec2.stop_instances instance_ids: [instance_id]
|
94
|
+
|
95
|
+
else
|
96
|
+
puts 'no instances to stop'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def on_stopping()
|
101
|
+
|
102
|
+
# timeout after 30 seconds
|
103
|
+
t1 = Time.now
|
104
|
+
sleep 1; ip = self.ip until ip.nil? or Time.now > t1 + 30
|
105
|
+
|
106
|
+
if ip.nil? then
|
107
|
+
yield
|
108
|
+
else
|
109
|
+
puts 'on_stopping timedout'
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
data.tar.gz.sig
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: instant_ec2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Robertson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
|
14
|
+
YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
|
15
|
+
8ixkARkWAmV1MB4XDTE1MTIyMDEyMzQ1M1oXDTE2MTIxOTEyMzQ1M1owSDESMBAG
|
16
|
+
A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
|
17
|
+
EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
|
18
|
+
ggEBAOL9HWugTkz4PWUVXPP5RHfk+z0Zw9ruGsWxVvIA9lHzqwmrgxVx0q/wc9Hv
|
19
|
+
TCMVFKiVAryDvwwbm3vpxBojd75QEknRHDCPvHXxMSlshj6PB5GUd7PNyi8byeGj
|
20
|
+
3Bpin6q39gt/wZJNBpuivepp+EuyaOHf5O2E35jM4SfEwkzN0DRf81XppJ2hPIz2
|
21
|
+
udmlZNLbcfxGEh1uBGkHrtesONSsUbGpDrjXlX0RGbt/fnqaX1G5msXbVwx6mOAd
|
22
|
+
DYOQzhlq3bCvx1lQmKDMcLgKgtoovm7wi+wW09jlF+odbeetqs3/DO2P/lL57WMU
|
23
|
+
oy+dZ5BxK6vlKPEDCqXNcVYgg50CAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
|
24
|
+
DwQEAwIEsDAdBgNVHQ4EFgQUo1yARhuV7ZyKmkIeRZF5cbtx5xcwJgYDVR0RBB8w
|
25
|
+
HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
|
26
|
+
c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEAl90VSpCF
|
27
|
+
BWuaKekhZNMVAwdYZ9FnBbBPUsKrzopv3ye8svNtNdn9H1k19ZchyqOG5aIauh1I
|
28
|
+
LHIfGW9WMWUxLEWIEf9VITsDHU6uIanPG73e4gNgfnQj33Z2UJTFh0kpLEVlhNQ/
|
29
|
+
2qYKX1wKxVkN03UlW7+M1JGeY16gjRkxxcV15Re8pZBXTFeMPGHHkyYx+W9O6gwp
|
30
|
+
BVzxCEtTfnBe45ftRA1qsABFh85y7UIye4uM2GgowTEhjhvWK7LJ7HWXiiuQBP2s
|
31
|
+
I2p/gjcBfDCdq3/4DlrprfJdiPD30+XqKCWbt0NOod/6Ky8nvmilmfrciMvsgp+g
|
32
|
+
bO5j5Um4EdA15w==
|
33
|
+
-----END CERTIFICATE-----
|
34
|
+
date: 2015-12-20 00:00:00.000000000 Z
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: aws-sdk
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.2'
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.2.7
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - "~>"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2.2'
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.2.7
|
56
|
+
description:
|
57
|
+
email: james@r0bertson.co.uk
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- lib/instant_ec2.rb
|
63
|
+
homepage: https://github.com/jrobertson/instant_ec2
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.4.8
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Start your EC2 instance in an instant.
|
87
|
+
test_files: []
|
metadata.gz.sig
ADDED
Binary file
|