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 30
def disabled_api_termination?
  ret = find_ec2_attribute(id, 'disableApiTermination')
  ret.disable_api_termination.value
end
has_ebs?(volume_id) click to toggle source
# File lib/awspec/type/ec2.rb, line 73
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 35
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 95
def has_event?(event_code)
  status = find_ec2_status(id)
  ret = status.events.find do |event|
    event.code == event_code
  end
end
has_events?() click to toggle source
# File lib/awspec/type/ec2.rb, line 102
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 67
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 86
def has_network_interface?(network_interface_id, device_index = nil)
  res = find_network_interface(network_interface_id)
  interfaces = resource_via_client.network_interfaces
  ret = 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 54
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 45
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

Private Instance Methods

match_group_ids?(sg_ids) click to toggle source
# File lib/awspec/type/ec2.rb, line 133
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 137
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 141
def resource_security_groups
  resource_via_client.security_groups
end