-
Notifications
You must be signed in to change notification settings - Fork 681
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
CLI to show 'system ready' message when the system is ready take config commands #693
Open
Kalimuthu-Velappan
wants to merge
3
commits into
sonic-net:master
Choose a base branch
from
Kalimuthu-Velappan:systemready
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,10 @@ | |
import netaddr | ||
import re | ||
import syslog | ||
import logging | ||
import swsssdk | ||
import getpass | ||
import uuid | ||
|
||
import sonic_device_util | ||
import ipaddress | ||
|
@@ -17,6 +21,12 @@ | |
|
||
import aaa | ||
import mlnx | ||
import traceback | ||
import base64 | ||
from Crypto.Cipher import AES | ||
from Crypto.Hash import SHA256 | ||
from Crypto import Random | ||
import time | ||
|
||
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help', '-?']) | ||
|
||
|
@@ -1579,5 +1589,134 @@ def del_ntp_server(ctx, ntp_ip_address): | |
except SystemExit as e: | ||
ctx.fail("Restart service ntp-config failed with error {}".format(e)) | ||
|
||
g_ext_cfg = {} | ||
|
||
@config.group('export', invoke_without_command=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This 'export' group does not appear to be relevant to the 'system ready' changes as stated in the PR title and description. Can these be removed and a separate PR created for them? |
||
@click.pass_context | ||
def export(ctx): | ||
pass | ||
|
||
@export.command('enable') | ||
@click.pass_context | ||
def export_enable(ctx): | ||
"""Enable the tech-support export service""" | ||
config_db = ConfigDBConnector() | ||
config_db.connect() | ||
cfg_entry = config_db.get_entry('EXPORT', 'export') | ||
|
||
if 'servername' in cfg_entry: | ||
cfg_entry['config'] = 'enable' | ||
config_db.set_entry('EXPORT', 'export',cfg_entry) | ||
else: | ||
print "export is not configured\n" | ||
|
||
@export.command('disable') | ||
@click.pass_context | ||
def export_disable(ctx): | ||
"""Disable the tech-support export service""" | ||
config_db = ConfigDBConnector() | ||
config_db.connect() | ||
cfg_entry = config_db.get_entry('EXPORT', 'export') | ||
|
||
if 'servername' in cfg_entry: | ||
cfg_entry['config'] = 'disable' | ||
config_db.set_entry('EXPORT', 'export',cfg_entry) | ||
else: | ||
print "export is not configured\n" | ||
|
||
|
||
|
||
class BasedIntParamType(click.ParamType): | ||
|
||
def convert(self, value, param, ctx): | ||
minval=30 | ||
maxval=1440 | ||
try: | ||
if int (value) == 0: | ||
return int(value) | ||
|
||
if ( int(value) >= minval and int(value) <= maxval) : | ||
return int(value) | ||
else: | ||
print "Invalid interval range, valid values[ 0(disable), {}-{} minutes]".format(minval, maxval) | ||
except Exception as e: | ||
print str(e) | ||
|
||
BASED_INT = BasedIntParamType() | ||
|
||
@export.command('interval') | ||
#@click.argument('interval', metavar='<interval in secs>', nargs=1, required=True, type=click.IntRange(0,1800,86400)) | ||
@click.argument('interval', metavar='<interval in minutes>', nargs=1, required=True, type=BASED_INT) | ||
@click.pass_context | ||
def export_interval(ctx, interval): | ||
"""Configure the tech-support export interval """ | ||
config_db = ConfigDBConnector() | ||
config_db.connect() | ||
cfg_entry = config_db.get_entry('EXPORT', 'export') | ||
|
||
if 'servername' in cfg_entry: | ||
cfg_entry['interval'] = interval | ||
config_db.set_entry('EXPORT', 'export',cfg_entry) | ||
else: | ||
print "export is not configured\n" | ||
|
||
|
||
def encrypt(key, source, encode=True): | ||
key = key.ljust(16,'F') | ||
obj = AES.new(key, AES.MODE_CFB, 'A287AJSHJKHJS562') | ||
data = obj.encrypt(source) | ||
return base64.b64encode(data).decode("latin-1") if encode else data | ||
|
||
|
||
@export.group('server') | ||
@click.pass_context | ||
def export_server(ctx): | ||
"""Configure the remote server name to connect""" | ||
pass | ||
|
||
@export_server.group('username', invoke_without_command=False) | ||
@click.pass_context | ||
def export_user(ctx): | ||
"""Configure the remote server user name to upload""" | ||
pass | ||
|
||
@export_user.group('destdir', invoke_without_command=False) | ||
@click.pass_context | ||
def export_destdir(ctx): | ||
"""Configure the remote server directory to save the tech-support data""" | ||
pass | ||
|
||
|
||
@export_destdir.command('protocol') | ||
@click.argument('servername', metavar='<server name>', nargs=1, required=True) | ||
@click.argument('username', metavar='<user name>', required=True) | ||
@click.argument('destdir', metavar='<destination directory>', required=True) | ||
@click.argument('protocol', metavar='<protocol: scp/sftp>', required=True, type=click.Choice(["scp", "sftp"])) | ||
@click.pass_context | ||
def export_protocol(ctx, servername, username, destdir, protocol ): | ||
""" | ||
Configures the export service to upload the tech-support data to a remote server \n | ||
<server name> - Configure the remote server name to connect \n | ||
<user name> - Configure the remote server user name to upload \n | ||
<dest dir> - Configure the remote server directory to save | ||
the tech-support data \n | ||
<protocol> - Configure the protocol type[scp/sftp] to upload | ||
the tech-support data \n | ||
""" | ||
g_ext_cfg['servername'] = servername | ||
g_ext_cfg['username'] = username | ||
g_ext_cfg['destdir'] = destdir | ||
g_ext_cfg['protocol'] = protocol | ||
|
||
try: | ||
g_ext_cfg['password'] = getpass.getpass('Password:') | ||
g_ext_cfg['password'] = encrypt(str(uuid.getnode()), g_ext_cfg['password']) | ||
except: | ||
print "Input reading error!" | ||
traceback.print_exc(file=sys.stdout) | ||
|
||
config_db = ConfigDBConnector() | ||
config_db.connect() | ||
config_db.set_entry('EXPORT', 'export', g_ext_cfg) | ||
if __name__ == '__main__': | ||
config() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These modules are not used. Remove?