confctl¶
Confctl module to abstract Conftool.
- exception spicerack.confctl.ConfctlError[source]¶
Bases:
spicerack.exceptions.SpicerackError
Custom exception class for errors of this module.
- class spicerack.confctl.Confctl(config: str = '/etc/conftool/config.yaml', schema: str = '/etc/conftool/schema.yaml', dry_run: bool = True)[source]¶
Bases:
object
Confctl class to abstract conftool operations.
Initialize the instance.
- Parameters
- entity(entity_name: str) spicerack.confctl.ConftoolEntity [source]¶
Get the Conftool specific entity class.
- Parameters
entity_name (str) -- the name of the entiryself.
- Returns
and entity-specific class to perform Conftool operations.
- Return type
- class spicerack.confctl.ConftoolEntity(entity: conftool.kvobject.Entity, dry_run: bool = True)[source]¶
Bases:
object
ConftoolEntity class to perform operations on a specific Conftool entity.
Initialize the instance.
- Parameters
entity (conftool.kvobject.Entity) -- an instance of Conftool entity.
dry_run (bool, optional) -- whether this is a DRY-RUN.
- change_and_revert(field: str, original: Union[bool, str, int, float], changed: Union[bool, str, int, float], **tags: str) Iterator[Iterable[conftool.kvobject.Entity]] [source]¶
Context manager to perform actions with a changed value in conftool.
This method will only act on objects that had the original value.
Warning
If the code executed within the contextmanager raises an unhandled exception, the original state of the objects will NOT be restored.
- Parameters
- Yields
generator -- conftool.kvObject.Entity the objects that were acted upon
- filter_objects(filter_expr: Dict[str, Union[bool, str, int, float]], **tags: str) Iterator[conftool.kvobject.Entity] [source]¶
Filters objects coming from conftool based on values.
A generator will be returned which will contain only objects that match all filters.
- Parameters
filter_expr (dict) -- a set of desired field names and values.
**tags -- arbitrary Conftool tags as keyword arguments.
- Yields
conftool.kvobject.Entity -- the selected object.
- Raises
spicerack.confctl.ConfctlError -- if no object corresponds to the tags
- get(**tags: str) Iterator[conftool.kvobject.Entity] [source]¶
Generator that yields conftool objects corresponding to the selection.
- Parameters
**tags -- arbitrary Conftool tags as keyword arguments.
- Yields
conftool.kvobject.Entity -- the selected object.
- set_and_verify(key: str, value: Union[bool, str, int, float], **tags: str) None [source]¶
Set and verify a single Conftool value.
- Parameters
key (str) -- the key in Conftool to modify.
value (mixed) -- the value to set.
**tags -- arbitrary Conftool tags as keyword arguments.
- Raises
spicerack.confctl.ConfctlError -- on etcd or Conftool errors or failing to verify the changes.
- update(changed: Dict[str, Union[bool, str, int, float]], **tags: str) None [source]¶
Updates the value of conftool objects corresponding to the selection done with tags.
- Parameters
changed (dict) -- the new values to set for the selected objects.
**tags -- arbitrary Conftool tags as keyword arguments.
- Raises
spicerack.confctl.ConfctlError -- on etcd or Conftool errors.
Examples
>>> confctl.update({'pooled': 'no'}, service='appservers-.*', name='eqiad')
- update_objects(changed: Dict[str, Union[bool, str, int, float]], objects: Iterable[conftool.kvobject.Entity]) None [source]¶
Updates the value of the provided conftool objects.
- Parameters
changed (dict) -- the new values to set for the selected objects.
query (iterator(kvobject.Entity)) -- an iterator of conftool objects
- Raises
spicerack.confctl.ConfctlError -- on etcd or Conftool errors.
Examples
>>> inactive = confctl.filter_objects({'pooled': 'inactive'}, service='appservers-.*', name='eqiad') >>> confctl.update_objects({'pooled': 'no'}, inactive)