lightswitch-cloud 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/lightswitch/cloud.rb +46 -0
- data/lib/lightswitch/errors.rb +3 -0
- metadata +47 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
require_relative 'errors'
|
3
|
+
|
4
|
+
module Lightswitch
|
5
|
+
class Cloud
|
6
|
+
|
7
|
+
EC2_REGIONS = %w( eu-central-1 sa-east-1 ap-northeast-1 eu-west-1 us-east-1 us-west-1 us-west-2 ap-southeast-2 ap-southeast-1 )
|
8
|
+
|
9
|
+
def initialize(credentials)
|
10
|
+
access_key_id = credentials[:access_key_id]
|
11
|
+
secret_access_key = credentials[:secret_access_key]
|
12
|
+
raise Errors::AwsCredentialsNotFoundError, 'AWS credentials were not provided' unless access_key_id && secret_access_key
|
13
|
+
|
14
|
+
Aws.config.update({access_key_id: access_key_id, secret_access_key: secret_access_key})
|
15
|
+
validate_access
|
16
|
+
end
|
17
|
+
|
18
|
+
def get_instance_status(instance_id, region_name)
|
19
|
+
begin
|
20
|
+
client = get_client(region_name)
|
21
|
+
response = client.describe_instance_status({instance_ids: [instance_id], include_all_instances: true})
|
22
|
+
if response
|
23
|
+
response.first['instance_statuses'].first.instance_state.name
|
24
|
+
else
|
25
|
+
'unavailable'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def validate_access
|
31
|
+
client = get_client(EC2_REGIONS.first)
|
32
|
+
begin
|
33
|
+
client.describe_regions
|
34
|
+
end
|
35
|
+
true
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def get_client(region_name)
|
41
|
+
@clients_by_region ||= {}
|
42
|
+
@clients_by_region[region_name] ||= Aws::EC2::Client.new(region: region_name)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lightswitch-cloud
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Krishnan M
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Implements functionality in lightswitch for AWS!
|
15
|
+
email: km@krishnanm.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/lightswitch/cloud.rb
|
21
|
+
- lib/lightswitch/errors.rb
|
22
|
+
homepage: http://rubygems.org/gems/lightswitch-cloud
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubyforge_project:
|
43
|
+
rubygems_version: 1.8.24
|
44
|
+
signing_key:
|
45
|
+
specification_version: 3
|
46
|
+
summary: Turn instances on and off in the cloud at will!
|
47
|
+
test_files: []
|