Class: HP::Cloud::RuleHelper

Inherits:
BaseHelper show all
Defined in:
lib/hpcloud/rule_helper.rb

Instance Attribute Summary collapse

Attributes inherited from BaseHelper

#connection, #cstatus, #fog

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseHelper

#is_valid?, #set_error, #to_hash

Constructor Details

#initialize(connection, security_group, foggy = nil) ⇒ RuleHelper

Returns a new instance of RuleHelper.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/hpcloud/rule_helper.rb', line 32

def initialize(connection, security_group, foggy = nil)
  super(connection, foggy)
  @security_group = security_group
  return if foggy.nil?
  @id = foggy['id']
  @name = foggy['remote_group_id']
  @source = @name
  @protocol = foggy['protocol']
  @direction = foggy['direction']
  @cidr = foggy['remote_ip_prefix']
  @tenant_id = foggy['tenant_id']
  @type = foggy['ethertype']
  @from = foggy['port_range_min']
  @to = foggy['port_range_max']
end

Instance Attribute Details

#cidrObject

Returns the value of attribute cidr.



26
27
28
# File 'lib/hpcloud/rule_helper.rb', line 26

def cidr
  @cidr
end

#directionObject

Returns the value of attribute direction.



26
27
28
# File 'lib/hpcloud/rule_helper.rb', line 26

def direction
  @direction
end

#fromObject

Returns the value of attribute from.



25
26
27
# File 'lib/hpcloud/rule_helper.rb', line 25

def from
  @from
end

#idObject

Returns the value of attribute id.



25
26
27
# File 'lib/hpcloud/rule_helper.rb', line 25

def id
  @id
end

#nameObject

Returns the value of attribute name.



25
26
27
# File 'lib/hpcloud/rule_helper.rb', line 25

def name
  @name
end

#protocolObject

Returns the value of attribute protocol.



25
26
27
# File 'lib/hpcloud/rule_helper.rb', line 25

def protocol
  @protocol
end

#sourceObject

Returns the value of attribute source.



25
26
27
# File 'lib/hpcloud/rule_helper.rb', line 25

def source
  @source
end

#tenant_idObject

Returns the value of attribute tenant_id.



26
27
28
# File 'lib/hpcloud/rule_helper.rb', line 26

def tenant_id
  @tenant_id
end

#toObject

Returns the value of attribute to.



25
26
27
# File 'lib/hpcloud/rule_helper.rb', line 25

def to
  @to
end

#typeObject

Returns the value of attribute type.



26
27
28
# File 'lib/hpcloud/rule_helper.rb', line 26

def type
  @type
end

Class Method Details

.get_keysObject



28
29
30
# File 'lib/hpcloud/rule_helper.rb', line 28

def self.get_keys()
  return [ "id", "source", "type", "protocol", "direction", "cidr", "from", "to" ]
end

Instance Method Details

#destroyObject



65
66
67
# File 'lib/hpcloud/rule_helper.rb', line 65

def destroy
  @fog.destroy
end

#saveObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/hpcloud/rule_helper.rb', line 48

def save
  return false if is_valid? == false
  if @fog.nil?
    port_range = @from.to_s + ".." + @to.to_s
    response = @security_group.fog.create_rule(port_range, @protocol, @name)
    if response.nil?
      set_error("Error creating rule")
      return false
    end
    @fog = response.body["security_group_rule"]
    @id = @fog['id']
    return true
  else
    raise "Update not implemented"
  end
end