Class: Ec2l::Client
- Inherits:
-
Object
show all
- Defined in:
- lib/ec2l.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
66
67
68
69
70
|
# File 'lib/ec2l.rb', line 66
def method_missing method, *args, &block
puts "Usage: action parameters...", "available actions:"
awesome_print (public_methods - "".public_methods)
nil
end
|
Instance Method Details
#i ⇒ Object
23
|
# File 'lib/ec2l.rb', line 23
def i() instances ["instanceId", "ipAddress", "tagSet", "instanceState"] end
|
#instance(id) ⇒ Object
17
|
# File 'lib/ec2l.rb', line 17
def instance(id) @ec2.describe_instances(instance_id: id) end
|
#instances(keep = ["instanceId", "ipAddress", "groups",
"launchType", "instanceType", "tagSet"]) ⇒ Object
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/ec2l.rb', line 7
def instances keep = ["instanceId", "ipAddress", "groups",
"launchType", "instanceType", "tagSet"]
@ec2.describe_instances.reservationSet.item.collect do |item|
group = item.groupSet if keep.include? "groups"
item = item.instancesSet.item[0].reject{|k, v| not keep.include? k}
item["groups"] = group.item.map{|x| x.groupId } if not group.nil?
item["tagSet"] = to_hash(item["tagSet"].item) if item["tagSet"]
Hash[item.map { |k, v| [k.to_sym, v] }]
end
end
|
#log(id) ⇒ Object
24
25
26
|
# File 'lib/ec2l.rb', line 24
def log id
puts Base64.decode64 @ec2.get_console_output(instance_id: id)["output"]
end
|
#read_credentials ⇒ Object
43
44
45
46
47
|
# File 'lib/ec2l.rb', line 43
def read_credentials
creds = []
File.open(@conf) { |f| f.each_line { |l| creds << l.chomp } } if File.exists?(@conf)
creds
end
|
#sgs ⇒ Object
18
19
20
21
22
|
# File 'lib/ec2l.rb', line 18
def sgs
@ec2.describe_security_groups.securityGroupInfo.item.collect do |item|
item.reject { |k, v| not ["groupName", "ownerId"].include? k }
end
end
|
#shell ⇒ Object
28
|
# File 'lib/ec2l.rb', line 28
def shell() binding.pry end
|
#terminate(id) ⇒ Object
27
|
# File 'lib/ec2l.rb', line 27
def terminate(id) @ec2.terminate_instances(instance_id: id) end
|
#update_configuration(creds = nil) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/ec2l.rb', line 29
def update_configuration creds = nil
puts "Will try and update configuration in #{@conf}"
creds = read_credentials if creds.nil?
File.open(@conf, "w") do |f|
["access key", "secret access key",
"entry point (default being https://aws.amazon.com if blank)"
].each_with_index do |prompt, i|
printf "#{prompt} (#{creds.size > i ? creds[i]:""}): "
line = $stdin.gets.chomp
line = creds[i] if line.empty? and creds.size > i
f.puts line if not line.empty?
end
end
end
|