Exemple #1
0
 def do_img_dnld_status(self, line, opts):
     """
     Get a image download status
     """
     device = self.get_device(depth=-1)
     self.poutput('device_id {}'.format(device.id))
     self.poutput('name {}'.format(opts.name))
     try:
         device_id = device.id
         if device_id and opts.name:
             kw = dict(id=device_id)
             kw['name'] = opts.name
         else:
             self.poutput('Device ID, Image Name are needed')
             raise Exception('Device ID, Image Name are needed')
     except Exception as e:
         self.poutput('Error get img dnld status {}.  Error:{}'.format(
             device_id, e))
         return
     status = None
     try:
         img_dnld = voltha_pb2.ImageDownload(**kw)
         stub = self.get_stub()
         status = stub.GetImageDownloadStatus(img_dnld)
     except Exception as e:
         self.poutput('Error get img dnld status {}. Error:{}'.format(
             device_id, e))
         return
     fields_to_omit = {
         'crc',
         'local_dir',
     }
     try:
         print_pb_as_table('ImageDownload Status:', status, fields_to_omit,
                           self.poutput)
     except Exception, e:
         self.poutput('Error {}.  Error:{}'.format(device_id, e))
Exemple #2
0
 def do_show(self, line):
     """Show detailed device information"""
     print_pb_as_table('Device {}'.format(self.device_id),
                       self.get_device(depth=-1))
Exemple #3
0
    def do_perf_config(self, line, opts):
        """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
            metric_list = set()
            if opts.enable is not None:
                metric_list |= {metric for metric in opts.enable}
            if opts.disable is not None:
                metric_list |= {metric for metric in opts.disable}
            if opts.override is not None:
                metric_list |= {metric for metric, _ in opts.override}

            # The default 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
                            metric_list.discard(g.group_name)
                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
                            metric_list.discard(g.group_name)
            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
                            metric_list.discard(m.name)
                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
                            metric_list.discard(m.name)

            # 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[g.group_name], 'blue')
                                        + " is not an integer... ignored")
                                del oo[g.group_name]
                                self.pm_config_dirty = True
                                metric_list.discard(g.group_name)
                    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
                                metric_list.discard(m.name)

                    # 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

            if len(metric_list):
                metric_name_list = ", ".join(
                    str(metric) for metric in metric_list)
                self.poutput(
                    self.colorize('Error: ', 'red') +
                    'Metric/Metric Group{} '.format(
                        's' if len(metric_list) > 1 else '') +
                    self.colorize(metric_name_list, 'blue') +
                    ' {} not found'.format(
                        'were' if len(metric_list) > 1 else 'was'))
                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_show(self, _):
     """Show detailed logical device information"""
     print_pb_as_table('Logical device {}'.format(self.logical_device_id),
                       self.get_logical_device(depth=-1))