karbor.db package

Submodules

karbor.db.api module

Defines interface for DB access.

Functions in this module are imported into the karbor.db namespace. Call these functions from karbor.db namespace, not the karbor.db.api namespace.

All functions in this module return objects that implement a dictionary-like interface. Currently, many of these objects are sqlalchemy objects that implement a dictionary interface. However, a future goal is to have all of these objects be simple dictionaries.

Related Flags

connection

string specifying the sqlalchemy connection to use, like: sqlite:///var/lib/karbor/karbor.sqlite.

enable_new_services

when adding a new service to the database, is it in the pool of available hardware (Default: True)

karbor.db.api.authorize_project_context(context, project_id)

Ensures a request has permission to access the given project.

karbor.db.api.checkpoint_record_create(context, values)

Create a checkpoint record from the values dictionary.

karbor.db.api.checkpoint_record_destroy(context, checkpoint_record_id)

Destroy the checkpoint record or raise if it does not exist.

karbor.db.api.checkpoint_record_get(context, checkpoint_record_id)

Get a checkpoint record or raise if it does not exist.

karbor.db.api.checkpoint_record_get_all_by_filters_sort(context, filters, limit=None, marker=None, sort_keys=None, sort_dirs=None)

Get all checkpoint records that match all filters sorted

by multiple keys. sort_keys and sort_dirs must be a list of strings.

karbor.db.api.checkpoint_record_update(context, checkpoint_record_id, values)

Set the given properties on a checkpoint record and update it.

Raises NotFound if checkpoint record does not exist.

karbor.db.api.dispose_engine()

Force the engine to establish new connections.

karbor.db.api.get_by_id(context, model, id, *args, **kwargs)
karbor.db.api.operation_log_create(context, values)

Create a operation log from the values dictionary.

karbor.db.api.operation_log_destroy(context, operation_log_id)

Destroy the operation log or raise if it does not exist.

karbor.db.api.operation_log_get(context, operation_log_id)

Get a operation log or raise if it does not exist.

karbor.db.api.operation_log_get_all(context, marker, limit, sort_keys=None, sort_dirs=None, filters=None, offset=None)

Get all operation logs.

karbor.db.api.operation_log_get_all_by_project(context, project_id, marker, limit, sort_keys=None, sort_dirs=None, filters=None, offset=None)

Get all operation logs belonging to a project.

karbor.db.api.operation_log_update(context, operation_log_id, values)

Set the given properties on a operation log and update it.

Raises NotFound if plan does not exist.

karbor.db.api.plan_create(context, values)

Create a plan from the values dictionary.

karbor.db.api.plan_destroy(context, plan_id)

Destroy the plan or raise if it does not exist.

karbor.db.api.plan_get(context, plan_id)

Get a plan or raise if it does not exist.

karbor.db.api.plan_get_all(context, marker, limit, sort_keys=None, sort_dirs=None, filters=None, offset=None)

Get all plans.

karbor.db.api.plan_get_all_by_project(context, project_id, marker, limit, sort_keys=None, sort_dirs=None, filters=None, offset=None)

Get all plans belonging to a project.

karbor.db.api.plan_resources_update(context, plan_id, resources)

Update resources if it exists, otherwise create it.

karbor.db.api.plan_update(context, plan_id, values)

Set the given properties on a plan and update it.

Raises NotFound if plan does not exist.

karbor.db.api.purge_deleted_rows(context, age_in_days)

Purge deleted rows older than given age from karbor tables

Raises InvalidParameterValue if age_in_days is incorrect. :returns: number of deleted rows

karbor.db.api.quota_class_create(context, class_name, resource, limit)

Create a quota class for the given name and resource.

karbor.db.api.quota_class_destroy(context, class_name, resource)

Destroy the quota class or raise if it does not exist.

karbor.db.api.quota_class_destroy_all_by_name(context, class_name)

Destroy all quotas associated with a given quota class.

karbor.db.api.quota_class_get(context, class_name, resource)

Retrieve a quota class or raise if it does not exist.

karbor.db.api.quota_class_get_all_by_name(context, class_name)

Retrieve all quotas associated with a given quota class.

karbor.db.api.quota_class_update(context, class_name, resource, limit)

Update a quota class or raise if it does not exist.

karbor.db.api.quota_create(context, project_id, resource, limit)

Create a quota for the given project and resource.

karbor.db.api.quota_destroy(context, project_id, resource)

Destroy the quota or raise if it does not exist.

karbor.db.api.quota_destroy_all_by_project(context, project_id)

Destroy all quotas associated with a given project.

karbor.db.api.quota_get(context, project_id, resource)

Retrieve a quota or raise if it does not exist.

karbor.db.api.quota_get_all_by_project(context, project_id)

Retrieve all quotas associated with a given project.

karbor.db.api.quota_reserve(context, resources, quotas, deltas, expire, until_refresh, max_age, project_id=None)

Check quotas and create appropriate reservations.

karbor.db.api.quota_update(context, project_id, resource, limit)

Update a quota or raise if it does not exist.

karbor.db.api.quota_usage_create(context, project_id, resource, in_use, reserved, until_refresh)

Create a quota usage for the given project and resource.

karbor.db.api.quota_usage_get(context, project_id, resource)

Retrieve a quota usage or raise if it does not exist.

karbor.db.api.quota_usage_get_all_by_project(context, project_id)

Retrieve all usage associated with a given resource.

karbor.db.api.reservation_commit(context, reservations, project_id=None)

Commit quota reservations.

karbor.db.api.reservation_create(context, uuid, usage, project_id, resource, delta, expire)

Create a reservation for the given project and resource.

karbor.db.api.reservation_destroy(context, uuid)

Destroy the reservation or raise if it does not exist.

karbor.db.api.reservation_expire(context)

Roll back any expired reservations.

karbor.db.api.reservation_get(context, uuid)

Retrieve a reservation or raise if it does not exist.

karbor.db.api.reservation_get_all_by_project(context, project_id)

Retrieve all reservations associated with a given project.

karbor.db.api.reservation_rollback(context, reservations, project_id=None)

Roll back quota reservations.

karbor.db.api.restore_create(context, values)

Create a restore from the values dictionary.

karbor.db.api.restore_destroy(context, restore_id)

Destroy the restore or raise if it does not exist.

karbor.db.api.restore_get(context, restore_id)

Get a restore or raise if it does not exist.

karbor.db.api.restore_get_all(context, marker, limit, sort_keys=None, sort_dirs=None, filters=None, offset=None)

Get all restores.

karbor.db.api.restore_get_all_by_project(context, project_id, marker, limit, sort_keys=None, sort_dirs=None, filters=None, offset=None)

Get all restores belonging to a project.

karbor.db.api.restore_update(context, restore_id, values)

Set the given properties on a restore and update it.

Raises NotFound if plan does not exist.

karbor.db.api.scheduled_operation_create(context, values)

Create a scheduled operation from the values dictionary.

Parameters
  • context – The security context

  • values – Dictionary containing scheduled operation properties

Returns

Dictionary-like object containing the properties of the created scheduled operation

karbor.db.api.scheduled_operation_delete(context, id)

Delete a scheduled operation from the database.

Parameters
  • context – The security context

  • id – ID of the scheduled operation

Raises ScheduledOperationNotFound if scheduled operation with the given ID doesn’t exist.

karbor.db.api.scheduled_operation_get(context, id, columns_to_join=[])

Get a scheduled operation by its id.

Parameters
  • context – The security context

  • id – ID of the scheduled operation

  • columns_to_join – columns which will be joined

Returns

Dictionary-like object containing properties of the scheduled operation

Raises ScheduledOperationNotFound if scheduled operation with

the given ID doesn’t exist.

karbor.db.api.scheduled_operation_get_all_by_filters_sort(context, filters, limit=None, marker=None, sort_keys=None, sort_dirs=None)

Get all operations that match all filters sorted by multiple keys.

sort_keys and sort_dirs must be a list of strings.

karbor.db.api.scheduled_operation_log_create(context, values)

Create a scheduled operation log from the values dictionary.

Parameters
  • context – The security context

  • values – Dictionary containing scheduled operation log properties

Returns

Dictionary-like object containing the properties of the created scheduled operation log

karbor.db.api.scheduled_operation_log_delete(context, log_id)

Delete a scheduled operation log from the database.

Parameters
  • context – The security context

  • log_id – Log_id of the scheduled operation log

Raises ScheduledOperationLogNotFound if scheduled operation log with the given ID doesn’t exist.

karbor.db.api.scheduled_operation_log_delete_oldest(context, operation_id, retained_num, excepted_states=[])

Delete the oldest scheduled operation logs from the database.

Parameters
  • context – The security context

  • operation_id – ID of the scheduled operation

  • retained_num – The number of retained logs

  • excepted_states – If the state of log is in excepted_states, it will not be deleted.

karbor.db.api.scheduled_operation_log_get(context, log_id)

Get a scheduled operation log by its id.

Parameters
  • context – The security context

  • log_id – Log_id of the scheduled operation log

Returns

Dictionary-like object containing properties of the scheduled operation log

Raises ScheduledOperationLogNotFound if scheduled operation log with

the given ID doesn’t exist.

karbor.db.api.scheduled_operation_log_get_all_by_filters_sort(context, filters, limit=None, marker=None, sort_keys=None, sort_dirs=None)

Get all operation logs that match all filters sorted by multiple keys.

sort_keys and sort_dirs must be a list of strings.

karbor.db.api.scheduled_operation_log_update(context, log_id, values)

Set the given properties on a scheduled operation log and update it.

Parameters
  • context – The security context

  • log_id – Log_id of the scheduled operation log

  • values – Dictionary containing scheduled operation log properties to be updated

Returns

Dictionary-like object containing the properties of the updated scheduled operation log

Raises ScheduledOperationLogNotFound if scheduled operation log with the given ID doesn’t exist.

karbor.db.api.scheduled_operation_state_create(context, values)

Create a scheduled operation state from the values dictionary.

Parameters
  • context – The security context

  • values – Dictionary containing scheduled operation state properties

Returns

Dictionary-like object containing the properties of the created scheduled operation state

karbor.db.api.scheduled_operation_state_delete(context, operation_id)

Delete a scheduled operation state from the database.

Parameters
  • context – The security context

  • operation_id – Operation_id of the scheduled operation state

Raises ScheduledOperationStateNotFound if scheduled operation state with the given ID doesn’t exist.

karbor.db.api.scheduled_operation_state_get(context, operation_id, columns_to_join=[])

Get a scheduled operation state by its id.

Parameters
  • context – The security context

  • operation_id – Operation_id of the scheduled operation state

Columns_to_join

columns which will be joined

Returns

Dictionary-like object containing properties of the scheduled operation state

Raises ScheduledOperationStateNotFound if scheduled operation state with

the given ID doesn’t exist.

karbor.db.api.scheduled_operation_state_get_all_by_filters_sort(context, filters, limit=None, marker=None, sort_keys=None, sort_dirs=None, columns_to_join=[])

Get all operation states that match all filters sorted by multiple keys.

sort_keys and sort_dirs must be a list of strings.

karbor.db.api.scheduled_operation_state_update(context, operation_id, values)

Set the given properties on a scheduled operation state and update it.

Parameters
  • context – The security context

  • operation_id – Operation_id of the scheduled operation state

  • values – Dictionary containing scheduled operation state properties to be updated

Returns

Dictionary-like object containing the properties of the updated scheduled operation state

Raises ScheduledOperationStateNotFound if scheduled operation state with the given ID doesn’t exist.

karbor.db.api.scheduled_operation_update(context, id, values)

Set the given properties on a scheduled operation and update it.

Parameters
  • context – The security context

  • id – ID of the scheduled operation

  • values – Dictionary containing scheduled operation properties to be updated

Returns

Dictionary-like object containing the properties of the updated scheduled operation

Raises ScheduledOperationNotFound if scheduled operation with the given ID doesn’t exist.

karbor.db.api.service_create(context, values)

Create a service from the values dictionary.

karbor.db.api.service_destroy(context, service_id)

Destroy the service or raise if it does not exist.

karbor.db.api.service_get(context, service_id)

Get a service or raise if it does not exist.

karbor.db.api.service_get_all(context, disabled=None)

Get all services.

karbor.db.api.service_get_all_by_args(context, host, binary)

Get all services for a given host and binary.

karbor.db.api.service_get_all_by_topic(context, topic, disabled=None)

Get all services for a given topic.

karbor.db.api.service_get_by_args(context, host, binary)

Get the state of an service by node name and binary.

karbor.db.api.service_get_by_host_and_topic(context, host, topic)

Get a service by host it’s on and topic it listens to.

karbor.db.api.service_update(context, service_id, values)

Set the given properties on an service and update it.

Raises NotFound if service does not exist.

karbor.db.api.trigger_create(context, values)

Create a trigger from the values dictionary.

Parameters
  • context – The security context

  • values – Dictionary containing trigger properties

Returns

Dictionary-like object containing the properties of the created trigger

karbor.db.api.trigger_delete(context, id)

Delete a trigger from the database.

Parameters
  • context – The security context

  • id – ID of the trigger

Raises TriggerNotFound if trigger with the given ID doesn’t exist.

karbor.db.api.trigger_execution_create(context, trigger_id, time)
karbor.db.api.trigger_execution_delete(context, id, trigger_id)
karbor.db.api.trigger_execution_get_next(context)
karbor.db.api.trigger_execution_update(context, id, current_time, new_time)
karbor.db.api.trigger_get(context, id)

Get a trigger by its id.

Parameters
  • context – The security context

  • id – ID of the trigger

Returns

Dictionary-like object containing properties of the trigger

Raises TriggerNotFound if trigger with the given ID doesn’t exist.

karbor.db.api.trigger_get_all_by_filters_sort(context, filters, limit=None, marker=None, sort_keys=None, sort_dirs=None)

Get all triggers that match all filters sorted by multiple keys.

sort_keys and sort_dirs must be a list of strings.

karbor.db.api.trigger_update(context, id, values)

Set the given properties on a trigger and update it.

Parameters
  • context – The security context

  • id – ID of the trigger

  • values – Dictionary containing trigger properties to be updated

Returns

Dictionary-like object containing the properties of the updated trigger

Raises TriggerNotFound if trigger with the given ID doesn’t exist.

karbor.db.api.verification_create(context, values)

Create a verification from the values dictionary.

karbor.db.api.verification_destroy(context, verification_id)

Destroy the verification or raise if it does not exist.

karbor.db.api.verification_get(context, verification_id)

Get a verification or raise if it does not exist.

karbor.db.api.verification_get_all(context, marker, limit, sort_keys=None, sort_dirs=None, filters=None, offset=None)

Get all verifications.

karbor.db.api.verification_get_all_by_project(context, project_id, marker, limit, sort_keys=None, sort_dirs=None, filters=None, offset=None)

Get all verifications belonging to a project.

karbor.db.api.verification_update(context, verification_id, values)

Set the given properties on a verification and update it.

Raises NotFound if verification does not exist.

karbor.db.base module

Base class for classes that need modular database access.

class karbor.db.base.Base(db_driver=None)

Bases: object

DB driver is injected in the init method.

karbor.db.migration module

Database setup and migration commands.

karbor.db.migration.db_sync(version=None, init_version=0, engine=None)

Migrate the database to version or the most recent version.

karbor.db.migration.get_backend()

Module contents

DB abstraction for karbor