Class: Fog::Compute::QingCloud::RouterRule

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/qingcloud/models/compute/router_rules.rb

Direct Known Subclasses

DHCPRule, GRERule, PortForwardRule, VPNRule

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ RouterRule

Returns a new instance of RouterRule.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fog/qingcloud/models/compute/router_rules.rb', line 10

def initialize(opts = {})
  @params = []
  opts.keys.each do |k| 
    if respond_to?("#{k}=".to_sym)
      send("#{k}=".to_sym, opts[k])
    else
      instance_variable_set("@#{k}".to_sym, opts[k])
    end
  end
  @static_type = self.class.const_get('TYPE')
end

Instance Attribute Details

#create_timeObject (readonly)

Returns the value of attribute create_time.



6
7
8
# File 'lib/fog/qingcloud/models/compute/router_rules.rb', line 6

def create_time
  @create_time
end

#router_static_idObject (readonly) Also known as: id

Returns the value of attribute router_static_id.



6
7
8
# File 'lib/fog/qingcloud/models/compute/router_rules.rb', line 6

def router_static_id
  @router_static_id
end

#static_typeObject (readonly) Also known as: type

Returns the value of attribute static_type.



6
7
8
# File 'lib/fog/qingcloud/models/compute/router_rules.rb', line 6

def static_type
  @static_type
end

#vxnet_idObject (readonly)

Returns the value of attribute vxnet_id.



6
7
8
# File 'lib/fog/qingcloud/models/compute/router_rules.rb', line 6

def vxnet_id
  @vxnet_id
end

Class Method Details

.bind_param(req_key, alias_key) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/fog/qingcloud/models/compute/router_rules.rb', line 22

def self.bind_param(req_key, alias_key)
  [req_key, alias_key].each do |x|
    class_eval <<-EOS, __FILE__, __LINE__
      def #{x}
        param = @params.find {|x| x.req_key == "#{req_key}" or x.alias_key == "#{alias_key}"}
        val = param.val if param
        val
      end

      def #{x}=(v)
        param = @params.find {|x| x.req_key == "#{req_key}" or x.alias_key == "#{alias_key}"}
        unless param
          param = OpenStruct.new({req_key: "#{req_key}", alias_key: "#{alias_key}", val: nil})
          @params << param
        end
        param.val = v
      end
    EOS
  end
end

.convert_type(t) ⇒ Object



53
54
55
# File 'lib/fog/qingcloud/models/compute/router_rules.rb', line 53

def self.convert_type(t)
  [PortForwardRule, VPNRule, DHCPRule, GRERule][t - 1]
end

.to_query(rules) ⇒ Object



57
58
59
60
# File 'lib/fog/qingcloud/models/compute/router_rules.rb', line 57

def self.to_query(rules)
  rules.compact!
  (1..rules.length).inject({}) {|ret, i| ret.merge rules[i - 1].to_h(i)}
end

Instance Method Details

#to_h(i) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/fog/qingcloud/models/compute/router_rules.rb', line 43

def to_h(i)
  @params.inject({}) do |x, o|
    if o.val
      x["statics.#{i}.#{o.req_key}"] = o.val if o.val
      x["statics.#{i}.static_type"]  = type
    end
    x
  end
end