def removeDevices(self, uids, organizer):
        # Resolve target if a path
        if isinstance(organizer, basestring):
            organizer = self._getObject(organizer)
        assert isinstance(organizer, DeviceOrganizer)
        devs = map(self._getObject, uids)
        removed = []
        if isinstance(organizer, DeviceGroup):
            for dev in devs:
                oldGroupNames = dev.getDeviceGroupNames()
                newGroupNames = self._removeOrganizer(organizer,
                                                      list(oldGroupNames))
                if oldGroupNames != newGroupNames:
                    dev.setGroups(newGroupNames)
                    notify(ObjectRemovedFromOrganizerEvent(dev, organizer))
                    removed.append(dev)

        elif isinstance(organizer, System):
            for dev in devs:
                oldSystemNames = dev.getSystemNames()
                newSystemNames = self._removeOrganizer(organizer,
                                                       list(oldSystemNames))
                if newSystemNames != oldSystemNames:
                    dev.setSystems(newSystemNames)
                    notify(ObjectRemovedFromOrganizerEvent(dev, organizer))
                    removed.append(dev)

        elif isinstance(organizer, Location):
            for dev in devs:
                dev.setLocation(None)
                notify(ObjectRemovedFromOrganizerEvent(dev, organizer))
                removed.append(dev)

        return removed
Beispiel #2
0
 def _moveDevices(self, uids, target):
     # Resolve target if a path
     if isinstance(target, basestring):
         target = self._getObject(target)
     assert isinstance(target, DeviceOrganizer)
     devs = (self._getObject(uid) for uid in uids)
     targetname = target.getOrganizerName()
     exports = 0
     if isinstance(target, DeviceGroup):
         for dev in devs:
             paths = set(dev.getDeviceGroupNames())
             paths.add(targetname)
             dev.setGroups(list(paths))
             notify(ObjectAddedToOrganizerEvent(dev, target))
     elif isinstance(target, System):
         for dev in devs:
             paths = set(dev.getSystemNames())
             paths.add(targetname)
             dev.setSystems(list(paths))
             notify(ObjectAddedToOrganizerEvent(dev, target))
     elif isinstance(target, Location):
         for dev in devs:
             if dev.location():
                 notify(ObjectRemovedFromOrganizerEvent(
                     dev, dev.location()))
             dev.setLocation(targetname)
             notify(ObjectAddedToOrganizerEvent(dev, target))
     elif isinstance(target, DeviceClass):
         exports = self._dmd.Devices.moveDevices(targetname,
                                                 [dev.id for dev in devs])
     return exports
    def _moveDevices(self, uids, target):
        # Resolve target if a path
        if isinstance(target, basestring):
            target = self._getObject(target)
        assert isinstance(target, DeviceOrganizer)
        devs = (self._getObject(uid) for uid in uids)
        targetname = target.getOrganizerName()
        moved_devices_count = 0
        success = False
        remodel_required = False
        if isinstance(target, DeviceGroup):
            for dev in devs:
                paths = set(dev.getDeviceGroupNames())
                paths.add(targetname)
                dev.setGroups(list(paths))
                notify(ObjectAddedToOrganizerEvent(dev, target))
            success = True
        elif isinstance(target, System):
            for dev in devs:
                paths = set(dev.getSystemNames())
                paths.add(targetname)
                dev.setSystems(list(paths))
                notify(ObjectAddedToOrganizerEvent(dev, target))
            success = True
        elif isinstance(target, Location):
            for dev in devs:
                if dev.location():
                    notify(ObjectRemovedFromOrganizerEvent(
                        dev, dev.location()))
                dev.setLocation(targetname)
                notify(ObjectAddedToOrganizerEvent(dev, target))
            success = True
        elif isinstance(target, DeviceClass):
            moved_devices_count = self._dmd.Devices.moveDevices(
                targetname, [dev.id for dev in devs])
            success = True
            remodel_required = True

        result = {
            'success': success,
            'message': 'The %s devices have been moved' % moved_devices_count,
            'remodel_required': remodel_required
        }
        return result