def _migrate_enabled_from_extra(migrate_engine, endpoint_table): """Remove `enabled` from `extra`, put it in the `enabled` column.""" eps = list(endpoint_table.select().execute()) for ep in eps: extra_dict = jsonutils.loads(ep.extra) if 'enabled' not in extra_dict: # `enabled` and `extra` are already as expected. continue enabled = extra_dict.pop('enabled') if enabled is None: enabled = True else: enabled = strutils.bool_from_string(enabled, default=True) new_values = { 'enabled': enabled, 'extra': jsonutils.dumps(extra_dict), } f = endpoint_table.c.id == ep.id update = endpoint_table.update().where(f).values(new_values) migrate_engine.execute(update)
def _migrate_enabled_from_extra(migrate_engine, service_table): """Remove `enabled` from `extra`, put it in the `enabled` column.""" services = list(service_table.select().execute()) for service in services: extra_dict = jsonutils.loads(service.extra) if 'enabled' not in extra_dict: # `enabled` and `extra` are already as expected. continue enabled = extra_dict.pop('enabled') if enabled is None: enabled = True else: enabled = strutils.bool_from_string(enabled, default=True) new_values = { 'enabled': enabled, 'extra': jsonutils.dumps(extra_dict), } f = service_table.c.id == service.id update = service_table.update().where(f).values(new_values) migrate_engine.execute(update)
def attr_as_boolean(val_attr): """Returns the boolean value, decoded from a string. We test explicitly for a value meaning False, which can be one of several formats as specified in oslo strutils.FALSE_STRINGS. All other string values (including an empty string) are treated as meaning True. """ return strutils.bool_from_string(val_attr, default=True)