Class: Fog::Compute::QingCloud::Router
- Inherits:
-
QingCloud::Model
- Object
- Model
- QingCloud::Model
- Fog::Compute::QingCloud::Router
- Defined in:
- lib/fog/qingcloud/models/compute/router.rb
Instance Method Summary collapse
- #add_dhcp_rule(server_id, dhcp_options, auto_apply = true) ⇒ Object
- #add_gre_rule(gre_options, auto_apply = true) ⇒ Object
- #add_port_forward_rule(src_port, dst_ip, dst_port, protocol, auto_apply = true) ⇒ Object
- #add_rules(rules, auto_apply = true) ⇒ Object (also: #add_rule, #add_statics, #add_static)
- #add_vpn_rule(type, port, protocol, cidr, auto_apply = true) ⇒ Object
- #delete_rules(rule_id) ⇒ Object (also: #delete_rule, #delete_statics, #delete_static)
- #destroy ⇒ Object
- #eip ⇒ Object (also: #address)
- #eip=(ip) ⇒ Object (also: #address=)
- #get_rule(rule_id) ⇒ Object (also: #get_static)
-
#initialize(attributes = {}) ⇒ Router
constructor
A new instance of Router.
- #poweroff ⇒ Object (also: #stop)
- #poweron ⇒ Object (also: #start)
- #ready? ⇒ Boolean
- #rules(rule_ids = [], type = nil) ⇒ Object (also: #statics)
- #save ⇒ Object
-
#security_group ⇒ Object
Return an object of the security group attached to this router.
- #security_group=(sg_id) ⇒ Object
Methods inherited from QingCloud::Model
Constructor Details
#initialize(attributes = {}) ⇒ Router
Returns a new instance of Router.
24 25 26 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 24 def initialize(attributes = {}) super end |
Instance Method Details
#add_dhcp_rule(server_id, dhcp_options, auto_apply = true) ⇒ Object
156 157 158 159 160 161 162 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 156 def add_dhcp_rule(server_id, , auto_apply = true) rule = DHCPRule.new( server_id: server_id, dhcp_options: ) add_rules(rule, auto_apply) end |
#add_gre_rule(gre_options, auto_apply = true) ⇒ Object
164 165 166 167 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 164 def add_gre_rule(, auto_apply = true) rule = GRERule.new(gre_options: ) add_rules(rule, auto_apply) end |
#add_port_forward_rule(src_port, dst_ip, dst_port, protocol, auto_apply = true) ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 136 def add_port_forward_rule(src_port, dst_ip, dst_port, protocol, auto_apply = true) rule = PortForwardRule.new( src_port: src_port, dst_ip: dst_ip, dst_port: dst_port, protocol: protocol ) add_rules(rule, auto_apply) end |
#add_rules(rules, auto_apply = true) ⇒ Object Also known as: add_rule, add_statics, add_static
125 126 127 128 129 130 131 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 125 def add_rules(rules, auto_apply = true) requires :id service.add_router_statics(id, RouterRule.to_query([*rules])) service.update_routers(id) if auto_apply wait_for {ready?} true end |
#add_vpn_rule(type, port, protocol, cidr, auto_apply = true) ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 146 def add_vpn_rule(type, port, protocol, cidr, auto_apply = true) rule = VPNRule.new( vpn_type: type, vpn_port: port, vpn_protocol: protocol, vpn_cidr_block: cidr ) add_rules(rule, auto_apply) end |
#delete_rules(rule_id) ⇒ Object Also known as: delete_rule, delete_statics, delete_static
169 170 171 172 173 174 175 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 169 def delete_rules(rule_id) requires :id service.delete_router_statics([*rule_id]) service.update_routers(id) wait_for {ready?} true end |
#destroy ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 38 def destroy requires :id service.delete_routers(id) true rescue Fog::QingCloud::Errors::PermissionDenied => e raise e unless e. =~ /has already been deleted/i true end |
#eip ⇒ Object Also known as: address
72 73 74 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 72 def eip service.addresses.get(address_id) end |
#eip=(ip) ⇒ Object Also known as: address=
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 51 def eip=(ip) raise Fog::Errors::Error, "Unsupported eip parameter for creating routers" unless persisted? if ip =~ /^[0-9]{1,3}\..+/ ip_str = ip ip_id = service.addresses.get(ip).id elsif ip.respond_to? :id ip_str = ip.public_ip ip_id = ip.id elsif ip && ip != '' ip_obj = service.addresses.get(ip) ip_str = ip_obj.public_ip ip_id = ip_obj.id else ip_str = ip_id = nil end service.modify_router_attributes(id, 'eip' => ip_id) service.update_routers(id) merge_attributes('public_ip' => ip_str, 'address_id' => ip_id) true end |
#get_rule(rule_id) ⇒ Object Also known as: get_static
120 121 122 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 120 def get_rule(rule_id) rules(rule_id).first end |
#poweroff ⇒ Object Also known as: stop
93 94 95 96 97 98 99 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 93 def poweroff if persisted? service.routers_power(id, 'off') wait_for {status == 'poweroffed'} end true end |
#poweron ⇒ Object Also known as: start
102 103 104 105 106 107 108 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 102 def poweron if persisted? service.routers_power(id, 'on') wait_for {ready?} end true end |
#ready? ⇒ Boolean
47 48 49 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 47 def ready? status == 'active' and transition_status == '' end |
#rules(rule_ids = [], type = nil) ⇒ Object Also known as: statics
111 112 113 114 115 116 117 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 111 def rules(rule_ids = [], type = nil) requires :id json = service.describe_router_statics(id, rule_ids, type).body['router_static_set'] json.inject([]) do |ret, o| ret << RouterRule.convert_type(o['static_type']).new(o) end end |
#save ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 28 def save if persisted? modify_attributes(name, description) else self.id = service.create_routers(name, 1, security_group_id).body['routers'].first wait_for {ready?} end true end |
#security_group ⇒ Object
Return an object of the security group attached to this router.
88 89 90 91 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 88 def security_group requires :id service.security_groups.get(security_group_id) end |
#security_group=(sg_id) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/fog/qingcloud/models/compute/router.rb', line 79 def security_group=(sg_id) if persisted? service.modify_router_attributes(id, 'security_group' => sg_id) service.apply_security_group(sg_id) end merge_attributes('security_group_id' => sg_id) end |