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.AddressObject( testlib.random_name(), value=testlib.random_ip(), type="ip-netmask", description="This is a test", ) dev.add(state.obj)
def create_dependencies(self, dev, state): state.aos = [ objects.AddressObject(testlib.random_name(), testlib.random_ip()) for x in range(4) ] for x in state.aos: dev.add(x) x.create()
def test_device_group_xpath_unchanged(): expected = "/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='somegroup']/address/entry[@name='intnet']" pano = panorama.Panorama("127.0.0.1") dg = panorama.DeviceGroup("somegroup") ao = objects.AddressObject("intnet", "192.168.0.0/16") pano.add(dg) dg.add(ao) assert expected == ao.xpath()
def parseSubnets(data, panoAddress): print('Detected json as subnets, parsing') pano = connect(panoAddress) addresses = [] for d in data: print(d['Subnet']) AddressName = '8x8-' + d['Subnet'].replace('/', '-') print(AddressName) address_object = objects.AddressObject(AddressName, d['Subnet']) pano.add(address_object).create() addresses.append(address_object) pano.add(objects.AddressGroup('8x8 Addresses', addresses))
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
network.IpsecTunnel(name=row['ipsec_tunnel_name'], tunnel_interface=row['tunnel_name'], type=settings['ipsec_tunnel']['type'], ak_ike_gateway=row['ike_gateway_name'], ak_ipsec_crypto_profile=settings['ipsec_tunnel']['ak_ipsec_crypto_profile'], enable_tunnel_monitor=settings['ipsec_tunnel']['enable_tunnel_monitor']) ) print("4. Created IPSEC Tunnel for {}".format(row['hostname'])) #################################################################################################################### # Network Objects address_objs_arr.append( objects.AddressObject(name=row['object_name'], value=row['subnet'], type=settings['address_object']['type'], description=row['object_description']) ) print("5. added network object for {}".format(row['hostname'])) #################################################################################################################### # Static Routes # Pull the Default_vRouter config from the router. This returns a list... # This will need to be modified if you have more than one router. vr = vr.refreshall(fw) vr = vr[0] static_route_arr.append( network.StaticRoute(name=row['object_name'],