Class: Awspec::Type::Elb

Inherits:
Base
  • Object
show all
Defined in:
lib/awspec/type/elb.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#id

Attributes included from Helper::Finder

#ec2_client

Instance Method Summary collapse

Methods inherited from Base

#exists?

Methods included from Helper::Finder::Elb

#find_elb, #select_elb_by_vpc_id

Methods included from Helper::Finder::Ebs

#find_ebs, #select_ebs_by_instance_id

Methods included from Helper::Finder::AutoScaling

#find_auto_scaling_group

Methods included from Helper::Finder::S3

#find_bucket

Methods included from Helper::Finder::Route53

#find_hosted_zone

Methods included from Helper::Finder::Rds

#find_rds, #select_rds_by_vpc_id

Methods included from Helper::Finder::SecurityGroup

#find_security_group, #select_security_group_by_vpc_id

Methods included from Helper::Finder::Ec2

#find_ec2, #find_internet_gateway, #find_security_group, #find_subnet, #select_ec2_by_vpc_id, #select_eip_by_instance_id

Methods included from Helper::Finder::Vpc

#find_network_acl, #find_route_table, #find_vpc, #select_network_acl_by_vpc_id, #select_route_table_by_vpc_id

Constructor Details

#initialize(id) ⇒ Elb

Returns a new instance of Elb.



5
6
7
8
9
# File 'lib/awspec/type/elb.rb', line 5

def initialize(id)
  super
  @lb = find_elb(id)
  @id = @lb[:load_balancer_name] if @lb
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/awspec/type/elb.rb', line 22

def method_missing(name)
  describe = name.to_sym
  if @lb.members.include?(describe)
    @lb[describe]
  else
    super
  end
end

Instance Attribute Details

#lbObject (readonly)

Returns the value of attribute lb.



3
4
5
# File 'lib/awspec/type/elb.rb', line 3

def lb
  @lb
end

Instance Method Details

#has_ec2?(id) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
# File 'lib/awspec/type/elb.rb', line 31

def has_ec2?(id)
  ec2 = find_ec2(id)
  @lb.instances.find do |instance|
    instance.instance_id = ec2.instance_id
  end if ec2
end

#has_listener?(protocol:, port:, instance_protocol:, instance_port:) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
# File 'lib/awspec/type/elb.rb', line 63

def has_listener?(protocol:, port:, instance_protocol:, instance_port:)
  @lb[:listener_descriptions].find do |desc|
    listener = desc.listener
    listener.protocol == protocol && listener.load_balancer_port == port && \
      listener.instance_protocol == instance_protocol && listener.instance_port == instance_port
  end
end

#has_security_group?(sg_id) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/awspec/type/elb.rb', line 38

def has_security_group?(sg_id)
  sgs = @lb[:security_groups]
  ret = sgs.find do |sg|
    sg == sg_id
  end
  return true if ret
  sg2 = find_security_group(sg_id)
  return false unless sg2.tag_name == sg_id || sg2[:group_name] == sg_id
  sgs.find do |sg|
    sg == sg2[:group_name]
  end
end

#has_subnet?(subnet_id) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/awspec/type/elb.rb', line 51

def has_subnet?(subnet_id)
  subnets = @lb[:subnets]
  ret = subnets.find do |s|
    s == subnet_id
  end
  return true if ret
  res = find_subnet(subnet_id)
  ret = subnets.find do |s|
    s == res[:subnet_id]
  end
end