Class: AWSTracker::Instance
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AWSTracker::Instance
- Includes:
- Taggable
- Defined in:
- lib/aws_tracker/models/instance.rb
Class Method Summary collapse
Instance Method Summary collapse
- #update_from_right_hash(rs_instance) ⇒ Object
-
#update_security_groups(group_names) ⇒ Object
Updates this Instance’s ActiveRecord relationship security_groups based on group_names, an array of strings.
Methods included from Taggable
Class Method Details
.refresh_from_account(acc) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/aws_tracker/models/instance.rb', line 15 def self.refresh_from_account(acc) acc.log.info "Updating instances for account '#{acc.name}'" right_aws_array = acc.ec2.describe_instances right_aws_array.each do |right_aws_hash| aws_id = right_aws_hash[:aws_instance_id] instance = Instance.find_or_initialize_by_instance_id(aws_id) do |inst| acc.instances << inst inst.account = acc end instance.update_from_right_hash(right_aws_hash) instance.save end acc.log.info "Account '#{acc.name}' reports #{right_aws_array.count} instances" end |
Instance Method Details
#update_from_right_hash(rs_instance) ⇒ Object
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 |
# File 'lib/aws_tracker/models/instance.rb', line 30 def update_from_right_hash(rs_instance) self.instance_id = rs_instance[:aws_instance_id] self.image_id = rs_instance[:aws_image_id] self.instance_state = rs_instance[:aws_state] self.state_code = rs_instance[:aws_state_code] self.instance_type = rs_instance[:aws_instance_type] self.private_dns_name = rs_instance[:private_dns_name] self.dns_name = rs_instance[:dns_name] self.key_name = rs_instance[:ssh_key_name] self.ami_launch_index = rs_instance[:ami_launch_index] self.launch_time = rs_instance[:aws_launch_time] self.termination_time = rs_instance[:aws_termination_time] self.availability_zone = rs_instance[:aws_availability_zone] self.kernel_id = rs_instance[:aws_kernel_id] self.ramdisk_id = rs_instance[:aws_ramdisk_id] self.private_ip_address = rs_instance[:private_ip_address] self.ip_address = rs_instance[:ip_address] self.architecture = rs_instance[:architecture] self.root_device_type = rs_instance[:root_device_type] self.root_device_name = rs_instance[:root_device_name] self.virtualization_type = rs_instance[:virtualization_type] self.reason = rs_instance[:aws_reason] self. = rs_instance[:state_reason_message] self.vpc_id = rs_instance[:vpc_id] #:instance_life_cycle = rs_instance[:XXXXXXXXX] #:spot_instance_request_id = rs_instance[:XXXXXXXXX] update_security_groups(rs_instance[:aws_groups]) end |
#update_security_groups(group_names) ⇒ Object
Updates this Instance’s ActiveRecord relationship security_groups based on group_names, an array of strings
61 62 63 64 65 66 67 68 69 |
# File 'lib/aws_tracker/models/instance.rb', line 61 def update_security_groups(group_names) new_groups = [] group_names.each do |name| new_group = self.account.security_groups.find(:first, :conditions => {:name => name}) new_groups.push(new_group) if new_group end self.security_groups = new_groups end |