avoid as much as possible accessing logger through class instances, whenever that...
[sfa.git] / sfa / rspecs / elements / versions / plosv1FWRule.py
index 974fc3d..e62a34f 100644 (file)
@@ -1,24 +1,26 @@
-from sfa.rspecs.elements.element import Element  
+from sfa.rspecs.elements.element import Element
 from sfa.rspecs.elements.fw_rule import FWRule
 
+
 class PLOSv1FWRule:
+
     @staticmethod
     def add_rules(xml, rules):
         if not rules:
-            return 
+            return
         for rule in rules:
-            rule_elem = xml.add_element('plos:fw_rule')
+            rule_elem = xml.add_element('{%s}fw_rule' % xml.namespaces['plos'])
             rule_elem.set('protocol', rule.get('protocol'))
             rule_elem.set('port_range', rule.get('port_range'))
             rule_elem.set('cidr_ip', rule.get('cidr_ip'))
-            rule_elem.set('icmp_type_code', rule.get('icmp_type_code'))
-              
+            if rule.get('icmp_type_code'):
+                rule_elem.set('icmp_type_code', rule.get('icmp_type_code'))
+
     @staticmethod
     def get_rules(xml):
         rules = []
-        if 'plos' in xml.namespaces: 
+        if 'plos' in xml.namespaces:
             for rule_elem in xml.xpath('./plos:fw_rule | ./fw_rule'):
                 rule = FWRule(rule_elem.attrib, rule_elem)
-                rules.append(rule)  
+                rules.append(rule)
         return rules
-