Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
 def setup_state_obj(self, dev, state):
     state.obj = objects.AddressGroup(
         testlib.random_name(),
         dynamic_value="'{0}' or '{1}'".format(state.tags[0].name,
                                               state.tags[1].name),
         description="This is my description",
         tag=state.tags[2].name,
     )
     dev.add(state.obj)
Ejemplo n.º 3
0
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))
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
def create_address_group_object(**kwargs):
    """
    Create an Address object

    @return False or ```objects.AddressObject```
    """
    ad_object = objects.AddressGroup(name=kwargs['address_gp_name'],
                                     dynamic_value=kwargs['dynamic_value'],
                                     description=kwargs['description'],
                                     tag=kwargs['tag_name'])
    if ad_object.static_value or ad_object.dynamic_value:
        return ad_object
    else:
        return None
Ejemplo n.º 6
0
# Add IPSEC Tunnel to FW ##############################################################
fw.extend(ipsec_tunnels_arr)
ipsec_tunnels_arr[0].create_similar()

print("12. Saved IPSEC tunnels")

# Add Addresses and Address groups ####################################################
fw.extend(address_objs_arr)
# this is bulk upload to PAN
address_objs_arr[0].create_similar()

print("13. Saved Address objects")

# get the groups
address_group = objects.AddressGroup(name=settings['address_group']['name'])
address_group = address_group.refreshall(fw)

for group in address_group:
    if group.name == settings['address_group']['name']:
        print("12.1. adding address to group")
        # will need for loop to bulk add Addresses
        for address in address_objs_arr:
            group.static_value.append(address.name)
        fw.add(group)
        group.create()

print("14. Saved Address groups")

# add the static router to the VirtualRouter #########################################
Ejemplo n.º 7
0
 def setup_state_obj(self, dev, state):
     state.obj = objects.AddressGroup(
         testlib.random_name(),
         [x.name for x in state.aos[:2]],
     )
     dev.add(state.obj)