def create_node_by_address(address): """ Creates new node with the given address. Return a refence to the node object if the node already exists. If the node has IP address, a port is created with the ip address """ node = find_node_by_address(address) if node is not None: return node # creating new node is needed if validIP4(address): hostname = get_host_by_addr(address, False) ips = [address] else: hostname = address ips = get_host_ips(address, False) node = Node() # if the address cannot be mapped to DNS name use '*' as domain if hostname is None: nodeName = ips[0] domainName = '*' else: nodeName = hostname.split('.')[0] domainName = hostname.replace(hostname.split('.')[0] + '.', '') node.unis_id = "urn:ogf:network:domain=%s:node=%s" % (domainName, nodeName) node.save() if hostname is None: hostname = ips[0] name = NetworkObjectNames.objects.create( name=Name.objects.create(value=hostname), networkobject=node) name.save() host = NodeAddresses.objects.create(node=node, address=Address.objects.create( value=hostname, type='hostname')) host.save() for ip in ips: port = Port(parent=node, unis_id=node.unis_id + ":port:%s" % ip) port.parent = node port.save() portAddress = PortAddresses.objects.create( port=port, address=Address.objects.create(value=ip, type='ipv4')) portAddress.save() dns = get_host_by_addr(ip) if dns is not None: portAddress = PortAddresses.objects.create( port=port, address=Address.objects.create(value=dns, type='hostname')) portAddress.save() logger.info("New node '%s' is created" % node) return node
def create_node_by_address(address): """ Creates new node with the given address. Return a refence to the node object if the node already exists. If the node has IP address, a port is created with the ip address """ node = find_node_by_address(address) if node is not None: return node # creating new node is needed if validIP4(address): hostname = get_host_by_addr(address, False) ips = [address] else: hostname = address ips = get_host_ips(address, False) node = Node() # if the address cannot be mapped to DNS name use '*' as domain if hostname is None: nodeName = ips[0] domainName = '*' else: nodeName = hostname.split('.')[0] domainName = hostname.replace(hostname.split('.')[0] + '.', '') node.unis_id = "urn:ogf:network:domain=%s:node=%s" % (domainName, nodeName) node.save() if hostname is None: hostname = ips[0] name = NetworkObjectNames.objects.create(name = Name.objects.create(value=hostname), networkobject=node) name.save() host = NodeAddresses.objects.create(node=node, address = Address.objects.create(value=hostname,type='hostname')) host.save() for ip in ips: port = Port(parent=node, unis_id=node.unis_id+":port:%s" % ip) port.parent = node port.save() portAddress = PortAddresses.objects.create(port=port, address = Address.objects.create(value=ip,type='ipv4')) portAddress.save() dns = get_host_by_addr(ip) if dns is not None: portAddress = PortAddresses.objects.create(port=port, address = Address.objects.create(value=dns,type='hostname')) portAddress.save() logger.info("New node '%s' is created" % node) return node
def process_port(port, node): portID = get_urn_value(port.getAttribute('id'), 'port') capacity = port.getElementsByTagNameNS(TOPOLOGY_NS, "capacity") maximumReservableCapacity = port.getElementsByTagNameNS(TOPOLOGY_NS, "maximumReservableCapacity") minimumReservableCapacity = port.getElementsByTagNameNS(TOPOLOGY_NS, "minimumReservableCapacity") granularity = port.getElementsByTagNameNS(TOPOLOGY_NS, "granularity") links = port.getElementsByTagNameNS(TOPOLOGY_NS, "link") p = Port(node=node, port=portID, capacity=capacity[0].firstChild.data, maximumReservableCapacity=maximumReservableCapacity[0].firstChild.data, minimumReservableCapacity=minimumReservableCapacity[0].firstChild.data, granularity=granularity[0].firstChild.data, ) p.save() for l in links: process_link(l, p)