@@ -79,11 +79,15 @@ def add_securitygroup_rule(self, group_id, remote_ip=None,
7979 :param int port_min: The lower port bound to enforce
8080 :param str protocol: The protocol to enforce (icmp, udp, tcp)
8181 """
82- rule = {'direction' : direction ,
83- 'ethertype' : ethertype ,
84- 'portRangeMax' : port_max ,
85- 'portRangeMin' : port_min ,
86- 'protocol' : protocol }
82+ rule = {'direction' : direction }
83+ if ethertype is not None :
84+ rule ['ethertype' ] = ethertype
85+ if port_max is not None :
86+ rule ['portRangeMax' ] = port_max
87+ if port_min is not None :
88+ rule ['portRangeMin' ] = port_min
89+ if protocol is not None :
90+ rule ['protocol' ] = protocol
8791 if remote_ip is not None :
8892 rule ['remoteIp' ] = remote_ip
8993 if remote_group is not None :
@@ -228,23 +232,24 @@ def delete_securitygroup(self, group_id):
228232 :param int group_id: The ID of the security group
229233 """
230234 delete_dict = {'id' : group_id }
231- self .security_group .deleteObjects ([delete_dict ])
235+ return self .security_group .deleteObjects ([delete_dict ])
232236
233237 def detach_securitygroup_component (self , group_id , component_id ):
234238 """Detaches a network component from a security group.
235239
236240 :param int group_id: The ID of the security group
237241 :param int component_id: The ID of the component to detach
238242 """
239- self .detach_securitygroup_components (group_id , [component_id ])
243+ return self .detach_securitygroup_components (group_id , [component_id ])
240244
241245 def detach_securitygroup_components (self , group_id , component_ids ):
242246 """Detaches network components from a security group.
243247
244248 :param int group_id: The ID of the security group
245249 :param list component_ids: The IDs of the network components to detach
246250 """
247- self .security_group .detachNetworkComponents (component_ids , id = group_id )
251+ return self .security_group .detachNetworkComponents (component_ids ,
252+ id = group_id )
248253
249254 def edit_rwhois (self , abuse_email = None , address1 = None , address2 = None ,
250255 city = None , company_name = None , country = None ,
@@ -281,6 +286,7 @@ def edit_securitygroup(self, group_id, name=None, description=None):
281286 :param string name: The name of the security group
282287 :param string description: The description of the security group
283288 """
289+ successful = False
284290 obj = {}
285291 if name :
286292 obj ['name' ] = name
@@ -289,9 +295,9 @@ def edit_securitygroup(self, group_id, name=None, description=None):
289295
290296 if obj :
291297 obj ['id' ] = group_id
292- self .security_group .editObjects ([obj ])
298+ successful = self .security_group .editObjects ([obj ])
293299
294- return bool ( name or description )
300+ return successful
295301
296302 def edit_securitygroup_rule (self , group_id , rule_id , remote_ip = None ,
297303 remote_group = None , direction = None ,
@@ -310,6 +316,7 @@ def edit_securitygroup_rule(self, group_id, rule_id, remote_ip=None,
310316 :param str port_range_min: The lower port bound to enforce
311317 :param str protocol: The protocol to enforce (icmp, udp, tcp)
312318 """
319+ successful = False
313320 obj = {}
314321 if remote_ip :
315322 obj ['remoteIp' ] = remote_ip
@@ -328,10 +335,9 @@ def edit_securitygroup_rule(self, group_id, rule_id, remote_ip=None,
328335
329336 if obj :
330337 obj ['id' ] = rule_id
331- self .security_group .editRules ([obj ], id = group_id )
338+ successful = self .security_group .editRules ([obj ], id = group_id )
332339
333- return bool (remote_ip or remote_group or direction or ethertype
334- or port_range_max or port_range_min or protocol )
340+ return successful
335341
336342 def ip_lookup (self , ip_address ):
337343 """Looks up an IP address and returns network information about it.
@@ -524,15 +530,15 @@ def remove_securitygroup_rule(self, group_id, rule_id):
524530 :param int group_id: The ID of the security group
525531 :param int rule_id: The ID of the rule to remove
526532 """
527- self .remove_securitygroup_rules (group_id , [rule_id ])
533+ return self .remove_securitygroup_rules (group_id , [rule_id ])
528534
529535 def remove_securitygroup_rules (self , group_id , rules ):
530536 """Remove rules from a security group.
531537
532538 :param int group_id: The ID of the security group
533539 :param list rules: The list of IDs to remove
534540 """
535- self .security_group .removeRules (rules , id = group_id )
541+ return self .security_group .removeRules (rules , id = group_id )
536542
537543 def resolve_global_ip_ids (self , identifier ):
538544 """Resolve global ip ids."""
0 commit comments