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

[config]: Add hostname command to config CLI #669

Merged
merged 5 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,25 @@ def load_minigraph():
click.echo("Please note setting loaded from minigraph will be lost after system reboot. To preserve setting, run `config save`.")


#
# 'change-hostname' command
#
@config.command('change-hostname')
@click.argument('hostname', metavar='<hostname>', required=True)
def change_hostname(hostname):
"""Change Hostname on a SONiC device without impacting the traffic."""

config_db = ConfigDBConnector()
config_db.connect()
config_db.mod_entry('DEVICE_METADATA' , 'localhost', {"hostname" : 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
23 changes: 23 additions & 0 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ This command lists all the possible configuration commands at the top level.
aaa AAA command line
acl ACL-related configuration tasks
bgp BGP-related configuration tasks
change-hostname Change Hostname on a SONiC device without...
ecn ECN-related configuration tasks
interface Interface-related configuration tasks
interface_naming_mode Modify interface naming mode for interacting...
Expand Down Expand Up @@ -1560,6 +1561,28 @@ This command is used to remove particular IPv4 or IPv6 BGP neighbor configuratio

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

# Update Hostname Configuration Commands

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

**config change-hostname <hostname>**
This command is used to change the hostname on a SONiC device without traffic being impacted.
- Usage: config change-hostname [OPTIONS] <hostname>

Change Hostname on a SONiC device without impacting the traffic.

Options:
--help Show this message and exit.
- Examples:
```
admin@csw06:~$ sudo config change-hostname csw06-sonic
Running command: service hostname-config restart
Please note loaded setting will be lost after system reboot. To preserve setting, run config save.


admin@csw06:~$ sudo config save -y
Running command: /usr/local/bin/sonic-cfggen -d --print-data > /etc/sonic/config_db.json
```

# ECN Configuration And Show Commands

Expand Down