Class: Ec2SecurityGroup

Inherits:
Object
  • Object
show all
Extended by:
RightScale::Api::BaseExtend
Includes:
RightScale::Api::Base
Defined in:
lib/rest_connection/rightscale/ec2_security_group.rb

Overview

API 1.0

Constant Summary collapse

VALID_RULE_TYPES =
[
  [:group, :owner],
  [:cidr_ips, :from_port, :protocol, :to_port],
  [:from_port, :group, :owner, :protocol, :to_port],
]

Instance Attribute Summary

Attributes included from RightScale::Api::Base

#params

Instance Method Summary collapse

Methods included from RightScale::Api::BaseExtend

[], create, deny_methods, filters, find, find_all, find_by, find_by_cloud_id, find_by_id, find_by_nickname, find_by_nickname_speed, find_with_filter, resource_plural_name, resource_singular_name

Methods included from RightScale::Api::BaseConnection

#connection

Methods included from RightScale::Api::Base

#[], #[]=, #destroy, #initialize, #method_missing, #reload, #resource_plural_name, #resource_singular_name, #rs_id, #save

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RightScale::Api::Base

Instance Method Details

#add_rule(opts = {}) ⇒ Object

NOTE - Create, Destroy, and Update require “security_manager” permissions NOTE - Can’t remove rules, can only add



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/rest_connection/rightscale/ec2_security_group.rb', line 39

def add_rule(opts={})
  rule = {}
  opts.each { |k,v| rule["#{k}".to_sym] = v }    

  unless validate_rule(rule)
    raise ArgumentError.new("add_rule expects one of these valid rule types: #{VALID_RULE_TYPES.to_json}")
  end

  params = {:ec2_security_group => rule}
  uri = URI.parse(self.href)
  connection.put(uri.path, params)

  self.reload
end

#validate_rule(rule) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/rest_connection/rightscale/ec2_security_group.rb', line 54

def validate_rule(rule)
  VALID_RULE_TYPES.each do |valid_rule_type|
    if rule.keys.sort_by {|sym| sym.to_s} == valid_rule_type.sort_by {|sym| sym.to_s}
      return true
    end
  end

  false
end