Class: Tama::Apis::Ec2ApiTest
- Inherits:
-
Object
- Object
- Tama::Apis::Ec2ApiTest
- Defined in:
- lib/apis/ec2.rb
Overview
Reads JSON files and returns Hash maps similar to right_aws
Instance Attribute Summary collapse
-
#account ⇒ Object
Returns the value of attribute account.
-
#describe_images_file ⇒ Object
Returns the value of attribute describe_images_file.
-
#describe_instances_file ⇒ Object
< ec2Api.
-
#run_instances_file ⇒ Object
Returns the value of attribute run_instances_file.
-
#terminate_instances_file ⇒ Object
Returns the value of attribute terminate_instances_file.
Instance Method Summary collapse
- #describe_images(list = [], image_type = nil) ⇒ Object
- #describe_instances(list = []) ⇒ Object
-
#initialize ⇒ Ec2ApiTest
constructor
A new instance of Ec2ApiTest.
-
#run_instances(image_id = nil, min_count = nil, max_count = nil, group_ids = nil, key_name = nil, user_data = '', addressing_type = nil, instance_type = nil, kernel_id = nil, ramdisk_id = nil, availability_zone = nil, block_device_mappings = nil) ⇒ Object
The arguments here are just placeholders to match the real run_instances method.
- #terminate_instances(list = []) ⇒ Object
Constructor Details
#initialize ⇒ Ec2ApiTest
Returns a new instance of Ec2ApiTest.
17 18 19 20 21 22 23 |
# File 'lib/apis/ec2.rb', line 17 def initialize self.terminate_instances_file = "#{File.(File.dirname(__FILE__))}/../../test/test_files/terminate_instances.json" self.describe_images_file = "#{File.(File.dirname(__FILE__))}/../../test/test_files/describe_images.json" self.describe_instances_file = "#{File.(File.dirname(__FILE__))}/../../test/test_files/describe_instances.json" self.run_instances_file = "#{File.(File.dirname(__FILE__))}/../../test/test_files/run_instances.json" self.account = "a-shpoolxx" end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
15 16 17 |
# File 'lib/apis/ec2.rb', line 15 def account @account end |
#describe_images_file ⇒ Object
Returns the value of attribute describe_images_file.
12 13 14 |
# File 'lib/apis/ec2.rb', line 12 def describe_images_file @describe_images_file end |
#describe_instances_file ⇒ Object
< ec2Api
11 12 13 |
# File 'lib/apis/ec2.rb', line 11 def describe_instances_file @describe_instances_file end |
#run_instances_file ⇒ Object
Returns the value of attribute run_instances_file.
13 14 15 |
# File 'lib/apis/ec2.rb', line 13 def run_instances_file @run_instances_file end |
#terminate_instances_file ⇒ Object
Returns the value of attribute terminate_instances_file.
14 15 16 |
# File 'lib/apis/ec2.rb', line 14 def terminate_instances_file @terminate_instances_file end |
Instance Method Details
#describe_images(list = [], image_type = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/apis/ec2.rb', line 71 def describe_images(list=[], image_type=nil) File.open(self.describe_images_file) { |file| res = JSON.parse(file.readlines.join.to_s).first["results"] res.delete_if {|item| not list.member?(item["id"])} unless list.empty? res.map { |img_map| {:root_device_name=>"", :aws_ramdisk_id=>"", :block_device_mappings=>[{:ebs_snapshot_id=>"", :ebs_volume_size=>0, :ebs_delete_on_termination=>false, :device_name=>""}], :aws_is_public=>img_map["is_public"], :virtualization_type=>"", :image_owner_alias=>"", :aws_id=>img_map["uuid"], :aws_architecture=>img_map["arch"], :root_device_type=>"", :aws_location=>img_map["source"], :aws_image_type=>"", :name=>"", :aws_state=>img_map["state"], :description=>img_map["description"], :aws_kernel_id=>"", :tags=>{}, :aws_owner=>img_map["account_id"] } } } end |
#describe_instances(list = []) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/apis/ec2.rb', line 25 def describe_instances(list=[]) File.open(self.describe_instances_file) { |file| res = JSON.parse(file.readlines.join.to_s).first["results"] res.delete_if {|item| not list.member?(item["id"])} unless list.empty? res.map { |inst_map| dns_name = inst_map["network"].first["nat_dns_name"] unless inst_map["network"].nil? || inst_map["network"].empty? private_dns_name = inst_map["network"].first["dns_name"] unless inst_map["network"].nil? || inst_map["network"].empty? ip_address = inst_map["vif"].first["ipv4"]["nat_address"] unless inst_map["vif"].nil? || inst_map["vif"].empty? || inst_map["vif"].first["ipv4"].nil? private_ip_address = inst_map["vif"].first["ipv4"]["address"] unless inst_map["vif"].nil? || inst_map["vif"].empty? || inst_map["vif"].first["ipv4"].nil? {:aws_kernel_id=>"", :aws_launch_time=>inst_map["created_at"], :tags=>{}, :aws_reservation_id=>"", :aws_owner=>self.account, :instance_lifecycle=>"", :block_device_mappings=>[{:ebs_volume_id=>"", :ebs_status=>"", :ebs_attach_time=>"", :ebs_delete_on_termination=>false, :device_name=>""}], :ami_launch_index=>"", :root_device_name=>"", :aws_ramdisk_id=>"", :aws_availability_zone=>inst_map["host_node"], :aws_groups=>inst_map["netfilter_group_id"], :spot_instance_request_id=>"", :ssh_key_name=>"", :virtualization_type=>"", :placement_group_name=>"", :requester_id=>"", :aws_instance_id=>inst_map["id"], :aws_product_codes=>[], :client_token=>"", :private_ip_address=>private_ip_address, :architecture=>inst_map["arch"], :aws_state_code=>0, :aws_image_id=>inst_map["image_id"], :root_device_type=>"", :ip_address=>ip_address, :dns_name=>dns_name, :monitoring_state=>"", :aws_instance_type=>inst_map["instance_spec_id"], :aws_state=>inst_map["state"], :private_dns_name=>private_dns_name, :aws_reason=>"" } } } end |
#run_instances(image_id = nil, min_count = nil, max_count = nil, group_ids = nil, key_name = nil, user_data = '', addressing_type = nil, instance_type = nil, kernel_id = nil, ramdisk_id = nil, availability_zone = nil, block_device_mappings = nil) ⇒ Object
The arguments here are just placeholders to match the real run_instances method. The output is read from a file as usual.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/apis/ec2.rb', line 103 def run_instances(image_id=nil, min_count=nil, max_count=nil, group_ids=nil, key_name=nil, user_data='', addressing_type = nil, instance_type = nil, kernel_id = nil, ramdisk_id = nil, availability_zone = nil, block_device_mappings = nil) File.open(self.run_instances_file) { |file| JSON.parse(file.readlines.join.to_s).map { |inst_map| dns_name = inst_map["network"].first["nat_dns_name"] unless inst_map["network"].nil? || inst_map["network"].empty? private_dns_name = inst_map["network"].first["dns_name"] unless inst_map["network"].nil? || inst_map["network"].empty? {:aws_launch_time=>inst_map["created_at"], :tags=>{}, :aws_reservation_id=>"", :aws_owner=>self.account, :ami_launch_index=>"", :aws_availability_zone=>"", :aws_groups=>inst_map["netfilter_group_id"], :ssh_key_name=>inst_map["ssh_key_pair"], :virtualization_type=>"", :placement_group_name=>"", :aws_instance_id=>inst_map["id"], :aws_product_codes=>[], :client_token=>"", :aws_state_code=>0, :aws_image_id=>inst_map["image_id"], :dns_name=>dns_name, :aws_instance_type=>inst_map["instance_spec_id"], :aws_state=>inst_map["state"], :private_dns_name=>private_dns_name, :aws_reason=>""} } } end |
#terminate_instances(list = []) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/apis/ec2.rb', line 132 def terminate_instances(list=[]) File.open(self.terminate_instances_file) { |file| JSON.parse(file.readlines.join.to_s).map { |instance_id| {:aws_current_state_name=>"", :aws_prev_state_name=>"", :aws_prev_state_code=>0, :aws_current_state_code=>0, :aws_instance_id=>instance_id} } } end |