Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute 'send_config_set' #3540

Open
benc1347 opened this issue Nov 28, 2024 · 2 comments
Open

AttributeError: 'NoneType' object has no attribute 'send_config_set' #3540

benc1347 opened this issue Nov 28, 2024 · 2 comments

Comments

@benc1347
Copy link

benc1347 commented Nov 28, 2024

Hi everyone,
I am new in python and I can't seem to find a way to get around it.

I have writen a python script, to select office number, vlan number, switch IP address (dropdown menu), and port number (dropdown menu)

Then connect to the switch with available details and configure the switch port accordingly.
The program works fine when I was collecting the data from text files, but now that I have converted into menu so there will be no mistake in typing the details, I am not able to figure out why it is not working.

Thanks in advance for your help

The codes is below:

import logging
from tkinter import *
import hvac
import paramiko


# Connect to Vault
vault_addr = "http://192.168.99.19:8200"
vault_token = "hvs.xxxxxxxxxxxxxxxxxxxxx"

client = hvac.Client(url=vault_addr, token=vault_token)

# Retrieve credentials from Vault
secret_path = "passwords"
secret = client.secrets.kv.v2.read_secret_version(path=secret_path)
username = secret['data']['data']['myuser']
password = secret['data']['data']['mypass']

main_window = Tk()
main_window.title('Switch Configuration')
main_window.iconbitmap('C:/soft/1/net.ico')
main_window.geometry("400x300")

main_window.columnconfigure(0, weight=1)
main_window.columnconfigure(1, weight=1)

#now we create check boxes
#first creating Options part
top_label = Label(main_window, text="Switch Configurations")
top_label.grid(column=0, row=2, columnspan=2)

#we create name label here we don't see entry section and only the left side of the frame
office_label = Label(main_window, text="Office No.    ")
office_label.grid(column=0, row=4)
office_field = Entry()
office_field.grid(column=1, row=4)

#we create name label here we don't see entry section and only the left side of the frame
vlan_label = Label(main_window, text="Vlan No.     ")
vlan_label.grid(column=0, row=6)
vlan_field = Entry()
vlan_field.grid(column=1, row=6)


#drop down menu switch List
switch_menu_label= Label(main_window, text="Switch List ")
switch_menu_label.grid(column=0, row=8)

switch_list = ["192.168.99.241", "192.168.99.242", "192.168.99.243", "192.168.99.244",
    "192.168.99.245", "192.168.99.246", "192.168.99.247", "192.168.99.248", "192.168.99.249"]
switch_value = StringVar(main_window)
switch_value.set("Select A Switch: ")

switch_menu = OptionMenu(main_window, switch_value, *switch_list)
switch_menu.grid(column=1, row=8)


#drop down menu
port_menu_label= Label(main_window, text="Switch Port ")
port_menu_label.grid(column=0, row=10)

port_list = ["FastEthernet0/1", "FastEthernet0/2", "FastEthernet0/3", "FastEthernet0/4",
    "FastEthernet0/5", "FastEthernet0/6", "FastEthernet0/7", "FastEthernet0/8", "FastEthernet0/9",
    "FastEthernet0/10", "FastEthernet0/11", "FastEthernet0/12", "FastEthernet0/13", "FastEthernet0/14",
    "FastEthernet0/15", "FastEthernet0/16", "FastEthernet0/17", "FastEthernet0/18", "FastEthernet0/19",
    "FastEthernet0/20", "FastEthernet0/21", "FastEthernet0/22", "FastEthernet0/23", "FastEthernet0/24",
    "FastEthernet0/25", "FastEthernet0/26", "FastEthernet0/27", "FastEthernet0/28", "FastEthernet0/29",
    "FastEthernet0/30", "FastEthernet0/31", "FastEthernet0/32", "FastEthernet0/33", "FastEthernet0/34",
    "FastEthernet0/35", "FastEthernet0/36", "FastEthernet0/37", "FastEthernet0/38", "FastEthernet0/39",
    "FastEthernet0/40", "FastEthernet0/41", "FastEthernet0/42", "FastEthernet0/43", "FastEthernet0/44",
    "FastEthernet0/45", "FastEthernet0/46", "FastEthernet0/47"]
port_value = StringVar(main_window)
port_value.set("Select Switch Port: ")

port_menu = OptionMenu(main_window, port_value, *port_list)
port_menu.grid(column=1, row=10)

desc = office_field.get()
vlan = vlan_field.get()
interface = port_value.get()
switches = switch_value.get()
ssh_client= paramiko.SSHClient()

def get_switch_data():
    def login():
        #connections = []
        
       
        ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        
    try:    

        connection = login()

        #for connection in connections:
        config_commands = [
        f"interface FastEthernet0/{interface}",
        f"switchport access vlan {vlan}",
        f"switchport voice vlan 96",
        f"des {desc}",
        f"switchport mode access",
        f"no switchport trunk encapsulation dot1q",
        f"no switchport trunk native vlan",
        f"no switchport trunk allowed vlan",
        f"no shutdown"
    ]
        output = connection.send_config_set(config_commands)
        print(output)
        print("-"*72)
        output = connection.send_command("wri")
        print(output)
        
    finally:
        ssh_client.close()            


  
#Submit Button
submit_button = Button(main_window, text="Submit Changes", command=get_switch_data)
submit_button.grid(column=0, row=20, columnspan=2)

main_window.mainloop()

### Error Traceback

c:\soft\Test\1.py:23: DeprecationWarning: The raise_on_deleted_version parameter will change its default value to False in hvac v3.0.0. The current default of True will presere previous behavior. 
To use the old behavior with no warning, explicitly set this value to True. See https://github.com/hvac/hvac/pull/907
  secret = client.secrets.kv.v2.read_secret_version(path=secret_path)
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\Python313\Lib\tkinter\__init__.py", line 2068, in __call__
    return self.func(*args)
           ~~~~~~~~~^^^^^^^
  File "c:\soft\Test\1.py", line 117, in get_switch_data
    output = connection.send_config_set(config_commands)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'send_config_set'
@ktbyers
Copy link
Owner

ktbyers commented Dec 4, 2024

Okay, your code doesn't look valid.

Anyways, your error is that connection is not a valid Netmiko object and is instead None and consequently has no method named send_config_set.

@benc1347
Copy link
Author

benc1347 commented Dec 7, 2024

Thanks,
I fixed the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants