This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Changing the hostnames on all switches on network with NCM

Hi Guys (and Gals),

Due to a recent change in our network we need to rename all of our cisco switches with a new naming convention.  Our current convention goes like this:

c12-001

c12-002

c12-003

...

c12-254

This is spread across the whole campus so new switches have more recent numbers, but can be located in ANY building.  So we have decided to change the naming convention so we know where a switch is based on the hostname.

So the new convention goes something like this:

BA45-001

BA45-002 - All for building A

BA45-003

----

BG150-001

BG150-002 - All for building G

BG150-003

The numbers represent the final two octets of the IP address of the switch, the first two are predefined. So for example BA45-001 has an IP of 10.15.45.1 and BG150-003 would have a IP of 10.15.150.3

At the moment I have to rename them manually and after about an hour change the IP address, this is because it takes a while for the hostname to update on the system.

Is there an easier way to do this?

Thank you,

phipse

(CCNP R&S)

  • There sure is an easy way. Export custom properties including nodeid and caption as excel. Do a find and replace for everything. So if C12 becomes BA150 just do the replace. It's excel so you can get as complicated as you want. Then do an index match to the new ip addresses. After that just write a SQL update statement in a formula like ="update nodes set ip_address='"&A1&"' where nodeid ="&B1

    Copy that formula for every row and put the resulting update statements into SMSS.

    Keep in mind that modifying the database can trash your whole system so take care. The entire change would take a few hours using this process. Let me know if you want some help

    Matthew Hawks

    Loop1 Systems

  • This changes the name in Orion, but doesn't affect the nodes themselves.   As I read the original question, I believe Euan wants to change the actual hostname on the device.

    I have the same need based on similar criteria.  I have a change where all the switches need one letter changed due to a naming standards "realignment".  I have access switches that are named ANxxxxx-## or APxxxxx-## that now need to be ABxxxxx-##.

    Can this be scripted in NCM?

  • First you need to get the new names into a custom property (use excel) and then just use a config change template to apply the name. This may be possible with a standard NCM script, but I personally only use those for things without variables. You could even extract your 3rd and 4th octets into custom proprieties and build the name within the config change template, but that may be more hassle than it is worth since you would have to take steps to ensure that names weren't used twice, but if the information is already in your custom properties it may save you time. Below is a config change template that passes validation that may do what you need (please test and verify everything before using as this was made with the basic information your provided). If you remove the string manipulation you could easily have it just push what is in a custom property. Custom properties I used below are: Campus, Building, Octet3, Octet4. Please let me know if this helps.

    /*

    .CHANGE_TEMPLATE_DESCRIPTION

        This change template changes the device name in a specific way.

    .CHANGE_TEMPLATE_TAGS

        cisco, eigrp, ios, netflow, routing

    .PLATFORM_DESCRIPTION

        Cisco IOS

    .PARAMETER_LABEL @ContextNode

        Node

    .PARAMETER_DESCRIPTION @ContextNode

        The node the template will operate on.  All templates require this by default. The target node is selected during the first part of the wizard so it will not be available for selection when defining values of variables.

    */

    script ChangeName (

                                 NCM.Nodes @ContextNode

                             )

    {

        string @NewName = @ContextNode.Campus + @ContextNode.Building

         @NewName = @NewName + @ContextNode.Octet3

         @NewName = @NewName + '-'

         @NewName = @NewName + @ContextNode.Octet4

        

        CLI

        {

            configure terminal

            hostname @NewName

            end

        }

    }

  • I wanted to update my response with how I did my name update back in 2018.

    • Using a report, I exported all the pertinent info into a CSV: Node name, IP.
    • I created a new custom property called NewNodeName.
    • Using Excel, I manipulated the names as desired and added the new names into a column: NewNodeName
    • I created a script in NCM to read the value of NewNodeName and apply it as a variable
    1. configure terminal   
    2. hostname ${NewNodeName}   
    3. end 
    4. copy run start
    • Applied it using filters in NCM.

    A couple of points:

    1. NCM will update the hostname in Orion automagically on whatever schedule you have rescans set for.  Patience will out.
    2. I heartily recommend you verify the script works as it is over two years old.

    All in all it was very easy (if a bit tedious) and was an interesting challenge.

  • Hello! I came across your post and wanted to thank you for answering this. Would you be able to clarify how NCM is able to read the names from Excel? Is there a way to upload them into the custom property?