예제 #1
0
def CreateRedSubnetv6(vlanid, description):
    config = ConfigParser()
    config.read('C:/Temp/Git/Fortinet/Fortigate/settings.ini')

    ipamuser = config.get('IPAM', 'ipamuser')
    ipampassword = config.get('IPAM', 'ipampassword')

    ipam = PhpIpamClient(
        url='https://ipam.consinto.com',
        app_id='network',
        username=ipamuser,
        ssl_verify=False,
        password=ipampassword,
        user_agent='myapiclient',  # custom user-agent header
    )

    IPAMv6subnets = ipam.get('/subnets/915/first_subnet/64/')
    v6subnet = IPAMv6subnets.split("/")
    # Das neue Netz wird angelegt
    IPAMvlans = ipam.post('/subnets/915/first_subnet/64/', {
        'description': description,
        'vlanId': vlanid
    })
    # Wir suchen uns die ID des Netzwerks
    searchstring = '/subnets/cidr/' + IPAMv6subnets + '/'
    bluev6Info = ipam.get(searchstring, {
        'filter_by': 'sectionId',
        'filter_value': 2,
    })
    bluev6Info = json.dumps(bluev6Info[0])
    bluev6Info = json.loads(bluev6Info)
    bluev6Id = bluev6Info['id']
    searchstring = '/addresses/first_free/' + bluev6Id + '/'
    IPAMvlans = ipam.post(searchstring, {
        'description': 'NA',
        'hostname': 'NA'
    })
    searchstring = '/addresses/first_free/' + bluev6Id + '/'
    IPAMvlans = ipam.post(
        searchstring, {
            'description': 'AnycastGateway',
            'hostname': 'AnycastGateway',
            'deviceId': 83
        })
    searchstring = '/addresses/first_free/' + bluev6Id + '/'
    IPAMvlans = ipam.post(searchstring, {
        'description': 'Fortigate',
        'hostname': 'Fortigate',
        'deviceId': 84
    })
    return bluev6Id
예제 #2
0
def CreateRedSubnetv4(vlanid, description):
    config = ConfigParser()
    config.read('C:/Temp/Git/Fortinet/Fortigate/settings.ini')

    ipamuser = config.get('IPAM', 'ipamuser')
    ipampassword = config.get('IPAM', 'ipampassword')

    ipam = PhpIpamClient(
        url='https://ipam.consinto.com',
        app_id='network',
        username=ipamuser,
        ssl_verify=False,
        password=ipampassword,
        user_agent='myapiclient',  # custom user-agent header
    )

    IPAMsubnets = ipam.get('/subnets/921/first_subnet/31/')

    subnet = IPAMsubnets.split("/")
    IPAMvlans = ipam.post(
        '/subnets/', {
            'subnet': subnet[0],
            'mask': subnet[1],
            'sectionId': '1',
            'description': description,
            'masterSubnetId': 921,
            'vlanId': vlanid
        })

    searchstring = '/subnets/cidr/' + IPAMsubnets + '/'
    redv4Info = ipam.get(searchstring, {
        'filter_by': 'sectionId',
        'filter_value': 1,
    })
    netid = redv4Info[0]['id']
    searchstring = '/addresses/first_free/' + netid + '/'
    IPAMvlans = ipam.post(
        searchstring, {
            'description': 'AnycastGateway',
            'hostname': 'AnycastGateway',
            'deviceId': 83
        })
    IPAMvlans = ipam.post(searchstring, {
        'description': 'Fortigate',
        'hostname': 'Fortigate',
        'deviceId': 84
    })
    return netid
예제 #3
0
def CreateCustomerSlash56(description):
    config = ConfigParser()
    config.read('C:/Temp/Git/Fortinet/Fortigate/settings.ini')

    ipamuser = config.get('IPAM', 'ipamuser')
    ipampassword = config.get('IPAM', 'ipampassword')

    ipam = PhpIpamClient(
        url='https://ipam.consinto.com',
        app_id='network',
        username=ipamuser,
        ssl_verify=False,
        password=ipampassword,
        user_agent='myapiclient',  # custom user-agent header
    )

    IPAMv6subnets = ipam.get('/subnets/432/first_subnet/56/')
    # Das neue Netz wird angelegt
    IPAMvlans = ipam.post('/subnets/432/first_subnet/56/',
                          {'description': description})
    searchstring = '/subnets/cidr/' + IPAMv6subnets + '/'
    v6Info = ipam.get(searchstring, {
        'filter_by': 'sectionId',
        'filter_value': 2,
    })
    v6Info = json.dumps(v6Info[0])
    v6Info = json.loads(v6Info)
    bluev6Id = v6Info['id']
    return bluev6Id
예제 #4
0
def CreateExternVlan(vlanid, name, description, customcb3, customl3):
    config = ConfigParser()
    config.read('C:/Temp/Git/Fortinet/Fortigate/settings.ini')

    ipamuser = config.get('IPAM', 'ipamuser')
    ipamurl = config.get('IPAM', 'url')
    ipampassword = config.get('IPAM', 'ipampassword')

    ipam = PhpIpamClient(
        url=ipamurl,
        app_id='network',
        username=ipamuser,
        ssl_verify=False,
        password=ipampassword,
        user_agent='myapiclient',  # custom user-agent header
    )
    IPAMvlans = ipam.post(
        '/vlan/', {
            'domainId': 3,
            'name': name,
            'number': vlanid,
            'description': description,
            'custom_CB3': customcb3,
            'custom_L3': customl3,
            'custom_VRF': 'Extern'
        })
    IPAMvlans = ipam.get('/vlan/', {
        'filter_by': 'domainId',
        'filter_value': 3,
    })
    for IPAMVlan in IPAMvlans:
        current = int(IPAMVlan['number'])
        if current == vlanid:
            ipamid = IPAMVlan['vlanId']
    return ipamid
예제 #5
0
def CreateGreenSubnetv4(vlanid, network, description):
    config = ConfigParser()
    config.read('C:/Temp/Git/Fortinet/Fortigate/settings.ini')

    ipamuser = config.get('IPAM', 'ipamuser')
    ipampassword = config.get('IPAM', 'ipampassword')

    ipam = PhpIpamClient(
        url='https://ipam.consinto.com',
        app_id='network',
        username=ipamuser,
        ssl_verify=False,
        password=ipampassword,
        user_agent='myapiclient',  # custom user-agent header
    )
    subnet = "10.113." + str(network) + ".0"
    IPAMsubnets = "10.113." + str(network) + ".0/24"
    IPAMvlans = ipam.post(
        '/subnets/', {
            'subnet': subnet,
            'mask': 24,
            'sectionId': '1',
            'description': description,
            'vlanId': vlanid
        })

    searchstring = '/subnets/cidr/' + IPAMsubnets + '/'
    redv4Info = ipam.get(searchstring, {
        'filter_by': 'sectionId',
        'filter_value': 1,
    })
    netid = redv4Info[0]['id']
    searchstring = '/addresses/first_free/' + netid + '/'

    IPAMvlans = ipam.post(searchstring, {
        'description': 'Fortigate',
        'hostname': 'Fortigate',
        'deviceId': 84
    })
    return netid
예제 #6
0
def create_address(ip, subnetId, username, password, server):
    result = ""
    username = username
    appcode = password
    ipam = PhpIpamClient(
        url=server,
        app_id=username,
        username=username,
        password=appcode,
        user_agent='snmpscanner',  # custom user-agent header
        ssl_verify=False)
    # read objecs
    try:
        ipam.post(f"/addresses/?subnetId={subnetId}&ip={ip}", {
            'description': 'Added via SNMP',
            'excludePing': 1
        })
        result = f"Created IP Address {ip} in subnet {subnetId}"
    except phpipam_client.client.PhpIpamException as e:
        if "IP address already exists" in str(e):
            result = "IP Already Exists"
    return result
예제 #7
0
def CreateNewSection(name, cust):
    """Erstellen neuer Section in Ipam

  Args:
      name (str): Kunden Name (z. B. Dokumental)
      cust (str): Firewall vdom Name (z. B. customer023)

  Returns:
      str: Returnt neue Section id
  """
    config = ConfigParser()
    config.read('C:/Temp/Git/Fortinet/Fortigate/settings.ini')

    ipamuser = config.get('IPAM', 'ipamuser')
    ipampassword = config.get('IPAM', 'ipampassword')

    ipam = PhpIpamClient(
        url='https://ipam.consinto.com',
        app_id='network',
        username=ipamuser,
        ssl_verify=False,
        password=ipampassword,
        user_agent='myapiclient',  # custom user-agent header
    )
    secname = name + " IPv4"
    secdesc = cust + '_' + name
    IPAMvlans = ipam.post(
        '/sections/', {
            'name': secname,
            'description': secdesc,
            'masterSection': '4',
            'permissions': '{"2":"2","3":"1","4":"3"}',
            'strictMode': '1',
            'subnetOrdering': 'default',
            'order': None,
            'showVLAN': '1',
            'showVRF': '1',
            'showSupernetOnly': '1',
            'DNS': None
        })

    searchstring = "/sections/"
    sectionid = ipam.get(searchstring, {
        'filter_by': 'name',
        'filter_value': secname,
    })

    return sectionid[0]['id']
예제 #8
0
def CreateServiceVlan(vlanid, name, description):
    """[summary]

  Args:
      vlanid (int): VLAN ID
      name (str): customer123 customer ID
      description (str): Kunden Name

  Returns:
      [type]: [description]
  """
    config = ConfigParser()
    config.read('C:/Temp/Git/Fortinet/Fortigate/settings.ini')

    ipamuser = config.get('IPAM', 'ipamuser')
    ipamurl = config.get('IPAM', 'url')
    ipampassword = config.get('IPAM', 'ipampassword')

    ipam = PhpIpamClient(
        url=ipamurl,
        app_id='network',
        username=ipamuser,
        ssl_verify=False,
        password=ipampassword,
        user_agent='myapiclient',  # custom user-agent header
    )
    IPAMvlans = ipam.post(
        '/vlan/', {
            'domainId': 3,
            'name': name,
            'number': vlanid,
            'description': description,
            'custom_CB3': 1,
            'custom_L3': 1,
            'custom_VRF': 'Service'
        })
    IPAMvlans = ipam.get('/vlan/', {
        'filter_by': 'domainId',
        'filter_value': 3,
    })
    for IPAMVlan in IPAMvlans:
        current = int(IPAMVlan['number'])
        if current == vlanid:
            ipamid = IPAMVlan['vlanId']
    return ipamid
예제 #9
0
config.read('C:/Temp/Git/Cisco/DCNM/settings.ini')

dcnmuser = config.get('DCNM', 'dcnmuser')
dcnmpassword = config.get('DCNM', 'dcnmpassword')
dcnmserver = config.get('DCNM', 'dcnmserver')
######

# DCNM Token abholen
# token = getRestToken(dcnmuser, dcnmpassword, dcnmserver)

# ipam Konfiguration
ipam = PhpIpamClient(
    url='https://ipam.consinto.com',
    app_id='network',
    username=dcnmuser,
    ssl_verify=False,
    password=dcnmpassword,
    user_agent='myapiclient',  # custom user-agent header
)

beginn = 3708
ende = 3800
for x in range(beginn, ende):
    IPAMvlans = ipam.post(
        '/vlan/', {
            'domainId': 57,
            'name': 'PLATZHALTER-DMZ',
            'number': x,
            'description': 'PLATZHALTER-DMZ'
        })
예제 #10
0
        if (last + 1) == network:
            last = network
        else:
            if (last + 1) != network:
                bluevlan = last + 1
                break

# Lücke gefunden - neues VLAN rein ins IPAM
logger.info('Blue-VLAN %s', bluevlan)
print("Blue VLAN: ", bluevlan)
namestring = customerID + '_' + customerName
IPAMvlans = ipam.post(
    '/vlan/', {
        'domainId': 3,
        'name': namestring,
        'number': bluevlan,
        'description': customerName,
        'custom_CB3': 1,
        'custom_L3': 1,
        'custom_VRF': 'Service'
    })

# Das VLAN wieder suchen weil wir die ID nicht als return Wert bekommen - alle VLANs abfragen
IPAMvlans = ipam.get('/vlan/', {
    'filter_by': 'domainId',
    'filter_value': 3,
})

# nach unserem VLAN suchen
for IPAMVlan in IPAMvlans:
    current = int(IPAMVlan['number'])
    if current == bluevlan: