Skip to content

Commit

Permalink
[config]: Add hostname command to config CLI (sonic-net#669)
Browse files Browse the repository at this point in the history
Signed-off-by: Sangita Maity <sangitamaity0211@gmail.com>
  • Loading branch information
samaity authored and jleveque committed Oct 3, 2019
1 parent 01903e2 commit 46f344e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
19 changes: 19 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,25 @@ def load_minigraph():
click.echo("Please note setting loaded from minigraph will be lost after system reboot. To preserve setting, run `config save`.")


#
# 'hostname' command
#
@config.command('hostname')
@click.argument('new_hostname', metavar='<new_hostname>', required=True)
def hostname(new_hostname):
"""Change device hostname without impacting the traffic."""

config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry('DEVICE_METADATA' , 'localhost', {"hostname" : new_hostname})
try:
command = "service hostname-config restart"
run_command(command, display_cmd=True)
except SystemExit as e:
click.echo("Restarting hostname-config service failed with error {}".format(e))
raise
click.echo("Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`.")

#
# 'portchannel' group ('config portchannel ...')
#
Expand Down
21 changes: 21 additions & 0 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ This command lists all the possible configuration commands at the top level.
acl ACL-related configuration tasks
bgp BGP-related configuration tasks
ecn ECN-related configuration tasks
hostname Change device hostname without impacting traffic
interface Interface-related configuration tasks
interface_naming_mode Modify interface naming mode for interacting...
load Import a previous saved config DB dump file.
Expand Down Expand Up @@ -1636,6 +1637,26 @@ The list of the WRED profile fields that are configurable is listed in the below

Go Back To [Beginning of the document](#SONiC-COMMAND-LINE-INTERFACE-GUIDE) or [Beginning of this section](#ECN-Configuration-And-Show-Commands)

# Update Device Hostname Configuration Commands

This sub-section of commands is used to change device hostname without traffic being impacted.

**config hostname <new_hostname>**
This command is used to change device hostname without traffic being impacted.

- Usage: config hostname [OPTIONS] <new_hostname>

Change device hostname without impacting the traffic.
Options:
-?, -h, --help Show this message and exit.

- Examples:
```
admin@lnos-x1-a-csw06:~$ sudo config hostname CSW06
Running command: service hostname-config restart
Please note loaded setting will be lost after system reboot. To preserve setting, run `config save`.
```

# Interface Configuration And Show-Commands

## Interface Show Commands
Expand Down

0 comments on commit 46f344e

Please sign in to comment.