def _parse_service_xml(self, xml): """parse the xml into actual objects and store them in the dicts""" for elm in xml: obj = objects.ServiceObject() obj.refresh(xml=elm) self.service_objects[obj.name] = obj
def create_object(**kwargs): if kwargs["addressobject"]: newobject = objects.AddressObject( name=kwargs["addressobject"], value=kwargs["address"], type=kwargs["address_type"], description=kwargs["description"], tag=kwargs["tag_name"], ) if newobject.type and newobject.value: return newobject else: return False elif kwargs["addressgroup"]: newobject = objects.AddressGroup( name=kwargs["addressgroup"], static_value=kwargs["static_value"], dynamic_value=kwargs["dynamic_value"], description=kwargs["description"], tag=kwargs["tag_name"], ) if newobject.static_value or newobject.dynamic_value: return newobject else: return False elif kwargs["serviceobject"]: newobject = objects.ServiceObject( name=kwargs["serviceobject"], protocol=kwargs["protocol"], source_port=kwargs["source_port"], destination_port=kwargs["destination_port"], tag=kwargs["tag_name"], ) if newobject.protocol and newobject.destination_port: return newobject else: return False elif kwargs["servicegroup"]: newobject = objects.ServiceGroup( name=kwargs["servicegroup"], value=kwargs["services"], tag=kwargs["tag_name"], ) if newobject.value: return newobject else: return False elif kwargs["tag_name"]: t = objects.Tag c = t.color_code(kwargs["color"]) newobject = objects.Tag(name=kwargs["tag_name"], color=c, comments=kwargs["description"]) if newobject.name: return newobject else: return False else: return False
def setup_state_obj(self, dev, state): state.obj = objects.ServiceObject( testlib.random_name(), protocol="tcp", source_port="1025-65535", destination_port="80,443,8080", description="My service object", ) dev.add(state.obj)
def create_object(**kwargs): if kwargs['addressobject']: newobject = objects.AddressObject(name=kwargs['addressobject'], value=kwargs['address'], type=kwargs['address_type'], description=kwargs['description'], tag=kwargs['tag_name']) if newobject.type and newobject.value: return newobject else: return False elif kwargs['addressgroup']: newobject = objects.AddressGroup(name=kwargs['addressgroup'], static_value=kwargs['static_value'], dynamic_value=kwargs['dynamic_value'], description=kwargs['description'], tag=kwargs['tag_name']) if newobject.static_value or newobject.dynamic_value: return newobject else: return False elif kwargs['serviceobject']: newobject = objects.ServiceObject( name=kwargs['serviceobject'], protocol=kwargs['protocol'], source_port=kwargs['source_port'], destination_port=kwargs['destination_port'], tag=kwargs['tag_name']) if newobject.protocol and newobject.destination_port: return newobject else: return False elif kwargs['servicegroup']: newobject = objects.ServiceGroup(name=kwargs['servicegroup'], value=kwargs['services'], tag=kwargs['tag_name']) if newobject.value: return newobject else: return False elif kwargs['tag_name']: t = objects.Tag c = t.color_code(kwargs['color']) newobject = objects.Tag(name=kwargs['tag_name'], color=c, comments=kwargs['description']) if newobject.name: return newobject else: return False else: return False
def create_dependencies(self, dev, state): state.tag = None state.services = [ objects.ServiceObject( testlib.random_name(), "tcp" if x % 2 == 0 else "udp", destination_port=2000 + x, description="Service {0}".format(x), ) for x in range(4) ] for x in state.services: dev.add(x) x.create() state.tag = objects.Tag(testlib.random_name(), "color5") dev.add(state.tag) state.tag.create()