예제 #1
0
def remove_vlans(snakearray, conn):
	for port in snakearray:
		conn.execute('show vlan ' + port)
		vlan = first_match(conn, r'(VLAN: [0-9]+)')
		vlan = re.split(' ', vlan)
		conn.execute('no vlan ' + vlan[1])
		error1 = any_match(conn, r'(Error: Cannot undo the configuration as)')
		error2 = any_match(conn, r'(session is using this mode\.)')
		if (error1!=[])and(error2!=[]):
			quit(conn)
			raise Exception('Another user is already using this mode, remove him/her/it so we can move on')
예제 #2
0
def remove_vlans(snakearray, conn):
    for port in snakearray:
        conn.execute('show vlan ' + port)
        vlan = first_match(conn, r'(VLAN: [0-9]+)')
        vlan = re.split(' ', vlan)
        conn.execute('no vlan ' + vlan[1])
        error1 = any_match(conn, r'(Error: Cannot undo the configuration as)')
        error2 = any_match(conn, r'(session is using this mode\.)')
        if (error1 != []) and (error2 != []):
            quit(conn)
            raise Exception(
                'Another user is already using this mode, remove him/her/it so we can move on'
            )
예제 #3
0
def get_port_dbm_and_type(port, error, conn):
    port_type_tx_rx = [port, 'unknown', 'None', 'None']
    conn.execute('show media ' + port + ' | include Type')
    port_type_tx_rx[1] = first_match(
        conn, r'(10GE LR|10GE ER|100GE 10x10|100GE LR4)')
    if port_type_tx_rx[1] == 'unknown':
        error.append(
            port +
            ' has an unknown port-type, please update the script to include it'
        )

    port_modport = re.split(' ', port)
    port_module = re.split('/', port_modport[1])
    conn.execute('show  optic ' + port_module[0] + ' | include ' +
                 port_modport[1] + '[\ t]')

    port_tx_rx = any_match(
        conn, r'([-]?[0-9]*\.[0-9]*[ \t]dBm[ \t]+[-]?[0-9]*\.[0-9]*[ \t]dBm)')
    port_tx_rx = re.split('\s+', str(port_tx_rx))
    port_tx = port_tx_rx[0]
    port_tx = re.split("'", port_tx)
    port_type_tx_rx[2] = port_tx[1]
    port_type_tx_rx[3] = port_tx_rx[2]

    return port_type_tx_rx
예제 #4
0
def untagged (port, currentvlan, error, conn):
	currentvlan = str(currentvlan)
	conn.execute('untagged ' + port)
	error1 = any_match(conn, r'(Error: ports)')
	error2 = any_match(conn, r'(are untagged in some user vlans)')
	if (error1!=[])and(error2!=[]):
		#Check if the VLAN error was becouse the port is already in currentvlan, if so then leave it there
		conn.execute('show vlan ' + port)
		vlan = first_match(conn, r'(VLAN: [0-9]+)')
		vlan = first_match(vlan, r'([0-9]+)') 
		if (vlan != currentvlan):
			#Check if the port is already in another snake VLAN 'SNAKE-VLAN', if so then we may replace it
			conn.execute('show vlan brief | include ' + vlan +'[\ t]')
			vlan_name = first_match(conn, r'(SNAKE-TEST)')
			if vlan_name == 'SNAKE-TEST':
				conn.execute('vlan '+ vlan)
				conn.execute('no untagged ' + port)
				conn.execute('vlan ' + currentvlan)
				conn.execute('untagged ' + port)
			else: 
				error.append(port + ' is already untagged in ' + vlan)
예제 #5
0
def untagged(port, currentvlan, error, conn):
    currentvlan = str(currentvlan)
    conn.execute('untagged ' + port)
    error1 = any_match(conn, r'(Error: ports)')
    error2 = any_match(conn, r'(are untagged in some user vlans)')
    if (error1 != []) and (error2 != []):
        #Check if the VLAN error was becouse the port is already in currentvlan, if so then leave it there
        conn.execute('show vlan ' + port)
        vlan = first_match(conn, r'(VLAN: [0-9]+)')
        vlan = first_match(vlan, r'([0-9]+)')
        if (vlan != currentvlan):
            #Check if the port is already in another snake VLAN 'SNAKE-VLAN', if so then we may replace it
            conn.execute('show vlan brief | include ' + vlan + '[\ t]')
            vlan_name = first_match(conn, r'(SNAKE-TEST)')
            if vlan_name == 'SNAKE-TEST':
                conn.execute('vlan ' + vlan)
                conn.execute('no untagged ' + port)
                conn.execute('vlan ' + currentvlan)
                conn.execute('untagged ' + port)
            else:
                error.append(port + ' is already untagged in ' + vlan)
예제 #6
0
    def testAnyMatch(self):
        from Exscript.util.match import any_match

        string = 'one uno\ntwo due'
        self.assertEqual(any_match(string, r'aaa'), [])
        self.assertEqual(any_match(string, r'\S+'), ['one uno', 'two due'])
        self.assertEqual(any_match(string, r'(aaa)'), [])
        self.assertEqual(any_match(string, r'(\S+)'), ['one', 'two'])
        self.assertEqual(any_match(string, r'(aaa) (\S+)'), [])
        expected = [('one', 'uno'), ('two', 'due')]
        self.assertEqual(any_match(string, r'(\S+) (\S+)'), expected)
예제 #7
0
def get_port_dbm_and_type(port, error, conn):
	port_type_tx_rx = [port, 'unknown', 'None', 'None']
	conn.execute('show media '+ port +' | include Type')
	port_type_tx_rx[1] = first_match(conn, r'(10GE LR|10GE ER|100GE 10x10|100GE LR4)')
	if port_type_tx_rx[1] == 'unknown':   
		error.append(port + ' has an unknown port-type, please update the script to include it')

	port_modport = re.split(' ', port)
	port_module = re.split('/', port_modport[1])
	conn.execute('show  optic '+ port_module[0] +' | include ' + port_modport[1] + '[\ t]')	

	port_tx_rx = any_match(conn, r'([-]?[0-9]*\.[0-9]*[ \t]dBm[ \t]+[-]?[0-9]*\.[0-9]*[ \t]dBm)')
	port_tx_rx = re.split('\s+', str(port_tx_rx))
	port_tx = port_tx_rx[0]
	port_tx = re.split("'", port_tx)
	port_type_tx_rx[2] = port_tx[1]
	port_type_tx_rx[3] = port_tx_rx[2]
	
	return port_type_tx_rx
예제 #8
0
def do_something(conn):
    conn.execute('ls -1')
    files = any_match(conn, r'(\S+)')
    print "Files found:", files
예제 #9
0
  def get_startup_config(self,conn):

    conn.execute('show startup-config')
    return any_match(conn, r'(.*)')[:-1]
예제 #10
0
  def get_running_config(self,conn):

    conn.execute('show running-config')
    return any_match(conn, r'(.*)')[:-1]
예제 #11
0
def do_something(job, host, conn):
    conn.execute('ls -1')
    files = any_match(conn, r'(\S+)')
    print "Files found:", files
예제 #12
0
def tagged (port, currentvlan, error, conn):
	conn.execute('tagged ' + port)
	error1 = any_match(conn, r'(Error: port)')
	error2 = any_match(conn, r'(has routing configuration)')
	if (error1!=[])and(error2!=[]):
		error.append(port + ' has routing information on it')
예제 #13
0
def tagged(port, currentvlan, error, conn):
    conn.execute('tagged ' + port)
    error1 = any_match(conn, r'(Error: port)')
    error2 = any_match(conn, r'(has routing configuration)')
    if (error1 != []) and (error2 != []):
        error.append(port + ' has routing information on it')