def do_adapters(self, line): """List loaded adapter""" stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel()) res = stub.ListAdapters(Empty()) omit_fields = {} print_pb_list_as_table('Adapters:', res.items, omit_fields, self.poutput)
def do_ports(self, line): """Show ports of device""" device = self.get_device(depth=-1) omit_fields = { } print_pb_list_as_table('Device ports:', device.ports, omit_fields, self.poutput)
def do_adapters(self, line): """List loaded adapter""" stub = self.get_stub() res = stub.ListAdapters(Empty()) omit_fields = {'config.log_level', 'logical_device_ids'} print_pb_list_as_table('Adapters:', res.items, omit_fields, self.poutput)
def do_devices(self, line): """List devices registered in Voltha""" devices = self.get_devices() omit_fields = { 'adapter', 'vendor', 'model', 'hardware_version', 'images', 'firmware_version', 'vendor_id' } print_pb_list_as_table('Devices:', devices, omit_fields, self.poutput)
def do_create(self, line, opts): if opts.filter_rules: stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel()) result = stub.CreateAlarmFilter( voltha_pb2.AlarmFilter(rules=opts.filter_rules)) print_pb_list_as_table( "Rules for Filter ID = {}:".format(result.id), result.rules, {}, self.poutput)
def do_ports(self, _): """Show ports of logical device""" device = self.get_logical_device(depth=-1) omit_fields = { 'ofp_port.advertised', 'ofp_port.peer', 'ofp_port.max_speed' } print_pb_list_as_table('Logical device ports:', device.ports, omit_fields, self.poutput)
def do_images(self, line): """Show software images on the device""" device = self.get_device(depth=-1) omit_fields = {} print_pb_list_as_table('Software Images:', device.images.image, omit_fields, self.poutput, show_nulls=True)
def do_logical_devices(self, line): """List logical devices in Voltha""" stub = self.get_stub() res = stub.ListLogicalDevices(Empty()) omit_fields = { 'desc.mfr_desc', 'desc.hw_desc', 'desc.sw_desc', 'desc.dp_desc', 'desc.serial_number', 'switch_features.capabilities' } print_pb_list_as_table('Logical devices:', res.items, omit_fields, self.poutput)
def do_ports(self, _): """Show ports of logical device""" device = self.get_logical_device(depth=-1) omit_fields = { 'ofp_port.advertised', 'ofp_port.peer', 'ofp_port.max_speed' } print_pb_list_as_table('Logical device ports:', device.ports, omit_fields, self.poutput)
def do_show(self, line, opts): stub = self.get_stub() if not opts.filter_id: result = stub.ListAlarmFilters(Empty()) print_pb_list_as_table("Alarm Filters:", result.filters, {}, self.poutput) else: result = stub.GetAlarmFilter(voltha_pb2.ID(id=opts.filter_id)) print_pb_list_as_table("Rules for Filter ID = {}:".format(opts.filter_id), result.rules, {}, self.poutput)
def do_show(self, line, opts): stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel()) if not opts.filter_id: result = stub.ListAlarmFilters(Empty()) print_pb_list_as_table("Alarm Filters:", result.filters, {}, self.poutput) else: result = stub.GetAlarmFilter(voltha_pb2.ID(id=opts.filter_id)) print_pb_list_as_table( "Rules for Filter ID = {}:".format(opts.filter_id), result.rules, {}, self.poutput)
def do_devices(self, line): """List devices registered in Voltha""" devices = self.get_devices() omit_fields = { 'adapter', 'vendor', 'model', 'hardware_version', 'images', 'firmware_version', 'serial_number' } print_pb_list_as_table('Devices:', devices, omit_fields, self.poutput)
def do_devices(self, line): """List devices that belong to this logical device""" logical_device = self.get_logical_device() root_device_id = logical_device.root_device_id devices = [self.get_device(root_device_id)] for d in self.get_devices(): if d.parent_id == root_device_id: devices.append(d) omit_fields = { 'adapter', 'vendor', 'model', 'hardware_version', 'software_version', 'firmware_version', 'serial_number' } print_pb_list_as_table('Devices:', devices, omit_fields, self.poutput)
def do_logical_devices(self, line): """List logical devices in Voltha""" stub = self.get_stub() res = stub.ListLogicalDevices(Empty()) omit_fields = { 'desc.mfr_desc', 'desc.hw_desc', 'desc.sw_desc', 'desc.dp_desc', 'desc.serial_number', 'switch_features.capabilities' } presfns = {'datapath_id': lambda x: "{0:0{1}x}".format(int(x), 16)} print_pb_list_as_table('Logical devices:', res.items, omit_fields, self.poutput, presfns=presfns)
def do_update(self, line, opts): if not opts.filter_id: self.poutput(self.colorize('Error: ', 'red') + 'Specify ' + \ self.colorize(self.colorize('"filter id"', 'blue'), 'bold') + ' to update') return if opts.filter_rules: stub = self.get_stub() result = stub.UpdateAlarmFilter( voltha_pb2.AlarmFilter(id=opts.filter_id, rules=opts.filter_rules) ) print_pb_list_as_table("Rules for Filter ID = {}:".format(result.id), result.rules, {}, self.poutput)
def do_logical_devices(self, line): """List logical devices in Voltha""" stub = self.get_stub() res = stub.ListLogicalDevices(Empty()) omit_fields = { 'desc.mfr_desc', 'desc.hw_desc', 'desc.sw_desc', 'desc.dp_desc', 'desc.serial_number', 'switch_features.capabilities' } print_pb_list_as_table('Logical devices:', res.items, omit_fields, self.poutput)
def do_update(self, line, opts): if not opts.filter_id: self.poutput(self.colorize('Error: ', 'red') + 'Specify ' + \ self.colorize(self.colorize('"filter id"', 'blue'), 'bold') + ' to update') return if opts.filter_rules: stub = voltha_pb2.VolthaLocalServiceStub(self.get_channel()) result = stub.UpdateAlarmFilter( voltha_pb2.AlarmFilter(id=opts.filter_id, rules=opts.filter_rules)) print_pb_list_as_table( "Rules for Filter ID = {}:".format(result.id), result.rules, {}, self.poutput)
def do_devices(self, line): """List devices registered in Voltha reduced for OMCI menu""" devices = self.get_devices() omit_fields = { 'adapter', 'model', 'hardware_version', 'images', 'firmware_version', 'serial_number', 'vlan', 'root', 'extra_args', 'proxy_address', } print_pb_list_as_table('Devices:', devices, omit_fields, self.poutput)
def do_devices(self, line): """List devices that belong to this logical device""" logical_device = self.get_logical_device() root_device_id = logical_device.root_device_id devices = [self.get_device(root_device_id)] for d in self.get_devices(): if d.parent_id == root_device_id: devices.append(d) omit_fields = { 'adapter', 'vendor', 'model', 'hardware_version', 'software_version', 'firmware_version', 'serial_number' } print_pb_list_as_table('Devices:', devices, omit_fields, self.poutput)
def do_adapters(self, line): """List loaded adapter""" stub = self.get_stub() res = stub.ListAdapters(Empty()) omit_fields = {'config.log_level', 'logical_device_ids'} print_pb_list_as_table('Adapters:', res.items, omit_fields, self.poutput)
def do_images(self, line): """Show software images on the device""" device = self.get_device(depth=-1) omit_fields = {} print_pb_list_as_table('Software Images:', device.images.image, omit_fields, self.poutput, show_nulls=True)
""" device = self.get_device(depth=-1) device_id = device.id self.poutput('Get all img dnld records {}'.format(device_id)) try: stub = self.get_stub() img_dnlds = stub.ListImageDownloads(voltha_pb2.ID(id=device_id)) except Exception, e: self.poutput('Error list img dnlds {}. Error:{}'.format(device_id, e)) return fields_to_omit = { 'crc', 'local_dir', } try: print_pb_list_as_table('ImageDownloads:', img_dnlds.items, fields_to_omit, self.poutput) except Exception, e: self.poutput('Error {}. Error:{}'.format(device_id, e)) @options([ make_option('-n', '--name', action='store', dest='name', help="Image name"), ]) def do_img_dnld_cancel(self, line, opts): """ Cancel a requested image download """ device = self.get_device(depth=-1) self.poutput('device_id {}'.format(device.id)) self.poutput('name {}'.format(opts.name))
def do_perf_config(self, line, opts): #print(line) """Show and set the performance monitoring configuration of the device""" device = self.get_device(depth=-1) if not self.pm_config_last: self.pm_config_last = device.pm_configs # Ensure that a valid sub-command was provided if line.strip() not in {"set", "show", "commit", "reset", ""}: self.poutput(self.colorize('Error: ', 'red') + \ self.colorize(self.colorize(line.strip(), 'blue'), 'bold') + ' is not recognized') return # Ensure no options are provided when requesting to view the config if line.strip() == "show" or line.strip() == "": if opts.default_freq or opts.enable or opts.disable: self.poutput(opts.disable) self.poutput(self.colorize('Error: ', 'red') + 'use ' + \ self.colorize(self.colorize('"set"', 'blue'), 'bold') + ' to change settings') return if line.strip() == "set": # Set the supplied values # The defualt frequency if opts.default_freq: self.pm_config_last.default_freq = opts.default_freq self.pm_config_dirty = True # Field or group visibility if self.pm_config_last.grouped: for g in self.pm_config_last.groups: if opts.enable: if g.group_name in opts.enable: g.enabled = True self.pm_config_dirty = True for g in self.pm_config_last.groups: if opts.disable: if g.group_name in opts.disable: g.enabled = False self.pm_config_dirty = True else: for m in self.pm_config_last.metrics: if opts.enable: if m.name in opts.enable: m.enabled = True self.pm_config_dirty = True for m in self.pm_config_last.metrics: if opts.disable: if m.name in opts.disable: m.enabled = False self.pm_config_dirty = True #Frequency overrides. if opts.override: if self.pm_config_last.freq_override: oo = dict() for o in opts.override: oo[o[0]] = o[1] if self.pm_config_last.grouped: for g in self.pm_config_last.groups: if g.group_name in oo: try: g.group_freq = int(oo[g.group_name]) except ValueError: self.poutput(self.colorize('Warning: ', 'yellow') + \ self.colorize(oo[m.name], 'blue') +\ " is not an integer... ignored") del oo[g.group_name] self.pm_config_dirty = True else: for m in self.pm_config_last.metrics: if m.name in oo: try: m.sample_freq = int(oo[m.name]) except ValueError: self.poutput(self.colorize('Warning: ', 'yellow') + \ self.colorize(oo[m.name], 'blue') +\ " is not an integer... ignored") del oo[m.name] self.pm_config_dirty = True # If there's anything left the input was typoed if self.pm_config_last.grouped: field = 'group' else: field = 'metric' for o in oo: self.poutput(self.colorize('Warning: ', 'yellow') + \ 'the parameter' + ' ' + \ self.colorize(o, 'blue') + ' is not ' + \ 'a ' + field + ' name... ignored') if oo: return else: # Frequency overrides not enabled self.poutput(self.colorize('Error: ', 'red') + \ 'Individual overrides are only ' + \ 'supported if ' + \ self.colorize('freq_override', 'blue') + \ ' is set to ' + self.colorize('True', 'blue')) return self.poutput("Success") return elif line.strip() == "commit" and self.pm_config_dirty: stub = self.get_stub() stub.UpdateDevicePmConfigs(self.pm_config_last) self.pm_config_last = self.get_device(depth=-1).pm_configs self.pm_config_dirty = False elif line.strip() == "reset" and self.pm_config_dirty: self.pm_config_last = self.get_device(depth=-1).pm_configs self.pm_config_dirty = False omit_fields = {'groups', 'metrics', 'id'} print_pb_as_table('PM Config:', self.pm_config_last, omit_fields, self.poutput,show_nulls=True) if self.pm_config_last.grouped: #self.poutput("Supported metric groups:") for g in self.pm_config_last.groups: if self.pm_config_last.freq_override: omit_fields = {'metrics'} else: omit_fields = {'group_freq','metrics'} print_pb_as_table('', g, omit_fields, self.poutput, show_nulls=True) if g.enabled: state = 'enabled' else: state = 'disabled' print_pb_list_as_table( 'Metric group {} is {}'.format(g.group_name,state), g.metrics, {'enabled', 'sample_freq'}, self.poutput, dividers=100, show_nulls=True) else: if self.pm_config_last.freq_override: omit_fields = {} else: omit_fields = {'sample_freq'} print_pb_list_as_table('Supported metrics:', self.pm_config_last.metrics, omit_fields, self.poutput, dividers=100, show_nulls=True)
def do_create(self, line, opts): if opts.filter_rules: stub = self.get_stub() result = stub.CreateAlarmFilter(voltha_pb2.AlarmFilter(rules=opts.filter_rules)) print_pb_list_as_table("Rules for Filter ID = {}:".format(result.id), result.rules, {}, self.poutput)