Defines interface for DB access.
The underlying driver is loaded as a LazyPluggable.
Functions in this module are imported into the nova.db namespace. Call these functions from nova.db namespace, not the nova.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
db_backend: | string to lookup in the list of LazyPluggable backends. sqlalchemy is the only supported backend right now. |
---|---|
connection: | string specifying the sqlalchemy connection to use, like: sqlite:///var/lib/nova/nova.sqlite. |
enable_new_services: | |
when adding a new service to the database, is it in the pool of available hardware (Default: True) |
Bases: nova.exception.NovaException
No more available networks.
Bases: nova.exception.NovaException
No more available targets.
Finish an event on an instance action.
Start an event on an instance action.
Get the events by action id.
Finish an action for an instance.
Get the action by request_id and given instance.
Start an action for an instance.
Get all instance actions for the provided instance.
Create a new agent build entry.
Destroy agent build entry.
Get all agent builds.
Get agent build by hypervisor/OS/architecture triple.
Update agent build entry.
Create a new aggregate with metadata.
Delete an aggregate.
Get a specific aggregate by id.
Get all aggregates.
Get a list of aggregates that host belongs to.
Add host to the aggregate.
Delete the given host from the aggregate.
Get hosts for the specified aggregate.
Get hosts with a specific metadata key metadata for all aggregates.
Returns a dictionary where each key is a hostname and each value is a set of the key values return value: {machine: set( az1, az2 )}
Add/update metadata. If set_delete=True, it adds only.
Delete the given metadata key.
Get metadata for the specified aggregate.
Get metadata for all aggregates that host belongs to.
Returns a dictionary where each value is a set, this is to cover the case where there two aggregates have different values for the same key. Optional key filter
Get metadata for an aggregate by metadata key.
Update the attributes of an aggregates.
If values contains a metadata key, it updates the aggregate metadata too.
Move up to max_rows rows from production tables to corresponding shadow tables.
Returns: | number of rows archived. |
---|
Move up to max_rows rows from tablename to corresponding shadow table.
Returns: | number of rows archived. |
---|
Create an entry of block device mapping.
Destroy the block device mapping.
Destroy the block device mapping.
Destroy the block device mapping.
Get all block device mapping belonging to an instance.
Get block device mapping for a given volume.
Update an entry of block device mapping.
Update an entry of block device mapping.
If not existed, create a new entry
Return bw usage for instance and mac in a given audit period.
Return bw usages for instance(s) in a given audit period.
Update cached bandwidth usage for an instance’s network based on mac address. Creates new record if needed.
Create a new child Cell entry.
Delete a child Cell.
Get a specific child Cell.
Get all child Cells.
Update a child Cell entry.
Create a certificate from the values dictionary.
Get all certificates for a project.
Get all certificates for a user.
Get all certificates for a user and project.
Create a computeNode from the values dictionary.
Delete a computeNode from the database.
Raises ComputeHostNotFound if computeNode does not exist.
Get a computeNode.
Get all computeNodes.
Parameters: |
|
---|---|
Returns: | List of dictionaries each containing compute node properties, including corresponding service and stats |
Get a computeNode by its associated service’s id.
Get computeNodes given a hypervisor hostname match string.
Set the given properties on a computeNode and update it.
Raises ComputeHostNotFound if computeNode does not exist.
Create a console.
Delete a console.
Get a specific console (possibly on a given instance).
Get consoles for a given instance.
Get console entry for a given instance and pool.
Create console pool.
Fetch all pools for given proxy host and type.
Fetch a console pool for a given proxy host, compute host, and type.
Return a constraint object suitable for use with some updates.
Get the db record for the specified domain.
Get a list of all zones in our database, public and private.
Associated a DNS domain with a project id.
Associated a DNS domain with an availability zone.
Purge associations for the specified DNS zone.
Create the ec2 id to instance uuid mapping on demand.
Return an equality condition object suitable for use in a constraint.
Equal_any conditions require that a model object’s attribute equal any one of the given values.
Associate fixed ip to instance.
Raises if fixed ip is not available.
Find free ip in network and associate it to instance or host.
Raises if one is not available.
Create a lot of fixed ips from the values dictionary.
Create a fixed ip from the values dictionary.
Disassociate a fixed ip from an instance by address.
Disassociate old fixed ips from host.
Get fixed ip by id or raise if it does not exist.
If get_network is true, also return the assocated network.
Get all defined fixed ips.
Get a fixed ip by address or raise if it does not exist.
Get detailed fixed ip info by address or raise if it does not exist.
Get a fixed ip by a floating address.
Get fixed ips by compute host.
Get fixed ips by instance or raise if none exist.
Get fixed ip for a host in a network.
Create a fixed ip from the values dictionary.
Get fixed ips by virtual interface or raise if none exist.
Add flavor access for project.
Get flavor access by flavor id.
Remove flavor access for project.
Create a new instance type.
Delete an instance type.
Delete the given extra specs item.
Get all extra specs for an instance type.
Get extra specs by key and flavor_id.
Create or update instance type extra specs.
This adds or modifies the key/value pairs specified in the extra specs dict argument
Get instance type by id.
Get all instance flavors.
Get instance type by flavor id.
Get instance type by name.
Allocate free floating ip from specified pool and return the address.
Raises if one is not available.
Create a lot of floating ips from the values dictionary.
Destroy a lot of floating ips from the values dictionary.
Create a floating ip from the values dictionary.
Deallocate a floating ip by address.
Destroy the floating_ip or raise if it does not exist.
Disassociate a floating ip from a fixed ip by address.
Returns: | the fixed ip record joined to network record or None if the ip was not associated to an ip. |
---|
Associate a floating ip to a fixed_ip by address.
Returns: | the fixed ip record joined to network record or None if the ip was already associated to the fixed ip. |
---|
Get all floating ips.
Get all floating ips by host.
Get all floating ips by project.
Get a floating ip by address or raise if it doesn’t exist.
Get a floating ips by fixed address.
Get a floating ips by fixed address.
Returns a list of floating ip pools.
Set auto_assigned flag to floating ip.
Update a floating ip by address or raise if it doesn’t exist.
Get ec2 id through uuid from instance_id_mappings table.
Get uuid through ec2 id from instance_id_mappings table.
Associate the given security group with the given instance.
Create an instance from the values dictionary.
Destroy the instance or raise if it does not exist.
Create a new Instance Fault.
Get all instance faults for the provided instance_uuids.
Get all floating ip addresses of an instance.
Get an instance or raise if it does not exist.
Get instances and joins active during a certain time window.
Specifying a project_id will filter for a certain project. Specifying a host will filter for instances on a given compute host.
Get all instances.
Get all instances that match all filters.
Get all instances belonging to a host.
Get all instances belonging to a node.
Get all instances belonging to a host with a different type_id.
Get all instances stuck in a rebooting state.
Get an instance or raise if it does not exist.
Get the first floating ip address of an instance.
Create a new group with metadata.
Each group will receive a unique uuid. This will be used for access to the group.
Delete an group.
Get a specific group by id.
Get all groups.
Get all groups for a specific project_id.
Delete a specific member from the group.
Add members to the group.
Get the members from the group.
Add metadata to the group.
Delete metadata from the group.
Get the metadata from the group.
Add policies to the group.
Get the policies from the group.
Delete a specific policy from the group.
Update the attributes of an group.
Deletes an existing instance_info_cache record
Parameters: | instance_uuid – = uuid of the instance tied to the cache record |
---|
Gets an instance info cache from the table.
Parameters: | instance_uuid – = uuid of the info cache’s instance |
---|
Update an instance info cache record in the table.
Parameters: |
|
---|
Delete the given metadata item.
Get all metadata for an instance.
Update metadata if it exists, otherwise create it.
Disassociate the given security group from the given instance.
Get all system metadata for an instance.
Update metadata if it exists, otherwise create it.
Add flavor access for project.
Get flavor access by flavor id.
Remove flavor access for project.
Create a new instance type.
Delete an instance type.
Delete the given extra specs item.
Get all extra specs for an instance type.
Get extra specs by key and flavor_id.
Create or update instance type extra specs.
This adds or modifies the key/value pairs specified in the extra specs dict argument
Get instance type by id.
Get all instance flavors.
Get instance type by flavor id.
Get instance type by name.
Set the given properties on an instance and update it.
Raises NotFound if instance does not exist.
Set the given properties on an instance and update it. Return a shallow copy of the original instance reference, as well as the updated one.
Parameters: |
|
---|---|
Returns: | a tuple of the form (old_instance_ref, new_instance_ref) |
Raises NotFound if instance does not exist.
Count number of key pairs for the given user ID.
Create a key_pair from the values dictionary.
Destroy the key_pair or raise if it does not exist.
Get a key_pair or raise if it does not exist.
Get all key_pairs by user.
Create a migration record.
Finds a migration by the id.
Finds all migrations in progress.
Finds a migration by the instance uuid its migrating.
Finds all migrations for the given host + node that are not yet confirmed or reverted.
Finds all unconfirmed migrations within the confirmation window for a specific destination compute host.
Update a migration instance.
Associate a free network to a project.
Return the number of reserved ips in the network.
Create a network from the values dict.
The network is only returned if the create succeeds. If the create violates constraints because the network already exists, no exception is raised.
Delete network with key network_id.
This method assumes that the network is not associated with any project
Disassociate the network from project or host
Raises if it does not exist.
Get a network or raise if it does not exist.
Return all defined networks.
All networks for which the given host is the network host.
Return networks by ids.
Get all network’s ips that have been associated.
Get a network by cidr or raise if it does not exist.
Get a network by uuid or raise if it does not exist.
Indicates if a network is currently in use on host.
Safely set the host for network.
Set the given properties on a network and update it.
Raises NotFound if network does not exist.
Return an inequality condition object suitable for use in a constraint.
Not_equal conditions require that a model object’s attribute differs from all of the given values.
Delete a PCI device record.
Get PCI devices allocated to instance.
Get all PCI devices for one host.
Get PCI device by address.
Get PCI device by id.
Update a pci device.
Return the network associated with the project.
If associate is true, it will attempt to associate a new network if one is not found, otherwise it returns None.
Add a firewall rule at the provider level (all hosts & instances).
Delete a provider firewall rule from the database.
Get all provider-level firewall rules.
Create a quota class for the given name and resource.
Retrieve a quota class or raise if it does not exist.
Retrieve all quotas associated with a given quota class.
Retrieve all default quotas.
Update a quota class or raise if it does not exist.
Create a quota for the given project and resource.
Destroy all quotas associated with a given project.
Destroy all quotas associated with a given project and user.
Retrieve a quota or raise if it does not exist.
Retrieve all user quotas associated with a given project.
Retrieve all quotas associated with a given project.
Retrieve all quotas associated with a given project and user.
Check quotas and create appropriate reservations.
Update a quota or raise if it does not exist.
Retrieve a quota usage or raise if it does not exist.
Retrieve all usage associated with a given resource.
Retrieve all usage associated with a given resource.
Update a quota usage or raise if it does not exist.
Commit quota reservations.
Create a reservation for the given project and resource.
Roll back any expired reservations.
Retrieve a reservation or raise if it does not exist.
Roll back quota reservations.
Create local s3 image represented by provided uuid.
Find local s3 image represented by the provided id.
Find local s3 image represented by the provided uuid.
Create a new security group.
Deletes a security group.
Ensure default security group exists for a project_id.
Returns a tuple with the first element being a bool indicating if the default security group previously existed. Second element is the dict used to create the default security group.
Get security group by its id.
Get all security groups.
Get security groups to which the instance is assigned.
Returns a security group with the specified name from a project.
Get all security groups belonging to a project.
Indicates if a security group is currently in use.
Count rules in a given security group.
Create a new security group.
Deletes a security group rule.
Gets a security group rule.
Get all rules for a given security group.
Get all rules that grant access to the given security group.
Update a security group.
Create a service from the values dictionary.
Destroy the service or raise if it does not exist.
Get a service or raise if it does not exist.
Get all services.
Get all services for a given host.
Get all services for a given topic.
Get the state of a service by node name and binary.
Get the service entry for a given compute host.
Returns the service entry joined with the compute_node entry.
Get a service by host it’s on and topic it listens to.
Set the given properties on a service and update it.
Raises NotFound if service does not exist.
Mark a task as started for a given host/time period.
Mark a task as complete for a given host/time period.
Create a virtual interface record in the database.
Delete virtual interface records associated with instance.
Gets a virtual interface from the table.
Gets all virtual interfaces from the table.
Gets a virtual interface from the table filtering on address.
Gets all virtual_interfaces for instance.
Gets all virtual interfaces for instance.
Gets a virtual interface from the table filtering on vif uuid.
Return volumes usage that have been updated after a specified time.
Update cached volume usage for a volume
Creates new record if needed.
Implementation of SQLAlchemy backend.
SQLAlchemy models for nova data.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents an agent build.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a cluster of hosts that exists in this zone.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a host that is member of an aggregate.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a metadata key/value pair for an aggregate.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Cache for instance bandwidth usage data pulled from the hypervisor.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents block device mapping that is defined by EC2.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents parent and child cells of this cell. Cells can have multiple parents and children, so there could be any number of entries with is_parent=True or False
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a x509 certificate.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a running compute service on a host.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Stats related to the current workload of a compute host that are intended to aid in making scheduler decisions.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a console session for an instance.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents pool of consoles on the same physical node.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a DNS domain with availability zone or project info.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a fixed ip for an instance.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a floating ip that dynamically forwards to a fixed ip.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a guest VM.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Track client actions on an instance.
The intention is that there will only be one of these per user request. A lookup by (instance_uuid, request_id) should always return a single result.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Track events that occur during an InstanceAction.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents an instance group.
A group will maintain a collection of instances and the relationship between them.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents the members for an instance group.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a key/value pair for an instance group.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents the policy type for an instance group.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Compatibility layer for the EC2 instance service.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a cache of information about an instance
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a user-provided metadata key/value pair for an instance.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a system-owned metadata key/value pair for an instance.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents additional specs as key/value pairs for an instance_type.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represent projects associated instance_types.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents possible flavors for instances.
Note: instance_type and flavor are synonyms and the term instance_type is deprecated and in the process of being removed.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents an iscsi target for a given host.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a public key pair for ssh.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a running host-to-host migration.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a network.
Bases: nova.openstack.common.db.sqlalchemy.models.SoftDeleteMixin, nova.openstack.common.db.sqlalchemy.models.TimestampMixin, nova.openstack.common.db.sqlalchemy.models.ModelBase
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a PCI host device that can be passed through to instances.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a single quota override for a user with in a project.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a rule in a security group.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a single quota override for a project.
If there is no row for a given project id and resource, then the default for the quota class is used. If there is no row for a given quota class and resource, then the default for the deployment is used. If the row is present but the hard limit is Null, then the resource is unlimited.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a single quota override for a quota class.
If there is no row for a given quota class and resource, then the default for the deployment is used. If the row is present but the hard limit is Null, then the resource is unlimited.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents the current usage for a given resource.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a resource reservation for quotas.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Compatibility layer for the S3 image service talking to Glance.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a security group.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a rule in a security group.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a running service on a host.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a block storage device that can be attached to a VM.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Compatibility layer for the EC2 snapshot service.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Audit log for background periodic tasks.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a virtual interface on an instance.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Represents a block storage device that can be attached to a VM.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Compatibility layer for the EC2 volume service.
Bases: sqlalchemy.ext.declarative.api.Base, nova.db.sqlalchemy.models.NovaBase
Cache for volume usage data pulled from the hypervisor.
Provide a relationship between two mapped classes.
This corresponds to a parent-child or associative table relationship. The constructed class is an instance of RelationshipProperty.
A typical relationship(), used in a classical mapping:
mapper(Parent, properties={
'children': relationship(Child)
})
Some arguments accepted by relationship() optionally accept a callable function, which when called produces the desired value. The callable is invoked by the parent Mapper at “mapper initialization” time, which happens only when mappers are first used, and is assumed to be after all mappings have been constructed. This can be used to resolve order-of-declaration and other dependency issues, such as if Child is declared below Parent in the same file:
mapper(Parent, properties={
"children":relationship(lambda: Child,
order_by=lambda: Child.id)
})
When using the declarative_toplevel extension, the Declarative initializer allows string arguments to be passed to relationship(). These string arguments are converted into callables that evaluate the string as Python code, using the Declarative class-registry as a namespace. This allows the lookup of related classes to be automatic via their string name, and removes the need to import related classes at all into the local module space:
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Parent(Base):
__tablename__ = 'parent'
id = Column(Integer, primary_key=True)
children = relationship("Child", order_by="Child.id")
See also
relationship_config_toplevel - Full introductory and reference documentation for relationship().
orm_tutorial_relationship - ORM tutorial introduction.
Parameters: |
|
---|
Tests are lacking for the db api layer and for the sqlalchemy driver. Failures in the drivers would be detected in other test cases, though.