Class: OpenStack::Network::QoSBandwidthLimitRule

Inherits:
Object
  • Object
show all
Defined in:
lib/openstack/network/qos_bandwidth_limit_rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(policy, rule_hash = {}) ⇒ QoSBandwidthLimitRule

Returns a new instance of QoSBandwidthLimitRule.



10
11
12
13
# File 'lib/openstack/network/qos_bandwidth_limit_rule.rb', line 10

def initialize(policy, rule_hash={})
  @policy = policy
  populate(rule_hash)
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/openstack/network/qos_bandwidth_limit_rule.rb', line 5

def id
  @id
end

#max_burst_kbpsObject (readonly)

Returns the value of attribute max_burst_kbps.



8
9
10
# File 'lib/openstack/network/qos_bandwidth_limit_rule.rb', line 8

def max_burst_kbps
  @max_burst_kbps
end

#max_kbpsObject (readonly)

Returns the value of attribute max_kbps.



7
8
9
# File 'lib/openstack/network/qos_bandwidth_limit_rule.rb', line 7

def max_kbps
  @max_kbps
end

#policy_idObject (readonly)

Returns the value of attribute policy_id.



6
7
8
# File 'lib/openstack/network/qos_bandwidth_limit_rule.rb', line 6

def policy_id
  @policy_id
end

Instance Method Details

#delete!Object



28
29
30
31
32
# File 'lib/openstack/network/qos_bandwidth_limit_rule.rb', line 28

def delete!
  response = @policy.connection.req('DELETE', "/qos/policies/#{@policy_id}/bandwidth_limit_rules/#{@id}")
  OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
  true
end

#populate(rule_hash = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/openstack/network/qos_bandwidth_limit_rule.rb', line 15

def populate(rule_hash=nil)
  if @id and not rule_hash
    response = @policy.connection.req("GET", "/qos/policies/#{@policy_id}/bandwidth_limit_rules/#{@id}")
    OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
    rule_hash = JSON.parse(response.body)["bandwidth_limit_rule"]
  end

  @id = rule_hash["id"]
  @policy_id = rule_hash["policy_id"] || @policy.id
  @max_kbps = rule_hash["max_kbps"]
  @max_burst_kbps = rule_hash["max_burst_kbps"]
end

#update(options) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/openstack/network/qos_bandwidth_limit_rule.rb', line 34

def update(options)
  data = JSON.generate(:bandwidth_limit_rule => options)
  response = @policy.connection.req("PUT", "/qos/policies/#{@policy_id}/bandwidth_limit_rules/#{@id}", {:data => data})
  OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
  populate(JSON.parse(response.body)["bandwidth_limit_rule"])
  true
end