def ipam_open(): conf_file = os.path.abspath( os.path.join(os.path.dirname(__file__), '../conf/conf.json')) #conf_file = '/home/ntradm/etc/ipam.json' try: with open(conf_file) as f: conf = json.load(f) except Exception as e: print "ipam_open(1): ", e raise SystemExit(1) try: api_fd = infoblox.Infoblox('ipam.auckland.ac.nz', conf['user'], conf['password'], '2.5', 'default', 'default', True) return api_fd except Exception as e: print "ipam_open(2): ", e raise SystemExit(2)
def main(): parser = argparse.ArgumentParser() parser.add_argument('-u', '--username', help='name of user' ) parser.add_argument('-p', '--password', help='password' ) parser.add_argument('-b', '--infobloxip', help='ipadress of the infoblox device', default=infobloxishere ) parser.add_argument('-n', '--hostname', help='new hostname' ) parser.add_argument('-i', '--ipaddress', help='new ipaddress' ) parser.add_argument('-m', '--mode', help='mode: create or delete', default='create' ) args = parser.parse_args() iba_api = infoblox.Infoblox(args.infobloxip, args.username, args.password, '1.6', 'default', 'default') if args.mode == 'create': print("Trying to create {host} with {ip}".format( host=args.hostname, ip=args.ipaddress) ) call = iba_api.create_host_record(args.ipaddress, args.hostname) print call else: print("trying to delete {host}".format(host=args.hostname)) call = iba_api.delete_host_record(args.hostname) print call
#!/usr/local/bin/python import infoblox #Uses Igor Feoktistov's infoblox.py import json import os conf_file = os.path.abspath( os.path.join(os.path.dirname(__file__), '../conf/conf.json')) with open(conf_file) as f: conf = json.load(f) iba_api = infoblox.Infoblox('ipam.auckland.ac.nz', conf['user'], conf['password'], '2.5', 'default', 'default', True) for i in range(2, 9): try: if (i != 69): host = "ivm{:0>2d}.nectar.auckland.ac.nz".format(i) ip = "130.216.189.{:d}".format(i) print "creating ", host, " ", ip iba_api.create_host_record(address=ip, fqdn=host) except Exception as e: print e print "done"
import requests requests.packages.urllib3.disable_warnings() # Assign command line arguments to named variables hostname = os.environ[ 'vmName'] # The VM name should come from CloudCenter. Use the name of the VM as the OS hostname domain = "test.com" fqdn = "{}.{}".format(hostname, domain) network = "10.110.1.0/24" netmask = "255.255.255.0" gateway = "10.110.1.1" dns_server = "10.100.1.15" # Setup connection object for Infoblox iba_api = infoblox.Infoblox('10.110.1.45', 'admin', 'infoblox', '1.6', 'default', 'default', False) try: # Create new host record with supplied network and fqdn arguments ip = iba_api.create_host_record(network, fqdn) print "nicCount=1" print "nicIP_0=" + ip print "DnsServerList=" + dns_server print "nicGateway_0=" + gateway print "nicNetmask_0=" + netmask print "domainName=" + domain print "hwClockUTC=true" print "timeZone=Canada/Eastern" print "osHostname=" + hostname except Exception as e: print e
import infoblox import ipaddress f=open("extrentiable_attibutes.csv","r") data=f.readlines() ex={} for info in data: info=info.split(",") ex[info[0]]=info[1] iba_api = infoblox.Infoblox("", '','', '1.6', 'internal', 'default') keys=ex.keys() for key in keys: if "network" not in key: update_network_extattrs(,) else: pass fw.close() f.close()
#network = sys.argv[2] fqdn = os.environ['vmName'] + '.test.local' #network = os.environ['IPAMNetwork'] network = '192.168.10.0/24' #Setup connection object for Infoblox iba_api = infoblox.Infoblox('192.168.10.1', 'admin', 'infoblox', '1.6', 'default', 'default', False) try: #Create new host record with supplied network and fqdn arguments ip = iba_api.create_host_record(network, fqdn) print 'domainName=test.local' print 'DnsServerList=8.8.8.8' print 'nicDnsServerList_0=8.8.8.8' print 'nicGateway_0=192.168.10.254'
#!/usr/bin/env python import infoblox import requests import os requests.packages.urllib3.disable_warnings() domain = os.environ['eNV_domain'] fqdn = os.environ['vmName'].lower() + "." + domain iba_api = infoblox.Infoblox('10.16.128.160', '<infoblox-user>', '<infoblox-passwd>', '1.6', iba_dns_view='default', iba_network_view='default', iba_verify_ssl=False) try: # Create new host record with supplied network and fqdn arguments ip = iba_api.delete_host_record(fqdn) except Exception as e: print e
# Get session on the basis of authentication token token = os.environ.get('API_TOKEN') user = os.environ.get('USER') tenant = os.environ.get('TENANT') print "[INFO] token: %s" % token print "[INFO] user: %s" % user print "[INFO] tenant: %s" % tenant ibx_server = '10.56.70.250' ibx_username = '******' ibx_password = '******' ibx_version = '2.0' ibx_dns_view = 'default' ibx_net_view = 'default' with ApiSession("localhost", user, token=token, tenant=tenant) as session: vs_name = ParseAviParams(session, tenant, sys.argv) vs = GetVSObject(session, vs_name, tenant) vs_hostnames = vs['vh_domain_name'] vs_parent_ref = vs['vh_parent_vs_ref'] vs_parent_vip = GetVSParentObject(session, vs_parent_ref) #Open connection to Infoblox ibx = infoblox.Infoblox(ibx_server, ibx_username, ibx_password, ibx_version, ibx_dns_view, ibx_net_view, iba_verify_ssl=False) AddHosts(vs_hostnames, vs_parent_vip, ibx)
#Assign command line arguments to named variables infobloxFQDN = os.environ['infobloxFQDN'] iba_host = '172.17.152.121' iba_wapi_version = 'v2.9' base_url = 'https://' + iba_host + '/wapi/' + iba_wapi_version + '/' domain = "noicldhcl.com" if domain in infobloxFQDN: fqdn = infobloxFQDN else: fqdn = infobloxFQDN + "." + domain #Setup connection object for Infoblox #Version 1.7 in call below correlated with version 6.12 of Infoblox iba_api = infoblox.Infoblox('172.17.152.121', 'admin', 'infoblox', '2.9', 'default', 'default', False) if os.environ.get("nicIndex") == '1': nicIP_0 = os.environ.get("nicIP_0") nwRef = requests.get("https://172.17.152.121/wapi/v2.9/ipv4address", auth=('admin', 'infoblox'), verify=False, data={'ip_address': nicIP_0}) hostRef = str(nwRef.json()[0]['_ref']) rest_url = base_url + hostRef deleteReq = requests.delete(url=rest_url, auth=('admin', 'infoblox'), verify=False) if os.environ.get("nicIndex") == '2':
networkDataValue = IPAddress(gwValue) - 1 # The network id required for Infoblox WAPI API. print networkDataValue nwValue = requests.get("https://172.17.152.121/wapi/v2.9/network", auth=('admin', 'infoblox'), verify=False, data={'ipv4addr': networkDataValue, '_return_fields': 'network'}) networkData = str(nwValue.json()[0]['network']) ip = IPNetwork(networkData) network = str(ip.network) netmask = str(ip.netmask) gateway = str(gwValue) broadcast = str(ip.broadcast) ip_range = [ip for ip in IPNetwork(networkData) if ip not in [IPAddress(gateway), IPAddress(network), IPAddress(broadcast)]] fvalue = str(ip_range[0]) lvalue = str(ip_range[len(ip_range) - 1]) # Setup connection object for Infoblox iba_api = infoblox.Infoblox('172.17.152.121', 'admin', 'infoblox', '2.9', iba_dns_view='default', iba_network_view='default', iba_verify_ssl=False) try: # Create new host record with supplied network and fqdn arguments ip = iba_api.create_host_record(networkData, fvalue, lvalue, fqdn, dnsConfig) print "DnsServerList=" + dns_server print "nicCount=1" print "nicIP_0=" + ip print "nicDnsServerList_0=" + dns_server # if os.environ.get("nicIndex") != '1': print "nicGateway_0=" + gateway print "nicNetmask_0=" + netmask print "domainName=" + domain print "HWClockUTC=true" print "timeZone=Canada/Eastern" if os.environ['eNV_osName'] == "Windows":
import re requests.packages.urllib3.disable_warnings() hostname = os.environ['vmName'] osName=os.environ['eNV_osName'] clusterName=os.environ['UserClusterName'] envName=os.environ['eNV_CliqrDepEnvName'] datacenter=os.environ['UserDataCenterName'] network=os.environ['subnetId'] vlan = re.search('\(([^)]+)', network).group(1) pg = network.replace("(IDCVSM01)", "") custSpec = pg + "Template" z = network.split('-') envname = z[0] iba_api = infoblox.Infoblox('<infoblox-IPAddress>', '<infoblox-username>', '<password>', '1.6', iba_dns_view='default', iba_network_view='default', iba_verify_ssl=False) #first find the subnet based on VLAN extended attribute unet = iba_api.get_network_by_extattrs("VLAN="+vlan) hostname = os.environ['vmName'] # The VM name should come from CloudCenter. Use the name of the VM as the OS hostname domain = "<domain name here>" fqdn = "{}.{}".format(hostname, domain) network = unet[0] mask = ipaddr.IPv4Network(network) umask = mask.netmask netmask =str(umask) x = str(mask) y = x.split(".") gateway = y[0]+"."+y[1]+"."+y[2]+".1" ##define DNS Servers
help='FQDN of host to add to DNS') # because we want -p for password, we use -o for port parser.add_argument('-n', '--network', required=True, action='store', help='Network in CIDR notation ') args = parser.parse_args() return args ip = '' args = get_args() iba_api = infoblox.Infoblox('infoblox.host.com', 'user', 'password', '1.6', 'default', 'default', False) try: ip = iba_api.get_next_available_ip(args.network) print "Next Available IP = " + ip except Exception as e: print e try: host = iba_api.create_host_record_no_dns(ip, args.fqdn) except Exception as e: print e print "FQDN: " + args.fqdn + " has been assigned the IP Address of: " + ip