def moveProcess(self, uid, targetUid): obj = self._getObject(uid) target = self._getObject(targetUid) brainsCollection = [] # reindex all the devices and processes underneath this guy and the target for org in (obj.getPrimaryParent().getPrimaryParent(), target): catalog = ICatalogTool(org) brainsCollection.append(catalog.search(OSProcess)) if isinstance(obj, OSProcessClass): source = obj.osProcessOrganizer() source.moveOSProcessClasses(targetUid, obj.id) newObj = getattr(target.osProcessClasses, obj.id) elif isinstance(obj, OSProcessOrganizer): source = aq_parent(obj) source.moveOrganizer(targetUid, (obj.id,)) newObj = getattr(target, obj.id) else: raise Exception('Illegal type %s' % obj.__class__.__name__) # fire the object moved event for the process instances (will update catalog) for brains in brainsCollection: objs = imap(unbrain, brains) for item in objs: notify(ObjectMovedEvent(item, item.os(), item.id, item.os(), item.id)) return newObj.getPrimaryPath()
def addIpAddress(self, ip, netmask=24): """ Add an ip to the ipaddresses relationship on this interface. """ self._invalidate_ipaddress_cache() networks = self.device().getNetworkRoot() ip, netmask = self._prepIp(ip, netmask) #see if ip exists already and link it to interface if not netmask: netmask = get_default_netmask(ip) ipobj = networks.findIp(ip, netmask) if ipobj: dev = ipobj.device() if dev and dev != self.device(): log.warn("Adding IP Address %s to %s found it on device %s", ip, self.getId(), dev.getId()) self.ipaddresses.addRelation(ipobj) #never seen this ip make a new one in correct subnet else: ipobj = networks.createIp(ip, netmask) self.ipaddresses.addRelation(ipobj) notify(IndexingEvent(ipobj)) if self.device(): notify(IndexingEvent(self.device(), idxs=('path'))) os = self.os() notify(ObjectMovedEvent(self, os, self.id, os, self.id)) self.dmd.getDmdRoot("ZenLinkManager").add_device_network_to_cache(self.device().getId(), ipobj.network().getPrimaryUrlPath())
def test_components_reregistered_on_rename(self): portal_type = u"testtype" fti = DexterityFTI(portal_type) container_dummy = self.create_dummy() # Mock the lookup of the site and the site manager at the site root dummy_site = self.create_dummy() self.mock_utility(dummy_site, ISiteRoot) site_manager_mock = self.mocker.proxy( PersistentComponents(bases=(getGlobalSiteManager(), ))) getSiteManager_mock = self.mocker.replace( 'zope.component.hooks.getSiteManager') self.expect( getSiteManager_mock(dummy_site)).result(site_manager_mock).count( 1, None) # First look for unregistration of all local components self.expect( site_manager_mock.unregisterUtility( provided=IDexterityFTI, name=portal_type)).passthrough() # Then look for re-registration of global components self.expect( site_manager_mock.registerUtility( fti, IDexterityFTI, portal_type, info='plone.dexterity.dynamic')).passthrough() self.expect( site_manager_mock.registerUtility( mocker.MATCH(lambda x: isinstance(x, DexterityFactory) and x. portal_type == portal_type), IFactory, portal_type, info='plone.dexterity.dynamic')).passthrough() self.assertEqual('string:${folder_url}/++add++testtype', fti.add_view_expr) self.replay() ftiRenamed( fti, ObjectMovedEvent(fti, container_dummy, fti.getId(), container_dummy, u"newtype")) site_dummy = self.create_dummy( getSiteManager=lambda: site_manager_mock) setSite(site_dummy) setHooks() self.assertNotEquals(None, queryUtility(IDexterityFTI, name=portal_type)) self.assertNotEquals(None, queryUtility(IFactory, name=portal_type))
def _createRelObject(self, device, objmap, relname): """Create an object on a relationship using its objmap. """ constructor = importClass(objmap.modname, objmap.classname) if hasattr(objmap, 'id'): remoteObj = constructor(objmap.id) else: remoteObj = constructor(device, objmap) if remoteObj is None: log.debug("Constructor returned None") return False, None id = remoteObj.id if not remoteObj: raise ObjectCreationError( "failed to create object %s in relation %s" % (id, relname)) realdevice = device.device() if realdevice.isLockedFromUpdates(): objtype = "" try: objtype = objmap.modname.split(".")[-1] except: pass msg = "Add Blocked: %s '%s' on %s" % (objtype, id, realdevice.id) log.warn(msg) if realdevice.sendEventWhenBlocked(): self.logEvent(realdevice, id, Change_Add_Blocked, msg, Event.Warning) return False, None rel = device._getOb(relname, None) if not rel: raise ObjectCreationError( "No relation %s found on device %s (%s)" % (relname, device.id, device.__class__)) #"No relation %s found on device %s" % (relname, device.id)) changed = False try: remoteObj = rel._getOb(remoteObj.id) except AttributeError: self.logChange( realdevice, remoteObj, Change_Add, "adding object %s to relationship %s" % (remoteObj.id, relname)) rel._setObject(remoteObj.id, remoteObj) remoteObj = rel._getOb(remoteObj.id) changed = True if not isinstance(rel, ToManyContRelationship): notify( ObjectMovedEvent(remoteObj, rel, remoteObj.id, rel, remoteObj.id)) up_changed = self._updateObject(remoteObj, objmap) self.num_obj_changed += 1 if not up_changed and changed else 0 return up_changed or changed, remoteObj
def test_components_reregistered_on_rename(self): portal_type = u"testtype" fti = DexterityFTI(portal_type) container_dummy = self.create_dummy() # Mock the lookup of the site and the site manager at the site root dummy_site = self.create_dummy() self.mock_utility(dummy_site, ISiteRoot) site_manager_mock = Mock( wraps=PersistentComponents(bases=(getGlobalSiteManager(),))) from zope.component.hooks import getSiteManager self.patch_global(getSiteManager, return_value=site_manager_mock) self.assertEqual( 'string:${folder_url}/++add++testtype', fti.add_view_expr ) ftiRenamed( fti, ObjectMovedEvent( fti, container_dummy, fti.getId(), container_dummy, u"newtype" ) ) # First look for unregistration of all local components site_manager_mock.unregisterUtility.assert_called_once_with( provided=IDexterityFTI, name=portal_type ) # Then look for re-registration of global components self.assertEqual(site_manager_mock.registerUtility.call_count, 2) site_dummy = self.create_dummy( getSiteManager=lambda: site_manager_mock ) setSite(site_dummy) setHooks() self.assertNotEqual( None, queryUtility(IDexterityFTI, name=portal_type) ) self.assertNotEqual(None, queryUtility(IFactory, name=portal_type))
def _add_target_to_relationship(self): if self.relationship.hasobject(self.target): return True log.debug( '%s add related object: parent=%s, relationship=%s, obj=%s', # pragma: no mutate self.logstr, self.parent.id, self.relname, self._target_id) # either use device.addRelation(relname, object_map) # or create the object, then relationship._setObject(obj.id, obj) self.relationship._setObject(self._target_id, self.target) if not isinstance(self.relationship, ToManyContRelationship): from zope.container.contained import ObjectMovedEvent notify( ObjectMovedEvent(self.target, self.relationship, self.id, self.relationship, self.id)) return True
def addIpAddress(self, ip, netmask=24): """ Add an ip to the ipaddresses relationship on this interface. """ self._invalidate_ipaddress_cache() networks = self.device().getNetworkRoot() ip, netmask = self._prepIp(ip, netmask) #see if ip exists already and link it to interface ipobj = networks.findIp(ip) if ipobj: dev = ipobj.device() if dev and dev != self.device(): log.warn("Adding IP Address %s to %s found it on device %s", ip, self.getId(), dev.getId()) self.ipaddresses.addRelation(ipobj) #never seen this ip make a new one in correct subnet else: ipobj = networks.createIp(ip, netmask) self.ipaddresses.addRelation(ipobj) ipobj.index_object() os = self.os() notify(ObjectMovedEvent(self, os, self.id, os, self.id))