def node_sort(upper_limit, lower_limit, location_code, file_append):

	with open ('data/nodes-%s.txt' %file_append, 'r') as nodes_file:
		devices = nodes_file.read().splitlines() 					
		
	nodes_dict = layers.nodes_dict()
 	layers_key = layers.layers_key()

	for i in range (0, len(devices)):
		device_type = devices[i][devices[i].find("-") + 1 : devices[i].find("-") + 3]
		node_location_code = devices[i][0:len(location_code)]
	
		if device_type in ['ma','lc','ic','sc']:
			device_type = 'cc'
		elif device_type in ['ra','ea','ha']:
			device_type = 'a1'	
		elif device_type in ['la','da','sa','ia']:
			device_type = 'a2'
		elif device_type not in layers.layers_list():
			print "Device Type '%s' not found" %device_type
			continue
		
		if (node_location_code != location_code) and (location_code != 'all'):
			continue
		elif (int(layers.layers_dict(device_type)) < int(layers.layers_dict(upper_limit))) or (int(layers.layers_dict(device_type)) > int(layers.layers_dict(lower_limit))):
			continue
		else:
			nodes_dict[device_type].append(devices[i])			
	
	for i in nodes_dict:
		for j in nodes_dict[i]:
			nodes_dict[i] = natsort.natsorted(nodes_dict[i])


	return nodes_dict
Esempio n. 2
0
def upper_limit():
	layers_list = layers.layers_list()
	
	print "\nEnter upper limit of device hierarchy. Valid inputs include:", ','.join(layers_list)
	upper_limit = raw_input("Upper limit: ")
	if (len(upper_limit) is 0) or (upper_limit not in layers_list):
		while (len(upper_limit) is 0) or (upper_limit not in layers_list):
			upper_limit = raw_input("Enter a valid upper limit: ")
	return upper_limit
Esempio n. 3
0
def lower_limit(upper_lim):
	layers_list = layers.layers_list()
	
	print "\nEnter lower limit of device hierarchy. Valid inputs include:", ','.join(layers_list[int(layers.layers_dict(upper_lim)):len(layers_list)])
	lower_limit = raw_input("Lower limit: ")
	
	if ((len(lower_limit) is 0) or (lower_limit not in layers_list) or (int(layers.layers_dict(lower_limit)) <= int(layers.layers_dict(upper_lim)))):
		while (len(lower_limit) is 0) or (lower_limit not in layers_list) or (int(layers.layers_dict(lower_limit)) <= int(layers.layers_dict(upper_lim))):
			lower_limit = raw_input("Enter a valid lower limit: ")
	return lower_limit
Esempio n. 4
0
def seed_device():
	
	seed_device = raw_input("\nEnter seed device hostname: ")
	device_type = seed_device[seed_device.find("-") + 1 : seed_device.find("-") + 3]
	layers_list = layers.layers_list()
	
	if (len(seed_device) < 9) or (device_type not in layers_list):
		while (len(seed_device) < 9) or (device_type not in layers_list):
			seed_device = raw_input("Enter a valid seed device hostname: ")
			device_type = seed_device[seed_device.find("-") + 1 : seed_device.find("-") + 3]
	return seed_device
Esempio n. 5
0
import layers

names = layers.layers_list()

def namecheck (hostname):
	valid = False

	if hostname.count('-') > 1:
		return valid

	for j in range (0,len(names)):
		if ("-" + names[j]) in hostname:
			valid = True
			return valid
	
	return valid
Esempio n. 6
0
import layers

names = layers.layers_list()


def namecheck(hostname):
    valid = False

    if hostname.count('-') > 1:
        return valid

    for j in range(0, len(names)):
        if ("-" + names[j]) in hostname:
            valid = True
            return valid

    return valid