class Awspec::Type::Ec2
Constants
- STATES
Public Class Methods
new(name)
click to toggle source
Calls superclass method
# File lib/awspec/type/ec2.rb, line 6 def initialize(name) super @display_name = name end
Public Instance Methods
disabled_api_termination?()
click to toggle source
# File lib/awspec/type/ec2.rb, line 34 def disabled_api_termination? ret = find_ec2_attribute(id, 'disableApiTermination') ret.disable_api_termination.value end
has_classiclink?(vpc_id = nil)
click to toggle source
# File lib/awspec/type/ec2.rb, line 112 def has_classiclink?(vpc_id = nil) option = { instance_ids: [id] } option[:filters] = [{ name: 'vpc-id', values: [vpc_id] }] if vpc_id ret = ec2_client.describe_classic_link_instances(option) return ret.instances.count == 1 if vpc_id end
has_classiclink_security_group?(sg_id)
click to toggle source
# File lib/awspec/type/ec2.rb, line 121 def has_classiclink_security_group?(sg_id) option = { instance_ids: [id] } classic_link_instances = ec2_client.describe_classic_link_instances(option) return false if classic_link_instances.instances.count == 0 instances = classic_link_instances[0] sgs = instances[0].groups ret = sgs.find do |sg| sg.group_id == sg_id || sg.group_name == sg_id end return true if ret end
has_credit_specification?(cpu_credits)
click to toggle source
# File lib/awspec/type/ec2.rb, line 135 def has_credit_specification?(cpu_credits) ret = find_ec2_credit_specifications(id) ret.cpu_credits == cpu_credits end
has_ebs?(volume_id)
click to toggle source
# File lib/awspec/type/ec2.rb, line 77 def has_ebs?(volume_id) blocks = resource_via_client.block_device_mappings ret = blocks.find do |block| next false unless block.ebs block.ebs.volume_id == volume_id end return true if ret blocks2 = find_ebs(volume_id) blocks2.attachments.find do |attachment| attachment.instance_id == id end end
has_eip?(ip_address = nil)
click to toggle source
# File lib/awspec/type/ec2.rb, line 39 def has_eip?(ip_address = nil) option = { filters: [{ name: 'instance-id', values: [id] }] } option[:public_ips] = [ip_address] if ip_address ret = ec2_client.describe_addresses(option) return ret.addresses.count == 1 if ip_address return ret.addresses.count > 0 unless ip_address end
has_event?(event_code)
click to toggle source
# File lib/awspec/type/ec2.rb, line 99 def has_event?(event_code) status = find_ec2_status(id) status.events.find do |event| event.code == event_code end end
has_events?()
click to toggle source
# File lib/awspec/type/ec2.rb, line 106 def has_events? status = find_ec2_status(id) return false if status.nil? status.events.count > 0 end
has_iam_instance_profile?(iam_instance_profile_name)
click to toggle source
# File lib/awspec/type/ec2.rb, line 71 def has_iam_instance_profile?(iam_instance_profile_name) iam = resource_via_client.iam_instance_profile ret = iam.arn.split('/').last == iam_instance_profile_name return true if ret end
has_network_interface?(network_interface_id, device_index = nil)
click to toggle source
# File lib/awspec/type/ec2.rb, line 90 def has_network_interface?(network_interface_id, device_index = nil) res = find_network_interface(network_interface_id) interfaces = resource_via_client.network_interfaces interfaces.find do |interface| next false if device_index && interface.attachment.device_index != device_index interface.network_interface_id == res.network_interface_id end end
has_security_group?(sg_id)
click to toggle source
# File lib/awspec/type/ec2.rb, line 58 def has_security_group?(sg_id) sgs = resource_via_client.security_groups ret = sgs.find do |sg| sg.group_id == sg_id || sg.group_name == sg_id end return true if ret sg2 = find_security_group(sg_id) return false unless sg2.tag_name == sg_id sgs.find do |sg| sg.group_id == sg2.group_id end end
has_security_groups?(sg_ids)
click to toggle source
# File lib/awspec/type/ec2.rb, line 49 def has_security_groups?(sg_ids) return true if match_group_ids?(sg_ids) || match_group_names?(sg_ids) group_ids = resource_security_groups.map { |sg| sg.group_id } tags = select_security_group_by_group_id(group_ids).map { |sg| sg.tags }.flatten group_names = tags.select { |tag| tag.key == 'Name' }.map { |tag| tag.value } group_names == sg_ids end
id()
click to toggle source
# File lib/awspec/type/ec2.rb, line 15 def id @id ||= resource_via_client.instance_id if resource_via_client end
resource_via_client()
click to toggle source
# File lib/awspec/type/ec2.rb, line 11 def resource_via_client @resource_via_client ||= find_ec2(@display_name) end
security_group_count()
click to toggle source
# File lib/awspec/type/ec2.rb, line 19 def security_group_count resource_via_client.security_groups.count end
Private Instance Methods
match_group_ids?(sg_ids)
click to toggle source
# File lib/awspec/type/ec2.rb, line 142 def match_group_ids?(sg_ids) sg_ids.sort == resource_security_groups.map { |sg| sg.group_id }.sort end
match_group_names?(sg_names)
click to toggle source
# File lib/awspec/type/ec2.rb, line 146 def match_group_names?(sg_names) sg_names.sort == resource_security_groups.map { |sg| sg.group_name }.sort end
resource_security_groups()
click to toggle source
# File lib/awspec/type/ec2.rb, line 150 def resource_security_groups resource_via_client.security_groups end