def addTufoForm(self, form, **info): ''' Add a tufo form to the data model Example: # must add tufo before adding tufo props model.addTufoForm('woot') Raises: BadPropName: If the property name is poorly formed. ''' if not propre.match(form): raise s_common.BadPropName(name=form) if info.get('ptype') is None: if self.isDataType(form): info['ptype'] = form else: info['ptype'] = 'str' self.forms.add(form) info['form'] = form self.model['forms'].append(form) return self.addPropDef(form, **info)
def addTufoProp(self, form, prop, **info): ''' Add a property to the data model. Example: # all foo tufos must have a foo:bar property model.addTufoProp('foo', 'bar', ptype='int', defval=0) ''' pdef = self.getPropDef(form) if pdef is None: raise s_common.NoSuchForm(name=form) if info.get('glob'): self._addPropGlob(form, prop, **info) return info['form'] = form fullprop = '%s:%s' % (form, prop) if not propre.match(fullprop): raise s_common.BadPropName(name=fullprop) self.addPropDef(fullprop, **info)
def updateProperty(self, oldprop, newprop): ''' Do a wholesale replacement of one property with another property. Args: oldprop (str): The orginal property which is removed. newprop (str): The property that is updated in place. Examples: Rename "inet:tcp4:port" to "inet:tcp4:foobar":: nrows = store.updateProperty('inet:tcp4:port', 'inet:tcp4:foobar') Notes: This API does fire syn:core:store:up:prop:pre and syn:core:store:up:prop:post events with the old and new property names in it, before and after the property update is done. This API is primarily designed for assisting with Cortex data migrations. Returns: int: Number of rows updated in place. ''' if oldprop == newprop: raise s_common.BadPropName( mesg='OldProp and newprop cannot be the same.', oldprop=oldprop, newprop=newprop) if not isinstance(newprop, str): raise s_common.BadPropName(mesg='newprop must be a str', newprop=newprop) self.savebus.fire('core:save:set:up:prop', oldprop=oldprop, newprop=newprop) self.fire('syn:core:store:up:prop:pre', oldprop=oldprop, newprop=newprop) nrows = self._updateProperty(oldprop, newprop) self.fire('syn:core:store:up:prop:post', oldprop=oldprop, newprop=newprop, nrows=nrows) return nrows