class Awspec::Type::Ec2

Constants

STATES

required by Awspec::Generator::Doc::Type

Public Class Methods

new(name) click to toggle source
Calls superclass method
# File lib/awspec/type/ec2.rb, line 10
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 38
def disabled_api_termination?
  ret = find_ec2_attribute(id, 'disableApiTermination')
  ret.disable_api_termination.value
end
has_credit_specification?(cpu_credits) click to toggle source
# File lib/awspec/type/ec2.rb, line 150
def has_credit_specification?(cpu_credits)
  find_ec2_credit_specifications(id).cpu_credits == cpu_credits
end
has_ebs?(volume_id) click to toggle source
# File lib/awspec/type/ec2.rb, line 85
def has_ebs?(volume_id)
  check_existence
  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 43
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 112
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 119
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 78
def has_iam_instance_profile?(iam_instance_profile_name)
  check_existence
  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 101
def has_network_interface?(network_interface_id, device_index = nil)
  res = find_network_interface(network_interface_id)
  check_existence
  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 62
def has_security_group?(sg_id)
  check_existence
  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 53
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 29
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 25
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 33
def security_group_count
  check_existence
  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 156
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 160
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 164
def resource_security_groups
  check_existence
  resource_via_client.security_groups
end