def delete_rooms(rooms, session): for num, item in enumerate(rooms): try: delete_room(item=item, session=session) except UnmappedInstanceError as e: raise SimpleException('Item #{} not found. Stopping'.format(num)) session.commit()
def add_device(item, session): model = DemoDeviceInputDTO(item) if not model.is_valid(): raise SimpleException('Model is not valid!\n {}'.format(item)) device = DeviceMdl(name=model.name, dev_type=model.type) device.sources = list() device.room_binds = list() for source in model.sources: endpoint = EndpointMdl.get_endpoint_by_name(name=source.endpoint, session=session) device.sources.append(DeviceSourceMdl(endpoint_uuid=endpoint.uuid, endpoint_param=source.ep_param, device_param=source.device_param)) if model.interface['export'] is True: device.interface = InterfaceMdl(read_acl=model.interface['read_acl'], write_acl=model.interface['write_acl']) for room in model.rooms: mdl = RoomMdl.get_room_with_name(name=room, session=session) device.room_binds.append(DeviceRoomBinding(room=mdl)) session.add(device) session.flush() return device
def delete_endpoints(endpoints, session): for num, item in enumerate(endpoints): try: endpoint = delete_endpoint(item=item, session=session) except UnmappedInstanceError as e: raise SimpleException('Item #{} not found. Stopping'.format(num)) driver = ServiceHub.retrieve(DriverSrv).get(endpoint.driver_uuid) driver.delete_endpoint(endpoint) session.commit()
def add_devices(devices, session): res = list() for num, item in enumerate(devices): try: res.append(add_device(item=item, session=session)) except IntegrityError as e: raise SimpleException('Duplicate on #{} in sequence. Stopping'.format(num)) session.commit() return res
def add_endpoints(endpoints, session): res = list() for num, item in enumerate(endpoints): try: endpoint = add_endpoint(item=item, session=session) except IntegrityError as e: raise SimpleException( 'Duplicate on #{} in sequence. Stopping'.format(num)) driver = ServiceHub.retrieve(DriverSrv).get(endpoint.driver_uuid) driver.add_endpoint(endpoint) res.append(endpoint) session.commit() return res