Class: OpenStack::Network::QoSPolicy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, qos_hash = {}) ⇒ QoSPolicy

Returns a new instance of QoSPolicy.



12
13
14
15
# File 'lib/openstack/network/qos_policy.rb', line 12

def initialize(connection, qos_hash={})
  @connection = connection
  populate(qos_hash)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



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

def connection
  @connection
end

#descriptionObject (readonly)

Returns the value of attribute description.



9
10
11
# File 'lib/openstack/network/qos_policy.rb', line 9

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#sharedObject (readonly)

Returns the value of attribute shared.



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

def shared
  @shared
end

#tenant_idObject (readonly)

Returns the value of attribute tenant_id.



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

def tenant_id
  @tenant_id
end

Instance Method Details

#add_port_id(port_id) ⇒ Object



64
65
66
67
68
69
# File 'lib/openstack/network/qos_policy.rb', line 64

def add_port_id(port_id)
    data = JSON.generate(:port => {:qos_policy_id => @id})
    response = @connection.req("PUT", "/ports/#{port_id}", {:data => data})
    OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
    true
end

#create_bandwidth_limit_rule(options) ⇒ Object



57
58
59
60
61
62
# File 'lib/openstack/network/qos_policy.rb', line 57

def create_bandwidth_limit_rule(options)
  data = JSON.generate(:bandwidth_limit_rule => options)
  response = @connection.req("POST", "/qos/policies/#{@id}/bandwidth_limit_rules", {:data => data})
  OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
  OpenStack::Network::QoSBandwidthLimitRule.new(self, JSON.parse(response.body)["bandwidth_limit_rule"])
end

#delete!Object



31
32
33
34
35
# File 'lib/openstack/network/qos_policy.rb', line 31

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

#get_bandwidth_limit_rule(rule_id) ⇒ Object



51
52
53
54
55
# File 'lib/openstack/network/qos_policy.rb', line 51

def get_bandwidth_limit_rule(rule_id)
  response = @connection.req("GET", "/qos/policies/#{@id}/bandwidth_limit_rules/#{rule_id}")
  OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
  OpenStack::Network::QoSBandwidthLimitRule.new(self, JSON.parse(response.body)["bandwidth_limit_rule"])
end

#get_bandwidth_limit_rulesObject



44
45
46
47
48
49
# File 'lib/openstack/network/qos_policy.rb', line 44

def get_bandwidth_limit_rules
  response = @connection.req("GET", "/qos/policies/#{@id}/bandwidth_limit_rules")
  OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
  rules_hash = JSON.parse(response.body)["bandwidth_limit_rules"]
  rules_hash.inject([]){|res, current| res << OpenStack::Network::QoSBandwidthLimitRule.new(self, current); res}
end

#populate(qos_hash = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/openstack/network/qos_policy.rb', line 17

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

  @id = qos_hash["id"]
  @tenant_id = qos_hash["tenant_id"]
  @name = qos_hash["name"]
  @description = qos_hash["description"]
  @shared = qos_hash["shared"]
end

#remove_port_id(port_id) ⇒ Object



71
72
73
74
75
76
# File 'lib/openstack/network/qos_policy.rb', line 71

def remove_port_id(port_id)
  data = JSON.generate(:port => {:qos_policy_id => nil})
  response = @connection.req("PUT", "/ports/#{port_id}", {:data => data})
  OpenStack::Exception.raise_exception(response) unless response.code.match(/^20.$/)
  true
end

#update(options) ⇒ Object



37
38
39
40
41
42
# File 'lib/openstack/network/qos_policy.rb', line 37

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