Class: Standup::EC2::SecurityGroup

Inherits:
Base
  • Object
show all
Defined in:
lib/standup/ec2/security_group.rb

Defined Under Namespace

Classes: IPRule

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#exists?, info_reader

Constructor Details

#initialize(name, info = false) ⇒ SecurityGroup

Returns a new instance of SecurityGroup.



6
7
8
9
# File 'lib/standup/ec2/security_group.rb', line 6

def initialize name, info = false
  @name = name
  super info
end

Class Method Details

.create(name, description = name) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/standup/ec2/security_group.rb', line 24

def self.create name, description = name
  api.create_security_group :group_name => name,
                            :group_description => description
  list[name] = SecurityGroup.new name,
                                 :description => description,
                                 :rules => []
end

.list(reload = false) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/standup/ec2/security_group.rb', line 13

def self.list reload = false
  if !class_variable_defined?(:@@list) || reload
    @@list = {}
    result = api.describe_security_groups
    result.securityGroupInfo.item.each do |gitem|
      @@list[gitem.groupName] = new gitem.groupName, build_info(gitem)
    end if result.securityGroupInfo
  end
  @@list
end

Instance Method Details

#add_rule(rule) ⇒ Object



37
38
39
40
# File 'lib/standup/ec2/security_group.rb', line 37

def add_rule rule
  api.authorize_security_group_ingress build_rules_opts(rule)
  rules << rule
end

#deleteObject



32
33
34
35
# File 'lib/standup/ec2/security_group.rb', line 32

def delete
  api.delete_security_group :group_name => @name
  list.delete @name
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/standup/ec2/security_group.rb', line 56

def eql? other
  @name == other.name
end

#hashObject



52
53
54
# File 'lib/standup/ec2/security_group.rb', line 52

def hash
  @name.hash
end

#load_infoObject



47
48
49
50
# File 'lib/standup/ec2/security_group.rb', line 47

def load_info
  result = api.describe_security_groups :group_name => [@name]
  set_info self.class.build_info(result.securityGroupInfo.item[0])
end

#remove_rule(rule) ⇒ Object



42
43
44
45
# File 'lib/standup/ec2/security_group.rb', line 42

def remove_rule rule
  api.revoke_security_group_ingress build_rules_opts(rule)
  rules.delete rule
end