def do_disable(self, line): """ Disable a device. ID of the device needs to be provided """ device_id = line if device_id not in self.device_ids(): self.poutput('Error: There is no such device') return try: stub = self.get_stub() device = stub.GetDevice(voltha_pb2.ID(id=device_id)) if device.admin_state == voltha_pb2.AdminState.DISABLED: self.poutput('Error: Device is already disabled') return stub.DisableDevice(voltha_pb2.ID(id=device_id)) self.poutput('disabling {}'.format(device_id)) # Do device query and verify that the device admin status is # DISABLED and Operational Status is unknown device = stub.GetDevice(voltha_pb2.ID(id=device_id)) if device.admin_state == voltha_pb2.AdminState.DISABLED: self.poutput('disabled successfully {}'.format(device_id)) else: self.poutput('disabling failed {}. Admin State:{} ' 'Operation State: {}'.format( device_id, device.admin_state, device.oper_status)) except Exception as e: self.poutput('Error disabling {}. Error:{}'.format(device_id, e))
def do_delete(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 stub = self.get_stub() stub.DeleteAlarmFilter(voltha_pb2.ID(id=opts.filter_id))
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 get_device_mib(self, device_id, depth=-1): stub = self.get_stub() try: res = stub.GetMibDeviceData(voltha_pb2.ID(id=device_id), metadata=(('get-depth', str(depth)), )) except Exception as e: pass return res
def do_delete(self, line): """ Deleting a device. ID of the device needs to be provided """ device_id = line or self.default_device_id self.poutput('deleting {}'.format(device_id)) try: stub = self.get_stub() stub.DeleteDevice(voltha_pb2.ID(id=device_id)) self.poutput('deleted {}'.format(device_id)) except Exception as e: self.poutput('Error deleting {}. Error:{}'.format(device_id, e))
def do_enable(self, line): """ Enable a device. If the <id> is not provided, it will be on the last pre-provisioned device. """ device_id = line or self.default_device_id if device_id not in self.device_ids(): self.poutput('Error: There is no such preprovisioned device') return try: stub = self.get_stub() device = stub.GetDevice(voltha_pb2.ID(id=device_id)) if device.admin_state == voltha_pb2.AdminState.ENABLED: if device.oper_status != voltha_pb2.OperStatus.ACTIVATING: self.poutput('Error: Device is already enabled') return else: stub.EnableDevice(voltha_pb2.ID(id=device_id)) self.poutput('enabling {}'.format(device_id)) while True: device = stub.GetDevice(voltha_pb2.ID(id=device_id)) # If this is an OLT then acquire logical device id if device.oper_status == voltha_pb2.OperStatus.ACTIVE: if device.type.endswith('_olt'): assert device.parent_id self.default_logical_device_id = device.parent_id self.poutput('success (logical device id = {})'.format( self.default_logical_device_id)) else: self.poutput('success (device id = {})'.format( device.id)) break self.poutput('waiting for device to be enabled...') sleep(.5) except Exception as e: self.poutput('Error enabling {}. Error:{}'.format(device_id, e))
def do_self_test(self, line): """ Self Test a device. ID of the device needs to be provided """ device_id = line or self.default_device_id self.poutput('Self Testing {}'.format(device_id)) try: stub = self.get_stub() res = stub.SelfTest(voltha_pb2.ID(id=device_id)) self.poutput('Self Tested {}'.format(device_id)) self.poutput(dumps(pb2dict(res), indent=4)) except Exception as e: self.poutput('Error in self test {}. Error:{}'.format( device_id, e))
def do_img_dnld_list(self, line): """ List all image download records for a given device """ 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
def get_logical_ports(self, logical_device_id): """ Return the NNI port number and the first usable UNI port of logical device, and the vlan associated with the latter. """ stub = self.get_stub() ports = stub.ListLogicalDevicePorts( voltha_pb2.ID(id=logical_device_id)).items nni = None unis = [] for port in ports: if port.root_port: assert nni is None, "There shall be only one root port" nni = port.ofp_port.port_no else: uni = port.ofp_port.port_no uni_device = self.get_device(port.device_id) vlan = uni_device.vlan unis.append((uni, vlan)) assert nni is not None, "No NNI port found" assert unis, "Not a single UNI?" return nni, unis
def get_device(self, device_id, depth=0): stub = self.get_stub() res = stub.GetDevice(voltha_pb2.ID(id=device_id), metadata=(('get-depth', str(depth)), )) return res
def get_device(self, id): stub = self.get_stub() return stub.GetDevice(voltha_pb2.ID(id=id))