def to_xml(self): """Map address objects to juniper SRX config tree elements """ address_element = create_element('address') create_element('name', text=self.name, parent=address_element) if self.a_type == BaseAddress.AddressTypes.IPv4: # ipv4 create_element('ip-prefix', text=self.value, parent=address_element) elif self.a_type == BaseAddress.AddressTypes.DNS: # dns dns_element = create_element('dns-name', parent=address_element) create_element('name', text=self.value, parent=dns_element) return address_element
def map(self): """Map service group objects to juniper SRX config tree elements """ servicegroup_element = create_element('application-set') create_element('name', text=self.name, parent=servicegroup_element) for service in self.elements: service_element = create_element('application', parent=servicegroup_element) create_element('name', text=service.name, parent=service_element) return servicegroup_element
def to_xml(self): """Map address group objects to juniper SRX config tree elements """ addressgroup_element = create_element('address-set') create_element('name', text=self.name, parent=addressgroup_element) for a in self.elements: if isinstance(a, BaseAddress): address_element = create_element('address', parent=addressgroup_element) else: address_element = create_element('address-set', parent=addressgroup_element) create_element('name', text=a.name, parent=address_element) return addressgroup_element
def map_destination_port(port): if isinstance(port, BasePortRange): port = port.value return create_element('destination-port', text=port)
def to_xml(self): """Map service objects to juniper SRX config tree elements """ def map_destination_port(port): if isinstance(port, BasePortRange): port = port.value return create_element('destination-port', text=port) service_element = create_element('application') create_element('name', text=self.name, parent=service_element) if len(self.terms) > 0: # termed based service for term in self.terms: term_element = create_element('term', parent=service_element) term_element.append(map_destination_port(term.port)) create_element('source-port', text='0-65535', parent=term_element) create_element('protocol', text=term.protocol, parent=term_element) create_element('name', text=term.name, parent=term_element) else: service_element.append(map_destination_port(self.port)) create_element('source-port', text='0-65535', parent=service_element) create_element('protocol', text=self.protocol, parent=service_element) return service_element
def to_xml(self): """Map Juniper SRX Policy Object into xml config element """ policy_element = create_element('policy') create_element('name', text=self.name, parent=policy_element) match_element = create_element('match', parent=policy_element) for s in self.src_addresses: create_element('source-address', text=s.name, parent=match_element) for d in self.dst_addresses: create_element('destination-address', text=d.name, parent=match_element) then_element = create_element('then', parent=policy_element) create_element(JuniperSRXPolicy.ActionMap[self.action], parent=then_element) log_element = create_element('log', parent=then_element) for log_type in self.logging: create_element(JuniperSRXPolicy.LoggingMap[log_type], parent=log_element) return policy_element