def adopt_device(self, device, **kwargs): d = Device() if device: device.Unpack(d) # Update the core reference for that device as it will be used # by the adapter to send async messages to the Core. if ARG_FROM_TOPIC in kwargs: t = StrType() kwargs[ARG_FROM_TOPIC].Unpack(t) # Update the core reference for that device self.core_proxy.update_device_core_reference(d.id, t.val) # # Start the creation of a device specific topic to handle all # # subsequent requests from the Core. This adapter instance will # # handle all requests for that device. # reactor.callLater(0, self.createKafkaDeviceTopic, d.id) result = self.adapter.adopt_device(d) # return True, self.adapter.adopt_device(d) return True, result else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid")
def setUp(self): self.log = structlog.get_logger() self.log.debug("do setup") self.device_id = '1' self._image_dnld = ImageDownload() self._image_dnld.id = '1' self._image_dnld.name = 'switchd_1012' # self._image_dnld.name = 'xgsont_4.4.4.006.img' self._image_dnld.url = 'http://192.168.100.222:9090/load/4.4.4.006.img' self._image_dnld.crc = 0 self._image_dnld.local_dir = '/home/lcui/work/tmp' self._image_dnld.state = ImageDownload.DOWNLOAD_SUCCEEDED # ImageDownload.DOWNLOAD_UNKNOWN self._end_image_busy_try = 2 self._act_image_busy_try = 0 # self.image_file = '/home/lcui/work/tmp/v_change.txt' self.reactor = EPollReactor() self.defer = Deferred() self.adapter_agent = MockAdapterAgent(self.defer) self.defer.addCallback(self.cb_after_send_omci) pb2_dev = Device(id='1') self.adapter_agent.add_device(pb2_dev) self.core = self.adapter_agent.core self.omci_agent = OpenOMCIAgent(self.core, clock=self.reactor) self.device = self.omci_agent.add_device(self.device_id, self.adapter_agent) self.omci_agent.start() self.omci_agent.database.add('1') self.omci_agent.database.set('1', SoftwareImage.class_id, 0, {"is_committed": 1, "is_active": 1, "is_valid": 1}) self.omci_agent.database.set('1', SoftwareImage.class_id, 1, {"is_committed": 0, "is_active": 0, "is_valid": 1})
def reboot_device(self, device, **kwargs): d = Device() if device: device.Unpack(d) return (True, self.adapter.reboot_device(d)) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid")
def get_ofp_device_info(self, device, **kwargs): d = Device() if device: device.Unpack(d) return True, self.adapter.get_ofp_device_info(d) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid")
def disable_device(self, device, **_kwargs): d = Device() if device: device.Unpack(d) return True, self.adapter.disable_device(d) return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid")
def get_devices(self): devices = dict() try: blobs = yield self._backend.list('devices') if blobs is None: log.error('devices-not-found') returnValue(devices) except Exception as e: log.exception('devices-lookup-failed', e=e) returnValue(devices) # Data is marshalled as proto bytes in the data store for blob, kv_metadata in blobs: key = kv_metadata.key.decode('utf-8') device = Device() device.ParseFromString(blob) devices[key] = device returnValue(devices)
def update_pm_config(self, device, pm_configs, **kwargs): d = Device() if device: device.Unpack(d) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid") pm = PmConfigs() if pm_configs: pm_configs.Unpack(pm) return (True, self.adapter.update_pm_config(d, pm))
def start_omci_test(self, device, omcitestrequest, **kwargs): if not device: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid") if not omcitestrequest: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="omcitestrequest-invalid") d = Device() device.Unpack(d) omci_test = OmciTestRequest() omcitestrequest.Unpack(omci_test) result = self.adapter.start_omci_test(d, omci_test.uuid) return True, result
def simulate_alarm(self, device, request, **kwargs): d = Device() if device: device.Unpack(d) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid") req = SimulateAlarmRequest() if request: request.Unpack(req) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="simulate-alarm-request-invalid") return True, self.adapter.simulate_alarm(d, req)
def revert_image_update(self, device, request, **kwargs): d = Device() if device: device.Unpack(d) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid") img = ImageDownload() if request: request.Unpack(img) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="port-no-invalid") return True, self.adapter.revert_image_update(device, request)
def get_ofp_port_info(self, device, port_no, **kwargs): d = Device() if device: device.Unpack(d) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid") p = IntType() if port_no: port_no.Unpack(p) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="port-no-invalid") return True, self.adapter.get_ofp_port_info(d, p.val)
def update_flows_bulk(self, device, flows, groups, **kwargs): d = Device() if device: device.Unpack(d) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid") f = Flows() if flows: flows.Unpack(f) g = FlowGroups() if groups: groups.Unpack(g) return (True, self.adapter.update_flows_bulk(d, f, g))
def update_flows_incrementally(self, device, flow_changes, group_changes, **kwargs): d = Device() if device: device.Unpack(d) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid") f = FlowChanges() if flow_changes: flow_changes.Unpack(f) g = FlowGroupChanges() if group_changes: group_changes.Unpack(g) return (True, self.adapter.update_flows_incrementally(d, f, g))
def delete_device(self, device, **kwargs): d = Device() if device: device.Unpack(d) result = self.adapter.delete_device(d) # return (True, self.adapter.delete_device(d)) # Before we return, delete the device specific topic as we will no # longer receive requests from the Core for that device kafka_proxy = get_messaging_proxy() device_topic = kafka_proxy.get_default_topic() + "/" + d.id kafka_proxy.unsubscribe(topic=device_topic) return (True, result) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid")
def get_ext_value(self, deviceId, device, value_flag, **_kwargs): # pylint: disable=invalid-name if deviceId: str_arg = StrType() deviceId.Unpack(str_arg) else: return False, Error(code=ErrorCode.INVALID_PARAMETER, reason="device-id") if device: dev = Device() device.Unpack(dev) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid") if value_flag: value = ValueSpecifier() value_flag.Unpack(value) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="value-flag-invalid") return True, self.adapter.get_ext_value(str_arg.val, dev, value)
def update_flows_incrementally(self, device, flow_changes, group_changes, flow_metadata, **_kwargs): dev = Device() if device: device.Unpack(dev) else: return False, Error(code=ErrorCode.INVALID_PARAMETERS, reason="device-invalid") flows = FlowChanges() if flow_changes: flow_changes.Unpack(flows) groups = FlowGroupChanges() if group_changes: group_changes.Unpack(groups) metadata = FlowMetadata() if flow_metadata: flow_metadata.Unpack(metadata) return True, self.adapter.update_flows_incrementally( dev, flows, groups, metadata)