Wireless

 View Only
last person joined: 4 days ago 

Ask questions and share experiences with Mist APs, Marvis, and all things wireless and Wi-Fi.
  • 1.  Bulk names APs using python script

    Posted 02-24-2024 20:20

    Hi all,

    I'm a novice with Python and when trying to bulk rename APs with the guide:Renaming Access Points Use Case , I get the error:

    main-rename-ap.py: error: the following arguments are required: config_file, aps_names

    Has anyone succesfully tried this? If so, can you share any pointers please?



    ------------------------------
    STUART JONES
    ------------------------------


  • 2.  RE: Bulk names APs using python script

    Posted 03-04-2024 15:35

    Hi Stuart,

    Did you create separate files for config_file.json and ap-names.csv? This need to be in the same directory as main-rename-ap.py.

    This is an example of the config_file.json file:

     {
      "api": {
        "org_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "token": "ApUYc...hsO",
        "mist_url": "https://<api-endpoint>.mist.com/api/v1/"
      },
      "site": {
        "name": "<site-name>"
      }
    }

    You would insert your unique variables (org_id, token, and site name) to connect to Mist.

    This is an example of the contents of the CSV file:

    name,mac
    <ap-name1>,aabbcc001122
    <ap-name2>,aabbcc001123
    <ap-name3>,aabbcc001124

    This should change the AP's name from the MAC to a name, in this case <ap-name*>.

    Hope this helps.



    ------------------------------
    Keir Asher
    ------------------------------



  • 3.  RE: Bulk names APs using python script

    Posted 03-07-2024 10:12

    Hi Keir,

    The issues was I was when I was running the script I was only entering python ap-names-ap.py but is should have been python ap-names-ap.py config.json ap-names.csv. Juniper support helped me with it.

    Thanks for the suggestion.

    Stuart



    ------------------------------
    STUART JONES
    ------------------------------



  • 4.  RE: Bulk names APs using python script

    Posted 03-07-2024 15:23

    Hi Stuart,

    We have updated the document to correct the config.json file and to include specific instructions about running the Python script. 

    You can see the updated document here.

    Thanks for reaching out.



    ------------------------------
    Pete Robbins
    ------------------------------



  • 5.  RE: Bulk names APs using python script

    Posted 5 days ago

    I'm getting the following error. And not 100% certain on the syntax of entering the csv_filename. I'm 30 minutes into learning Python. All variations and placements give the same error with "unmatched }"

    SyntaxError: unmatched '}'

    D:\Python>python main-rename-ap.py config.json ap-names.csv
      File "D:\Python\main-rename-ap.py", line 67
        def retreive_ap_mac_list(csv_filename: str) -} dict:



    ------------------------------
    CHRISTOPHER HIATT
    ------------------------------



  • 6.  RE: Bulk names APs using python script

     
    Posted 4 days ago

    The script is incorrect on the documentation portal.  I've raised this with the folks that are responsible for that page and hopefully an updated version of the script will be posted in the next few days.

    Although I've not tested it, I suspect that the following is all that is required to resolve the script issue:

    Change this line:
    
    def retreive_ap_mac_list(csv_filename: str) -} dict:
    
    to 
    
    def retreive_ap_mac_list(csv_filename: str):
    



  • 7.  RE: Bulk names APs using python script

    Posted 4 days ago

    Thanks for that. I did try that variation yesterday and it gave an error for line 11. I may have messed something else up trying to troubleshoot. I'll recopy the script with that single edit and test again.

    I'm on my fourth agent on a case for this and they just keep asking for a serial number. Ugh.....



    ------------------------------
    CHRISTOPHER HIATT
    ------------------------------



  • 8.  RE: Bulk names APs using python script

     
    Posted 4 days ago

    Line 11 is referencing the import clauses, so you would need to ensure that you have the necessary Python libraries installed.

    For example: import requests

    Would mean that you should have the requests library installed.  You can check using the following command to see if you have the relevant library installed.

    pip3 freeze | grep requests
    requests==2.31.0

    If you are missing a library, then you could install it using pip, e.g. 

    pip3 install requests



  • 9.  RE: Bulk names APs using python script

    Posted 4 days ago

    Thanks for the tip. Added needed libraries and got new error. I think a good error. The AP I used to test isn't actually in the site I tested against so this looks like the correct result. I'm about to move 50 devices and will test on a device in the site to verify. 

    Now I gotta figure out how to use this to move devices to a site. I have 3500 units to rename and did NOT want to do them manually.

    D:\Python>python main-rename-ap.py config.json ap-names.csv
    ** Start the batch renaming of APs...

    Traceback (most recent call last):
      File "D:\Python\main-rename-ap.py", line 108, in <module>
        main()
      File "D:\Python\main-rename-ap.py", line 102, in main
        print(f"AP {ap['name']} is not part of site {configs['site']['id']}")
                    ~~^^^^^^^^
    KeyError: 'name'



    ------------------------------
    CHRISTOPHER HIATT
    ------------------------------



  • 10.  RE: Bulk names APs using python script

     
    Posted 4 days ago

    Yes, looks like it has progressed. 

    It looks like the script could have been updated a little more to handle a situation such as when the ap isn't part of the site, rather than throwing a KeyError.  But that's just a cosmetic issue.

    I'll probably take a look at this script in a week or so, as I have my kit for Mist due to be delivered in a week from now, so I've been itching to actually get some hands-on time with it.  Only a small lab SRX320, EX4100 and an AP45, so hopefully that will be sufficient.




  • 11.  RE: Bulk names APs using python script

    Posted 4 days ago

    I just found this repository and used the assignment script to move 3500 devices to 40 locations in about 30 minutes. Worked flawlessly.

    https://github.com/tmunzer/mist_library/blob/master/scripts/orgs/inventory_assign.py

    Going to try this rename script from same repository tomorrow.

    https://github.com/tmunzer/mist_library/blob/master/scripts/devices/rename_devices.py



    ------------------------------
    CHRISTOPHER HIATT
    ------------------------------