octavia.db package

octavia.db package

Submodules

octavia.db.api module

get_engine()[source]
get_lock_session(*args, **kwds)[source]

Context manager for using a locking (not auto-commit) session.

get_session(expire_on_commit=True, autocommit=True)[source]

Helper method to grab session.

octavia.db.base_models module

class IdMixin[source]

Bases: object

Id mixin, add to subclasses that have an id.

id = Column(None, String(length=36), table=None, primary_key=True, nullable=False, default=ColumnDefault(<function generate_uuid>))
class LookupTableMixin[source]

Bases: object

Mixin to add to classes that are lookup tables.

description = Column(None, String(length=255), table=None)
name = Column(None, String(length=255), table=None, primary_key=True, nullable=False)
class NameMixin[source]

Bases: object

Name mixin to add to classes which need a name.

name = Column(None, String(length=255), table=None)
class OctaviaBase[source]

Bases: oslo_db.sqlalchemy.models.ModelBase

static apply_filter(query, model, filters)[source]
to_data_model(_graph_nodes=None)[source]

Converts to a data model graph.

In order to make the resulting data model graph usable no matter how many internal references are followed, we generate a complete graph of OctaviaBase nodes connected to the object passed to this method.

Parameters:_graph_nodes – Used only for internal recursion of this method. Should not be called from the outside. Contains a dictionary of all OctaviaBase type objects in the generated graph
class ProjectMixin[source]

Bases: object

Tenant mixin, add to subclasses that have a project.

project_id = Column(None, String(length=36), table=None)

octavia.db.models module

class Algorithm(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.LookupTableMixin

description
name
class Amphora(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.IdMixin

cert_busy
cert_expiration
compute_id
ha_ip
ha_port_id
id
lb_network_ip
load_balancer_id
role
status
vrrp_id
vrrp_interface
vrrp_ip
vrrp_port_id
vrrp_priority
class AmphoraBuildRequest(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

amphora_id
created_time
priority
status
class AmphoraBuildSlots(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

id
slots_used
class AmphoraHealth(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

amphora_id
busy
last_update
class AmphoraRoles(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.LookupTableMixin

description
name
class HealthMonitor(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.IdMixin, octavia.db.base_models.ProjectMixin, oslo_db.sqlalchemy.models.TimestampMixin, octavia.db.base_models.NameMixin

created_at
delay
enabled
expected_codes
fall_threshold
http_method
id
name
operating_status
pool
pool_id
project_id
provisioning_status
rise_threshold
timeout
type
updated_at
url_path
class HealthMonitorType(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.LookupTableMixin

description
name
class L7Policy(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.IdMixin, octavia.db.base_models.ProjectMixin, oslo_db.sqlalchemy.models.TimestampMixin, octavia.db.base_models.NameMixin

action
created_at
description
enabled
id
listener
listener_id
name
operating_status
position
project_id
provisioning_status
redirect_pool
redirect_pool_id
redirect_url
updated_at
class L7PolicyAction(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.LookupTableMixin

description
name
class L7Rule(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.IdMixin, octavia.db.base_models.ProjectMixin, oslo_db.sqlalchemy.models.TimestampMixin

compare_type
created_at
enabled
id
invert
key
l7policy
l7policy_id
operating_status
project_id
provisioning_status
type
updated_at
value
class L7RuleCompareType(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.LookupTableMixin

description
name
class L7RuleType(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.LookupTableMixin

description
name
class LBTopology(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.LookupTableMixin

description
name
class Listener(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.IdMixin, octavia.db.base_models.ProjectMixin, oslo_db.sqlalchemy.models.TimestampMixin, octavia.db.base_models.NameMixin

connection_limit
created_at
default_pool
default_pool_id
description
enabled
id
insert_headers
load_balancer
load_balancer_id
name
operating_status
peer_port
pools
project_id
protocol
protocol_port
provisioning_status
tls_certificate_id
updated_at
class ListenerStatistics(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

active_connections
amphora_id
bytes_in
bytes_out
listener_id
request_errors
total_connections
validate_non_negative_int(key, value)[source]
class LoadBalancer(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.IdMixin, octavia.db.base_models.ProjectMixin, oslo_db.sqlalchemy.models.TimestampMixin, octavia.db.base_models.NameMixin

amphorae
created_at
description
enabled
id
name
operating_status
project_id
provisioning_status
server_group_id
topology
updated_at
class Member(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.IdMixin, octavia.db.base_models.ProjectMixin, oslo_db.sqlalchemy.models.TimestampMixin, octavia.db.base_models.NameMixin

created_at
enabled
id
ip_address
monitor_address
monitor_port
name
operating_status
pool
pool_id
project_id
protocol_port
provisioning_status
subnet_id
updated_at
weight
class OperatingStatus(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.LookupTableMixin

description
name
class Pool(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.IdMixin, octavia.db.base_models.ProjectMixin, oslo_db.sqlalchemy.models.TimestampMixin, octavia.db.base_models.NameMixin

created_at
description
enabled
id
lb_algorithm
listeners
load_balancer
load_balancer_id
name
operating_status
project_id
protocol
provisioning_status
updated_at
class Protocol(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.LookupTableMixin

description
name
class ProvisioningStatus(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.LookupTableMixin

description
name
class Quotas(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

health_monitor
in_use_health_monitor
in_use_listener
in_use_load_balancer
in_use_member
in_use_pool
listener
load_balancer
member
pool
project_id
class SNI(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

listener
listener_id
position
tls_container_id
class SessionPersistence(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

cookie_name
pool
pool_id
type
class SessionPersistenceType(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.LookupTableMixin

description
name
class VRRPAuthMethod(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base, octavia.db.base_models.LookupTableMixin

description
name
class VRRPGroup(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

advert_int
load_balancer
load_balancer_id
vrrp_auth_pass
vrrp_auth_type
vrrp_group_name
class Vip(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

ip_address
load_balancer
load_balancer_id
network_id
port_id
subnet_id

octavia.db.prepare module

create_health_monitor(hm_dict, pool_id=None)[source]
create_l7policy(l7policy_dict, lb_id, listener_id)[source]
create_l7rule(l7rule_dict, l7policy_id)[source]
create_listener(listener_dict, lb_id)[source]
create_load_balancer(lb_dict)[source]
create_load_balancer_tree(lb_dict)[source]
create_member(member_dict, pool_id, has_health_monitor=False)[source]
create_pool(pool_dict, lb_id=None)[source]

octavia.db.repositories module

Defines interface for DB access that Resource or Octavia Controllers may reference

class AmphoraBuildReqRepository[source]

Bases: octavia.db.repositories.BaseRepository

add_to_build_queue(session, amphora_id=None, priority=None)[source]

Adds the build request to the table.

delete_all(session)[source]

Deletes all the build requests.

get_highest_priority_build_req(session)[source]

Fetches build request with highest priority and least created_time.

priority 20 = failover (highest) priority 40 = create_loadbalancer priority 60 = sparespool (least) :param session: A Sql Alchemy database session. :returns amphora_id corresponding to highest priority and least created time in ‘WAITING’ status.

model_class

alias of AmphoraBuildRequest

update_req_status(session, amphora_id=None)[source]

Updates the request status.

class AmphoraBuildSlotsRepository[source]

Bases: octavia.db.repositories.BaseRepository

get_used_build_slots_count(session)[source]

Gets the number of build slots in use.

Returns:Number of current build slots.
model_class

alias of AmphoraBuildSlots

update_count(session, action='increment')[source]

Increments/Decrements/Resets the number of build_slots used.

class AmphoraHealthRepository[source]

Bases: octavia.db.repositories.BaseRepository

check_amphora_expired(session, amphora_id, exp_age=None)[source]

check if a specific amphora is expired

Parameters:
  • session – A Sql Alchemy database session.
  • amphora_id – id of an amphora object
  • exp_age – A standard datetime delta which is used to see for how long can an amphora live without updates before it is considered expired (default: CONF.house_keeping.amphora_expiry_age)
Returns:

boolean

get_stale_amphora(session)[source]

Retrieves a staled amphora from the health manager database.

Parameters:session – A Sql Alchemy database session.
Returns:[octavia.common.data_model]
model_class

alias of AmphoraHealth

replace(session, amphora_id, **model_kwargs)[source]

replace or insert amphora into database.

update(session, amphora_id, **model_kwargs)[source]

Updates a healthmanager entity in the database by amphora_id.

class AmphoraRepository[source]

Bases: octavia.db.repositories.BaseRepository

allocate_and_associate(session, load_balancer_id)[source]

Allocate an amphora for a load balancer.

For v0.5 this is simple, find a free amp and associate the lb. In the future this needs to be enhanced.

Parameters:
  • session – A Sql Alchemy database session.
  • load_balancer_id – The load balancer id to associate
Returns:

The amphora ID for the load balancer or None

associate(session, load_balancer_id, amphora_id)[source]

Associates an amphora with a load balancer.

Parameters:
  • session – A Sql Alchemy database session.
  • load_balancer_id – The load balancer id to associate
  • amphora_id – The amphora id to associate
get_all_lbs_on_amphora(session, amphora_id)[source]

Get all of the load balancers on an amphora.

Parameters:
  • session – A Sql Alchemy database session.
  • amphora_id – The amphora id to list the load balancers from
Returns:

[octavia.common.data_model]

get_cert_expiring_amphora(session)[source]

Retrieves an amphora whose cert is close to expiring..

Parameters:session – A Sql Alchemy database session.
Returns:one amphora with expiring certificate
get_spare_amphora_count(session)[source]

Get the count of the spare amphora.

Returns:Number of current spare amphora.
model_class

alias of Amphora

class BaseRepository[source]

Bases: object

count(session, **filters)[source]

Retrieves a count of entities from the database.

Parameters:
  • session – A Sql Alchemy database session.
  • filters – Filters to decide which entities should be retrieved.
Returns:

int

create(session, **model_kwargs)[source]

Base create method for a database entity.

Parameters:
  • session – A Sql Alchemy database session.
  • model_kwargs – Attributes of the model to insert.
Returns:

octavia.common.data_model

delete(session, **filters)[source]

Deletes an entity from the database.

Parameters:
  • session – A Sql Alchemy database session.
  • filters – Filters to decide which entity should be deleted.
Returns:

None

Raises:

sqlalchemy.orm.exc.NoResultFound

delete_batch(session, ids=None)[source]

Batch deletes by entity ids.

exists(session, id)[source]

Determines whether an entity exists in the database by its id.

Parameters:
  • session – A Sql Alchemy database session.
  • id – id of entity to check for existence.
Returns:

octavia.common.data_model

get(session, **filters)[source]

Retrieves an entity from the database.

Parameters:
  • session – A Sql Alchemy database session.
  • filters – Filters to decide which entity should be retrieved.
Returns:

octavia.common.data_model

get_all(session, pagination_helper=None, **filters)[source]

Retrieves a list of entities from the database.

Parameters:
  • session – A Sql Alchemy database session.
  • pagination_helper – Helper to apply pagination and sorting.
  • filters – Filters to decide which entities should be retrieved.
Returns:

[octavia.common.data_model]

model_class = None
update(session, id, **model_kwargs)[source]

Updates an entity in the database.

Parameters:
  • session – A Sql Alchemy database session.
  • model_kwargs – Entity attributes that should be updates.
Returns:

octavia.common.data_model

class HealthMonitorRepository[source]

Bases: octavia.db.repositories.BaseRepository

model_class

alias of HealthMonitor

class L7PolicyRepository[source]

Bases: octavia.db.repositories.BaseRepository

create(session, **model_kwargs)[source]
delete(session, id, **filters)[source]
get_all(session, pagination_helper=None, **filters)[source]
model_class

alias of L7Policy

update(session, id, **model_kwargs)[source]
class L7RuleRepository[source]

Bases: octavia.db.repositories.BaseRepository

create(session, **model_kwargs)[source]
model_class

alias of L7Rule

update(session, id, **model_kwargs)[source]
class ListenerRepository[source]

Bases: octavia.db.repositories.BaseRepository

create(session, **model_kwargs)[source]

Creates a new Listener with some validation.

has_default_pool(session, id)[source]

Checks if a listener has a default pool.

model_class

alias of Listener

update(session, id, **model_kwargs)[source]
class ListenerStatisticsRepository[source]

Bases: octavia.db.repositories.BaseRepository

model_class

alias of ListenerStatistics

replace(session, listener_id, amphora_id, **model_kwargs)[source]

replace or insert listener into database.

update(session, listener_id, **model_kwargs)[source]

Updates a listener’s statistics by a listener’s id.

class LoadBalancerRepository[source]

Bases: octavia.db.repositories.BaseRepository

check_load_balancer_expired(session, lb_id, exp_age=None)[source]

Checks if a given load balancer is expired.

Parameters:
  • session – A Sql Alchemy database session.
  • lb_id – id of an load balancer object
  • exp_age – A standard datetime delta which is used to see for how long can a load balancer live without updates before it is considered expired (default: CONF.house_keeping.load_balancer_expiry_age)
Returns:

boolean

model_class

alias of LoadBalancer

test_and_set_provisioning_status(session, id, status, raise_exception=False)[source]

Tests and sets a load balancer and provisioning status.

Puts a lock on the load balancer table to check the status of a load balancer. If the status is ACTIVE then the status of the load balancer is updated and the method returns True. If the status is not ACTIVE, then nothing is done and False is returned.

Parameters:
  • session – A Sql Alchemy database session.
  • id – id of Load Balancer
  • status – Status to set Load Balancer if check passes.
  • raise_exception – If True, raise ImmutableObject on failure
Returns:

bool

class MemberRepository[source]

Bases: octavia.db.repositories.BaseRepository

delete_members(session, member_ids)[source]

Batch deletes members from a pool.

model_class

alias of Member

class PoolRepository[source]

Bases: octavia.db.repositories.BaseRepository

model_class

alias of Pool

class QuotasRepository[source]

Bases: octavia.db.repositories.BaseRepository

delete(session, project_id)[source]
model_class

alias of Quotas

update(session, project_id, **model_kwargs)[source]
class Repositories[source]

Bases: object

check_quota_met(session, lock_session, _class, project_id, count=1)[source]

Checks and updates object quotas.

This method makes sure the project has available quota for the resource and updates the quota to reflect the new ussage.

Parameters:
  • session – Context database session
  • lock_session – Locking database session (autocommit=False)
  • _class – Data model object requesting quota
  • project_id – Project ID requesting quota
  • count – Number of objects we’re going to create (default=1)
Returns:

True if quota is met, False if quota was available

create_load_balancer_and_vip(session, lb_dict, vip_dict)[source]

Inserts load balancer and vip entities into the database.

Inserts load balancer and vip entities into the database in one transaction and returns the data model of the load balancer.

Parameters:
  • session – A Sql Alchemy database session.
  • lb_dict – Dictionary representation of a load balancer
  • vip_dict – Dictionary representation of a vip
Returns:

octava.common.data_models.LoadBalancer

create_load_balancer_tree(session, lock_session, lb_dict)[source]
create_pool_on_load_balancer(session, pool_dict, listener_id=None)[source]

Inserts a pool and session persistence entity into the database.

Parameters:
  • session – A Sql Alchemy database session.
  • pool_dict – Dictionary representation of a pool
  • listener_id – Optional listener id that will reference this pool as its default_pool_id
Returns:

octavia.common.data_models.Pool

decrement_quota(lock_session, _class, project_id, quantity=1)[source]

Decrements the object quota for a project

Parameters:
  • lock_session – Locking database session (autocommit=False)
  • _class – Data model object to decrement quota
  • project_id – Project ID to decrement quota on
  • quantity – Quantity of quota to decrement
Returns:

None

test_and_set_lb_and_listeners_prov_status(session, lb_id, lb_prov_status, listener_prov_status, listener_ids=None, pool_id=None, l7policy_id=None)[source]

Tests and sets a load balancer and listener provisioning status.

Puts a lock on the load balancer table to check the status of a load balancer. If the status is ACTIVE then the status of the load balancer and listener is updated and the method returns True. If the status is not ACTIVE, then nothing is done and False is returned.

Parameters:
  • session – A Sql Alchemy database session.
  • lb_id – ID of the Load Balancer to check and lock
  • lb_prov_status – Status to set Load Balancer and Listener if check passes.
  • listener_prov_status – Status to set Listeners if check passes
  • listener_ids – List of IDs of listeners to check and lock (only use this when relevant to the operation)
  • pool_id – ID of the Pool to check and lock (only use this when relevant to the operation)
  • l7policy_id – ID of the L7Policy to check and lock (only use this when relevant to the operation)
Returns:

bool

update_pool_and_sp(session, pool_id, pool_dict)[source]

Updates a pool and session persistence entity in the database.

Parameters:
  • session – A Sql Alchemy database session.
  • pool_dict – Dictionary representation of a pool
Returns:

octavia.common.data_models.Pool

class SNIRepository[source]

Bases: octavia.db.repositories.BaseRepository

model_class

alias of SNI

update(session, listener_id=None, tls_container_id=None, **model_kwargs)[source]

Updates an SNI entity in the database.

class SessionPersistenceRepository[source]

Bases: octavia.db.repositories.BaseRepository

exists(session, pool_id)[source]

Checks if session persistence exists on a pool.

model_class

alias of SessionPersistence

update(session, pool_id, **model_kwargs)[source]

Updates a session persistence entity in the database by pool_id.

class VRRPGroupRepository[source]

Bases: octavia.db.repositories.BaseRepository

model_class

alias of VRRPGroup

update(session, load_balancer_id, **model_kwargs)[source]

Updates a VRRPGroup entry for by load_balancer_id.

class VipRepository[source]

Bases: octavia.db.repositories.BaseRepository

model_class

alias of Vip

update(session, load_balancer_id, **model_kwargs)[source]

Updates a vip entity in the database by load_balancer_id.

Module contents

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.