def ssdhealth(device, verbose, vendor): """Show SSD Health information""" if not device: device = os.popen( "lsblk -o NAME,TYPE -p | grep disk").readline().strip().split()[0] cmd = "sudo ssdutil -d " + device options = " -v" if verbose else "" options += " -e" if vendor else "" clicommon.run_command(cmd + options, display_cmd=verbose)
def pattern(prefix_pattern, vrf, verbose, namespace): """Show statistics of route flow counters by pattern""" command = "flow_counters_stat -t route --prefix_pattern \"{}\"".format( prefix_pattern) if vrf: command += ' --vrf {}'.format(vrf) if namespace is not None: command += " -n {}".format(namespace) clicommon.run_command(command, display_cmd=verbose)
def interfaces(namespace, display): cmd = "sudo ipintutil -a ipv6" if namespace is not None: cmd += " -n {}".format(namespace) cmd += " -d {}".format(display) clicommon.run_command(cmd)
def route(prefix, vrf, namespace): """Clear route flow counters by prefix""" command = "flow_counters_stat -c -t route --prefix {}".format(prefix) if vrf: command += ' --vrf {}'.format(vrf) # None namespace means default namespace if namespace is not None: command += " -n {}".format(namespace) clicommon.run_command(command)
def flowcnt_route(ctx, namespace): """Clear all route flow counters""" exit_if_route_flow_counter_not_support() if ctx.invoked_subcommand is None: command = "flow_counters_stat -c -t route" # None namespace means default namespace if namespace is not None: command += " -n {}".format(namespace) clicommon.run_command(command)
def rates(verbose, period, namespace, display): """Show interface counters rates""" cmd = "portstat -R" if period is not None: cmd += " -p {}".format(period) cmd += " -s {}".format(display) if namespace is not None: cmd += " -n {}".format(namespace) clicommon.run_command(cmd, display_cmd=verbose)
def rif(interface, period, verbose): """Show interface counters""" cmd = "intfstat" if period is not None: cmd += " -p {}".format(period) if interface is not None: cmd += " -i {}".format(interface) clicommon.run_command(cmd, display_cmd=verbose)
def detailed(interface, period, verbose): """Show interface counters detailed""" cmd = "portstat -l" if period is not None: cmd += " -p {}".format(period) if interface is not None: cmd += " -i {}".format(interface) clicommon.run_command(cmd, display_cmd=verbose)
def counters(tunnel, period, verbose): """Show VxLAN counters""" cmd = "tunnelstat -T vxlan" if period is not None: cmd += " -p {}".format(period) if tunnel is not None: cmd += " -i {}".format(tunnel) clicommon.run_command(cmd, display_cmd=verbose)
def rule(table_name, rule_id, verbose): """Show existing ACL rules""" cmd = "acl-loader show rule" if table_name is not None: cmd += " {}".format(table_name) if rule_id is not None: cmd += " {}".format(rule_id) clicommon.run_command(cmd, display_cmd=verbose)
def counts(group, counter_type, verbose): """Show drop counts""" cmd = "dropstat -c show" if group: cmd += " -g '{}'".format(group) if counter_type: cmd += " -t '{}'".format(counter_type) clicommon.run_command(cmd, display_cmd=verbose)
def psustatus(index, json, verbose): """Show PSU status information""" cmd = "psushow -s" if index >= 0: cmd += " -i {}".format(index) if json: cmd += " -j" clicommon.run_command(cmd, display_cmd=verbose)
def summary(interfacename, dump_dom, verbose): """Show interface transceiver summary information""" cmd = "sfpshow summary" if dump_dom: cmd += " --dom" if interfacename is not None: if get_interface_mode() == "alias": interfacename = iface_alias_converter.alias_to_name(interfacename) cmd += " -p {}".format(interfacename) clicommon.run_command(cmd, display_cmd=verbose)
def system_neighbors(asicname, ipaddress, verbose): """Show VOQ system neighbors information""" cmd = "voqutil -c system_neighbors" if ipaddress is not None: cmd += " -a {}".format(ipaddress) if asicname is not None: cmd += " -n {}".format(asicname) clicommon.run_command(cmd, display_cmd=verbose)
def system_ports(systemportname, namespace, verbose): """Show VOQ system ports information""" cmd = "voqutil -c system_ports" if systemportname is not None: cmd += " -i \"{}\"".format(systemportname) if namespace is not None: cmd += " -n {}".format(namespace) clicommon.run_command(cmd, display_cmd=verbose)
def lpmode(interfacename, verbose): """Show interface transceiver low-power mode status""" ctx = click.get_current_context() cmd = "sudo sfputil show lpmode" if interfacename is not None: interfacename = try_convert_interfacename_from_alias(ctx, interfacename) cmd += " -p {}".format(interfacename) clicommon.run_command(cmd, display_cmd=verbose)
def description(db, interfacename, verbose): """Show interface status, protocol and description""" ctx = click.get_current_context() cmd = "intfutil description" if interfacename is not None: interfacename = try_convert_interfacename_from_alias( ctx, db, interfacename) cmd += " {}".format(interfacename) clicommon.run_command(cmd, display_cmd=verbose)
def counters(ctx, verbose, period, interface, printall): """Show interface counters""" if ctx.invoked_subcommand is None: cmd = "portstat" if printall: cmd += " -a" if period is not None: cmd += " -p {}".format(period) if interface is not None: cmd += " -i {}".format(interface) clicommon.run_command(cmd, display_cmd=verbose)
def presence(db, interfacename, verbose): """Show interface transceiver presence""" ctx = click.get_current_context() cmd = "sfpshow presence" if interfacename is not None: interfacename = try_convert_interfacename_from_alias( ctx, db, interfacename) cmd += " -p {}".format(interfacename) clicommon.run_command(cmd, display_cmd=verbose)
def status(db, interfacename, verbose): """Show Interface status information""" ctx = click.get_current_context() cmd = "intfutil status" if interfacename is not None: interfacename = try_convert_interfacename_from_alias( ctx, db, interfacename) cmd += " {}".format(interfacename) clicommon.run_command(cmd, display_cmd=verbose)
def restart_ndppd(): verify_swss_running_cmd = "docker container inspect -f '{{.State.Status}}' swss" docker_exec_cmd = "docker exec -i swss {}" ndppd_config_gen_cmd = "sonic-cfggen -d -t /usr/share/sonic/templates/ndppd.conf.j2,/etc/ndppd.conf" ndppd_restart_cmd = "supervisorctl restart ndppd" output = clicommon.run_command(verify_swss_running_cmd, return_cmd=True) if output and output.strip() != "running": click.echo(click.style('SWSS container is not running, changes will take effect the next time the SWSS container starts', fg='red'),) return clicommon.run_command(docker_exec_cmd.format(ndppd_config_gen_cmd), display_cmd=True) sleep(3) clicommon.run_command(docker_exec_cmd.format(ndppd_restart_cmd), display_cmd=True)
def system_lags(systemlagname, asicname, linecardname, verbose): """Show VOQ system lags information""" cmd = "voqutil -c system_lags" if systemlagname is not None: cmd += " -s \"{}\"".format(systemlagname) if asicname is not None: cmd += " -n {}".format(asicname) if linecardname is not None: cmd += " -l \"{}\"".format(linecardname) clicommon.run_command(cmd, display_cmd=verbose)
def error_status(db, interfacename, fetch_from_hardware, namespace, verbose): """ Show transceiver error-status """ ctx = click.get_current_context() cmd = "sudo sfputil show error-status" if interfacename is not None: interfacename = try_convert_interfacename_from_alias(ctx, interfacename) cmd += " -p {}".format(interfacename) if fetch_from_hardware: cmd += " -hw" clicommon.run_command(cmd, display_cmd=verbose)
def eeprom(db, interfacename, dump_dom, verbose): """Show interface transceiver EEPROM information""" ctx = click.get_current_context() cmd = "sfpshow eeprom" if dump_dom: cmd += " --dom" if interfacename is not None: interfacename = try_convert_interfacename_from_alias( ctx, db, interfacename) cmd += " -p {}".format(interfacename) clicommon.run_command(cmd, display_cmd=verbose)
def tpid(interfacename, namespace, display, verbose): """Show Interface tpid information""" ctx = click.get_current_context() cmd = "intfutil -c tpid" if interfacename is not None: interfacename = try_convert_interfacename_from_alias(ctx, interfacename) cmd += " -i {}".format(interfacename) else: cmd += " -d {}".format(display) if namespace is not None: cmd += " -n {}".format(namespace) clicommon.run_command(cmd, display_cmd=verbose)
def autoneg_status(interfacename, namespace, display, verbose): """Show interface autoneg status""" ctx = click.get_current_context() cmd = "intfutil -c autoneg" #ignore the display option when interface name is passed if interfacename is not None: interfacename = try_convert_interfacename_from_alias(ctx, interfacename) cmd += " -i {}".format(interfacename) else: cmd += " -d {}".format(display) if namespace is not None: cmd += " -n {}".format(namespace) clicommon.run_command(cmd, display_cmd=verbose)
def delete(db, server_ip_address): """ Delete object from SYSLOG_SERVER table """ ctx = click.get_current_context() server_validator(ctx, db.cfgdb, server_ip_address) table = str(SYSLOG_TABLE_CDB) key = str(server_ip_address) try: del_entry(db.cfgdb, table, key) clicommon.run_command("systemctl reset-failed rsyslog-config rsyslog", display_cmd=True) clicommon.run_command("systemctl restart rsyslog-config", display_cmd=True) log.log_notice("Removed remote syslog logging: server={}".format( server_ip_address)) except Exception as e: log.log_error("Failed to remove remote syslog logging: {}".format( str(e))) ctx.fail(str(e))
def logging(filename, lines): cmd = "sudo tail -{}".format(lines) if filename: timestamp = filename.strip().split(".")[-1] file_path = "/var/crash/{}/{}".format(timestamp, filename) if os.path.isfile(file_path): cmd += " {}".format(file_path) else: click.echo("Invalid filename: '{}'!".format(filename)) sys.exit(1) else: cmd_message, dmesg_file_result = get_kdump_dmesg_files() if len(dmesg_file_result) == 0: click.echo(cmd_message) sys.exit(2) dmesg_file_result.sort(reverse=True) cmd += " {}".format(dmesg_file_result[0]) clicommon.run_command(cmd)
def del_vlan_dhcp_relay_destination(db, vid, dhcp_relay_destination_ip): """ Remove a destination IP address from the VLAN's DHCP relay """ ctx = click.get_current_context() if not clicommon.is_ipaddress(dhcp_relay_destination_ip): ctx.fail('{} is invalid IP address'.format(dhcp_relay_destination_ip)) vlan_name = 'Vlan{}'.format(vid) vlan = db.cfgdb.get_entry('VLAN', vlan_name) if len(vlan) == 0: ctx.fail("{} doesn't exist".format(vlan_name)) dhcp_relay_dests = vlan.get('dhcp_servers', []) if not dhcp_relay_destination_ip in dhcp_relay_dests: ctx.fail("{} is not a DHCP relay destination for {}".format( dhcp_relay_destination_ip, vlan_name)) dhcp_relay_dests.remove(dhcp_relay_destination_ip) if len(dhcp_relay_dests) == 0: del vlan['dhcp_servers'] else: vlan['dhcp_servers'] = dhcp_relay_dests db.cfgdb.set_entry('VLAN', vlan_name, vlan) click.echo("Removed DHCP relay destination address {} from {}".format( dhcp_relay_destination_ip, vlan_name)) try: click.echo("Restarting DHCP relay service...") clicommon.run_command("systemctl stop dhcp_relay", display_cmd=False) clicommon.run_command("systemctl reset-failed dhcp_relay", display_cmd=False) clicommon.run_command("systemctl start dhcp_relay", display_cmd=False) except SystemExit as e: ctx.fail("Restart service dhcp_relay failed with error {}".format(e))
def config(ctx, verbose): """Show NAT config related information""" if ctx.invoked_subcommand is None: click.echo("\nGlobal Values") cmd = "sudo natconfig -g" clicommon.run_command(cmd, display_cmd=verbose) click.echo("Static Entries") cmd = "sudo natconfig -s" clicommon.run_command(cmd, display_cmd=verbose) click.echo("Pool Entries") cmd = "sudo natconfig -p" clicommon.run_command(cmd, display_cmd=verbose) click.echo("NAT Bindings") cmd = "sudo natconfig -b" clicommon.run_command(cmd, display_cmd=verbose) click.echo("NAT Zones") cmd = "sudo natconfig -z" clicommon.run_command(cmd, display_cmd=verbose)