config/sysinv/cgts-client/cgts-client/cgtsclient/v1/ptp_shell.py
Alex Kozyrev 3a42372b64 Implementation of PTP support in SysInv and Puppet
Precision Time Protocol (PTP) support is added to StarlingX.
Controller Nodes act as a Boundary Clocks and synchronize its clock to a
Grand Master clock via OAM interface. Serve as a time source to other nodes.
Compute/Storage Nodes are Slave Clocks (Ordinary Clocks) and synchronize
its clock to a Controller Nodes via Management interface.
API is provided to enable and configure PTP as follows:
"system ptp-modify --enabled=<true/false>" is there to turn it on/off.
Note that NTP must be disabled first before turning PTP service on.
"system ptp-modify --mode=<hardware/software/legacy>" selects time stamping.
Hardware timestamping is the default option and achieves best time syncing.
"system ptp-modify --transport=<l2,udp>" switches between IEEE 802.3 or UDP
network transport for PTP messaging. L2 is the default transport.
"system ptp-modify --mechanism=<e2e,p2p>" sets the PTP delay mechanism.
Options: default delay request-response (E2E) mechanism and peer delay (P2P).
"system ptp-show" displays the current status of PTP service.

Change-Id: I6bb6162903c70a49b55f4fc02b44e5ca8a66d5a5
Story: 2002935
Task: 22923
Signed-off-by: Alex Kozyrev <alex.kozyrev@windriver.com>
2018-08-22 11:57:14 -04:00

80 lines
2.2 KiB
Python

########################################################################
#
# Copyright (c) 2018 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
########################################################################
from cgtsclient.common import utils
from cgtsclient import exc
def _print_ptp_show(ptp):
fields = ['uuid', 'enabled', 'mode', 'transport', 'mechanism',
'isystem_uuid', 'created_at', 'updated_at']
data = [(f, getattr(ptp, f, '')) for f in fields]
utils.print_tuple_list(data)
def do_ptp_show(cc, args):
"""Show PTP (Precision Time Protocol) attributes."""
ptps = cc.ptp.list()
_print_ptp_show(ptps[0])
def donot_config_ptp_list(cc, args):
"""List ptps."""
ptps = cc.ptp.list()
field_labels = ['uuid', 'enabled', 'mode', 'transport', 'mechanism']
fields = ['uuid', 'enabled', 'mode', 'transport', 'mechanism']
utils.print_list(ptps, fields, field_labels, sortby=1)
@utils.arg('--enabled',
metavar='<true/false>',
help="PTP service enabled.")
@utils.arg('--mode',
metavar='<mode>',
default=None,
help="PTP time stamping mode.")
@utils.arg('--transport',
metavar='<transport>',
default=None,
help="PTP transport protocol.")
@utils.arg('--mechanism',
metavar='<mechanism>',
default=None,
help="PTP delay mechanism.")
def do_ptp_modify(cc, args):
"""Modify PTP attributes."""
ptps = cc.ptp.list()
ptp = ptps[0]
op = "replace"
attributes = []
if args.enabled is not None:
attributes.append('enabled=%s' % args.enabled)
if args.mode is not None:
attributes.append('mode=%s' % args.mode)
if args.transport is not None:
attributes.append('transport=%s' % args.transport)
if args.mechanism is not None:
attributes.append('mechanism=%s' % args.mechanism)
if len(attributes) == 0:
print "No options provided."
return
patch = utils.args_array_to_patch("replace", attributes)
try:
ptp = cc.ptp.update(ptp.uuid, patch)
except exc.HTTPNotFound:
raise exc.CommandError('PTP not found: %s' % ptp.uuid)
_print_ptp_show(ptp)