Exemple #1
0
 def do_img_revert(self, line, opts):
     """
     Revert an image update on device
     """
     device = self.get_device(depth=-1)
     device_id = device.id
     try:
         if device_id and opts.name and opts.local_dir:
             kw = dict(id=device_id)
             kw['name'] = opts.name
             kw['local_dir'] = opts.local_dir
         else:
             self.poutput('Device ID, Image Name, and Location are needed')
             raise Exception('Device ID, Image Name, and Location are needed')
     except Exception as e:
         self.poutput('Error revert image {}. Error:{}'.format(device_id, e))
         return
     kw['save_config'] = json.loads(opts.save_config.lower())
     self.poutput('revert image update {} {} {} {}'.format( \
                 kw['id'], kw['name'],
                 kw['local_dir'], kw['save_config']))
     response = None
     try:
         img_dnld = voltha_pb2.ImageDownload(**kw)
         stub = self.get_stub()
         img_dnld = stub.GetImageDownload(img_dnld)
         response = stub.RevertImageUpdate(img_dnld)
     except Exception as e:
         self.poutput('Error revert image {}. Error:{}'.format(kw['id'], e))
         return
     name = enum2name(common_pb2.OperationResp,
                     'OperationReturnCode', response.code)
     self.poutput('response: {}'.format(name))
     self.poutput('{}'.format(response))
Exemple #2
0
 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))
     device_id = device.id
     try:
         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 cancel sw dnld {}. Error:{}'.format(device_id, e))
         return
     response = None
     try:
         img_dnld = voltha_pb2.ImageDownload(**kw)
         stub = self.get_stub()
         img_dnld = stub.GetImageDownload(img_dnld)
         response = stub.CancelImageDownload(img_dnld)
     except Exception as e:
         self.poutput('Error cancel sw dnld {}. Error:{}'.format(device_id, e))
         return
     name = enum2name(common_pb2.OperationResp,
                     'OperationReturnCode', response.code)
     self.poutput('response: {}'.format(name))
     self.poutput('{}'.format(response))
Exemple #3
0
 def do_img_dnld_request(self, line, opts):
     """
     Request image download to a device
     """
     device = self.get_device(depth=-1)
     self.poutput('device_id {}'.format(device.id))
     self.poutput('name {}'.format(opts.name))
     self.poutput('url {}'.format(opts.url))
     self.poutput('crc {}'.format(opts.crc))
     self.poutput('version {}'.format(opts.version))
     self.poutput('local dir {}'.format(opts.dir))
     try:
         device_id = device.id
         if device_id and opts.name and opts.url:
             kw = dict(id=device_id)
             kw['name'] = opts.name
             kw['url'] = opts.url
         else:
             self.poutput('Device ID and URL are needed')
             raise Exception('Device ID and URL are needed')
         if opts.dir:
             kw['local_dir'] = opts.dir
     except Exception as e:
         self.poutput('Error request img dnld {}.  Error:{}'.format(
             device_id, e))
         return
     kw['crc'] = long(opts.crc)
     kw['image_version'] = opts.version
     response = None
     try:
         request = voltha_pb2.ImageDownload(**kw)
         stub = self.get_stub()
         response = stub.DownloadImage(request)
     except Exception as e:
         self.poutput('Error download image {}. Error:{}'.format(
             kw['id'], e))
         return
     name = enum2name(common_pb2.OperationResp, 'OperationReturnCode',
                      response.code)
     self.poutput('response: {}'.format(name))
     self.poutput('{}'.format(response))
Exemple #4
0
 def do_img_dnld_request(self, line, opts):
     """
     Request image download to a device
     """
     device = self.get_device(depth=-1)
     self.poutput('device_id {}'.format(device.id))
     self.poutput('name {}'.format(opts.name))
     self.poutput('url {}'.format(opts.url))
     self.poutput('crc {}'.format(opts.crc))
     self.poutput('version {}'.format(opts.version))
     try:
         device_id = device.id
         if device_id and opts.name and opts.url:
             kw = dict(id=device_id)
             kw['name'] = opts.name
             kw['url'] = opts.url
         else:
             self.poutput('Device ID and URL are needed')
             raise Exception('Device ID and URL are needed')
     except Exception as e:
         self.poutput('Error request img dnld {}.  Error:{}'.format(device_id, e))
         return
     kw['crc'] = long(opts.crc)
     kw['image_version'] = opts.version
     response = None
     try:
         request = voltha_pb2.ImageDownload(**kw)
         stub = self.get_stub()
         response = stub.DownloadImage(request)
     except Exception as e:
         self.poutput('Error download image {}. Error:{}'.format(kw['id'], e))
         return
     name = enum2name(common_pb2.OperationResp,
                     'OperationReturnCode', response.code)
     self.poutput('response: {}'.format(name))
     self.poutput('{}'.format(response))
Exemple #5
0
    def do_simulate_alarm(self, line, opts):
        indicator = line
        device = self.get_device(depth=-1)
        device_id = device.id

        alarm_args = {
            "los": ["intf_id", "port_type_name"],
            "dying_gasp": ["intf_id", "onu_device_id"],
            "onu_los": ["intf_id", "onu_device_id"],
            "onu_lopc_miss": ["intf_id", "onu_device_id"],
            "onu_lopc_mic": ["intf_id", "onu_device_id"],
            "onu_lob": ["intf_id", "onu_device_id"],
            "onu_signal_degrade":
            ["intf_id", "onu_device_id", "inverse_bit_error_rate"],
            "onu_drift_of_window":
            ["intf_id", "onu_device_id", "drift", "new_eqd"],
            "onu_signal_fail":
            ["intf_id", "onu_device_id", "inverse_bit_error_rate"],
            "onu_activation": ["intf_id", "onu_device_id"],
            "onu_startup": ["intf_id", "onu_device_id"],
            "onu_discovery": ["intf_id", "onu_serial_number"]
        }
        try:
            if indicator not in alarm_args:
                self.poutput(
                    "Unknown alarm indicator %s. Valid choices are %s." %
                    (indicator, ", ".join(alarm_args.keys())))
                raise Exception("Unknown alarm indicator %s" % indicator)

            for arg_name in alarm_args[indicator]:
                if not getattr(opts, arg_name):
                    self.poutput(
                        "Option %s is required for alarm %s. See help." %
                        (arg_name, indicator))
                    raise Exception("Option %s is required for alarm %s" %
                                    (arg_name, indicator))

            # TODO: check for required arguments
            kw = dict(id=device_id)

            kw["indicator"] = indicator
            kw["intf_id"] = opts.intf_id
            kw["onu_device_id"] = opts.onu_device_id
            kw["port_type_name"] = opts.port_type_name
            kw["inverse_bit_error_rate"] = opts.inverse_bit_error_rate
            kw["drift"] = opts.drift
            kw["new_eqd"] = opts.new_eqd
            kw["onu_serial_number"] = opts.onu_serial_number

            if opts.clear:
                kw["operation"] = voltha_pb2.SimulateAlarmRequest.CLEAR
            else:
                kw["operation"] = voltha_pb2.SimulateAlarmRequest.RAISE
        except Exception as e:
            self.poutput('Error simulate alarm {}. Error:{}'.format(
                device_id, e))
            return
        response = None
        try:
            simulate_alarm = voltha_pb2.SimulateAlarmRequest(**kw)
            stub = self.get_stub()
            response = stub.SimulateAlarm(simulate_alarm)
        except Exception as e:
            self.poutput('Error simulate alarm {}. Error:{}'.format(
                kw['id'], e))
            return
        name = enum2name(common_pb2.OperationResp, 'OperationReturnCode',
                         response.code)
        self.poutput('response: {}'.format(name))
        self.poutput('{}'.format(response))