Compute API¶
For details on how to use compute, see Using OpenStack Compute
The Compute Class¶
The compute high-level interface is available through the compute
member of a Connection object. The
compute member will only be added if the service is detected.
-
class
openstack.compute.v2._proxy.Proxy(session)¶ -
find_extension(name_or_id, ignore_missing=True)¶ Find a single extension
Parameters: - name_or_id – The name or ID of an extension.
- ignore_missing (bool) – When set to
FalseResourceNotFoundwill be raised when the resource does not exist. When set toTrue, None will be returned when attempting to find a nonexistent resource.
Returns: One
Extensionor None
-
extensions()¶ Retrieve a generator of extensions
Returns: A generator of extension instances. Return type: Extension
-
find_flavor(name_or_id, ignore_missing=True)¶ Find a single flavor
Parameters: - name_or_id – The name or ID of a flavor.
- ignore_missing (bool) – When set to
FalseResourceNotFoundwill be raised when the resource does not exist. When set toTrue, None will be returned when attempting to find a nonexistent resource.
Returns: One
Flavoror None
-
create_flavor(**attrs)¶ Create a new flavor from attributes
Parameters: attrs (dict) – Keyword arguments which will be used to create a Flavor, comprised of the properties on the Flavor class.Returns: The results of flavor creation Return type: Flavor
-
delete_flavor(flavor, ignore_missing=True)¶ Delete a flavor
Parameters: - flavor – The value can be either the ID of a flavor or a
Flavorinstance. - ignore_missing (bool) – When set to
FalseResourceNotFoundwill be raised when the flavor does not exist. When set toTrue, no exception will be set when attempting to delete a nonexistent flavor.
Returns: None- flavor – The value can be either the ID of a flavor or a
-
get_flavor(flavor)¶ Get a single flavor
Parameters: flavor – The value can be the ID of a flavor or a Flavorinstance.Returns: One FlavorRaises: ResourceNotFoundwhen no resource can be found.
-
flavors(details=True, **query)¶ Return a generator of flavors
Parameters: - details (bool) – When
True, returnsFlavorDetailobjects, otherwiseFlavor. Default: ``True`` - **query (kwargs) – Optional query parameters to be sent to limit the flavors being returned.
Returns: A generator of flavor objects
- details (bool) – When
-
delete_image(image, ignore_missing=True)¶ Delete an image
Parameters: - image – The value can be either the ID of an image or a
Imageinstance. - ignore_missing (bool) – When set to
FalseResourceNotFoundwill be raised when the image does not exist. When set toTrue, no exception will be set when attempting to delete a nonexistent image.
Returns: None- image – The value can be either the ID of an image or a
-
find_image(name_or_id, ignore_missing=True)¶ Find a single image
Parameters: - name_or_id – The name or ID of a image.
- ignore_missing (bool) – When set to
FalseResourceNotFoundwill be raised when the resource does not exist. When set toTrue, None will be returned when attempting to find a nonexistent resource.
Returns: One
Imageor None
-
get_image(image)¶ Get a single image
Parameters: image – The value can be the ID of an image or a Imageinstance.Returns: One ImageRaises: ResourceNotFoundwhen no resource can be found.
-
images(details=True, **query)¶ Return a generator of images
Parameters: - details (bool) – When
True, returnsImageDetailobjects, otherwiseImage. Default: ``True`` - **query (kwargs) – Optional query parameters to be sent to limit the resources being returned.
Returns: A generator of image objects
- details (bool) – When
-
get_image_metadata(image)¶ Return a dictionary of metadata for an image
Parameters: image – Either the ID of an image or a ImageorImageDetailinstance.Returns: A Imagewith only the image’s metadata. All keys and values are Unicode text.Return type: Image
-
set_image_metadata(image, **metadata)¶ Update metadata for an image
Parameters: - image – Either the ID of an image or a
ImageorImageDetailinstance. - metadata (kwargs) – Key/value pairs to be updated in the image’s metadata. No other metadata is modified by this call. All keys and values are stored as Unicode.
Returns: A
Imagewith only the image’s metadata. All keys and values are Unicode text.Return type: - image – Either the ID of an image or a
-
delete_image_metadata(image, keys)¶ Delete metadata for an image
Note: This method will do a HTTP DELETE request for every key in keys.
Parameters: - image – Either the ID of an image or a
ImageorImageDetailinstance. - keys (list) – The keys to delete.
Return type: None- image – Either the ID of an image or a
-
create_keypair(**attrs)¶ Create a new keypair from attributes
Parameters: attrs (dict) – Keyword arguments which will be used to create a Keypair, comprised of the properties on the Keypair class.Returns: The results of keypair creation Return type: Keypair
-
delete_keypair(keypair, ignore_missing=True)¶ Delete a keypair
Parameters: - keypair – The value can be either the ID of a keypair or a
Keypairinstance. - ignore_missing (bool) – When set to
FalseResourceNotFoundwill be raised when the keypair does not exist. When set toTrue, no exception will be set when attempting to delete a nonexistent keypair.
Returns: None- keypair – The value can be either the ID of a keypair or a
-
get_keypair(keypair)¶ Get a single keypair
Parameters: keypair – The value can be the ID of a keypair or a Keypairinstance.Returns: One KeypairRaises: ResourceNotFoundwhen no resource can be found.
-
find_keypair(name_or_id, ignore_missing=True)¶ Find a single keypair
Parameters: - name_or_id – The name or ID of a keypair.
- ignore_missing (bool) – When set to
FalseResourceNotFoundwill be raised when the resource does not exist. When set toTrue, None will be returned when attempting to find a nonexistent resource.
Returns: One
Keypairor None
-
keypairs()¶ Return a generator of keypairs
Returns: A generator of keypair objects Return type: Keypair
-
get_limits()¶ Retrieve limits that are applied to the project’s account
Returns: A Limits object, including both AbsoluteLimitsandRateLimitsReturn type: Limits
-
create_server(**attrs)¶ Create a new server from attributes
Parameters: attrs (dict) – Keyword arguments which will be used to create a Server, comprised of the properties on the Server class.Returns: The results of server creation Return type: Server
-
delete_server(server, ignore_missing=True, force=False)¶ Delete a server
Parameters: - server – The value can be either the ID of a server or a
Serverinstance. - ignore_missing (bool) – When set to
FalseResourceNotFoundwill be raised when the server does not exist. When set toTrue, no exception will be set when attempting to delete a nonexistent server - force (bool) – When set to
True, the server deletion will be forced immediatly.
Returns: None- server – The value can be either the ID of a server or a
-
find_server(name_or_id, ignore_missing=True)¶ Find a single server
Parameters: - name_or_id – The name or ID of a server.
- ignore_missing (bool) – When set to
FalseResourceNotFoundwill be raised when the resource does not exist. When set toTrue, None will be returned when attempting to find a nonexistent resource.
Returns: One
Serveror None
-
get_server(server)¶ Get a single server
Parameters: server – The value can be the ID of a server or a Serverinstance.Returns: One ServerRaises: ResourceNotFoundwhen no resource can be found.
-
servers(details=True, **query)¶ Retrieve a generator of servers
Parameters: - details (bool) – When set to
FalseServerinstances will be returned. The default,True, will causeServerDetailinstances to be returned. - **query (kwargs) –
Optional query parameters to be sent to limit the servers being returned. Available parameters include:
- changes_since: A time/date stamp for when the server last changed
- status.
- image: An image resource or ID.
- flavor: A flavor resource or ID.
- name: Name of the server as a string. Can be queried with
- regular expressions. The regular expression ?name=bob returns both bob and bobb. If you must match on only bob, you can use a regular expression that matches the syntax of the underlying database server that is implemented for Compute, such as MySQL or PostgreSQL.
- status: Value of the status of the server so that you can filter
- on “ACTIVE” for example.
- host: Name of the host as a string.
- limit: Requests a specified page size of returned items from the
- query. Returns a number of items up to the specified limit value. Use the limit parameter to make an initial limited request and use the ID of the last-seen item from the response as the marker parameter value in a subsequent limited request.
- marker: Specifies the ID of the last-seen item. Use the limit
- parameter to make an initial limited request and use the ID of the last-seen item from the response as the marker parameter value in a subsequent limited request.
Returns: A generator of server instances.
- details (bool) – When set to
-
update_server(server, **attrs)¶ Update a server
Parameters: server – Either the ID of a server or a Serverinstance.Attrs kwargs: The attributes to update on the server represented by server.Returns: The updated server Return type: Server
-
change_server_password(server, new_password)¶ Change the administrator password
Parameters: - server – Either the ID of a server or a
Serverinstance. - new_password (str) – The new password to be set.
Returns: None
- server – Either the ID of a server or a
-
reboot_server(server, reboot_type)¶ Reboot a server
Parameters: - server – Either the ID of a server or a
Serverinstance. - reboot_type (str) – The type of reboot to perform. “HARD” and “SOFT” are the current options.
Returns: None
- server – Either the ID of a server or a
-
rebuild_server(server, name, admin_password, **attrs)¶ Rebuild a server
Parameters: - server – Either the ID of a server or a
Serverinstance. - name (str) – The name of the server
- admin_password (str) – The administrator password
- preserve_ephemeral (bool) – Indicates whether the server is rebuilt with the preservation of the ephemeral partition. Default: False
- image (str) – The id of an image to rebuild with. Default: None
- access_ipv4 (str) – The IPv4 address to rebuild with. Default: None
- access_ipv6 (str) – The IPv6 address to rebuild with. Default: None
- metadata (dict) – A dictionary of metadata to rebuild with. Default: None
- personality (list) – A list of dictionaries, each including a path and contents key, to be injected into the rebuilt server at launch. Default: None
Returns: The rebuilt
Serverinstance.- server – Either the ID of a server or a
-
resize_server(server, flavor)¶ Resize a server
Parameters: Returns: None
-
confirm_server_resize(server)¶ Confirm a server resize
Parameters: server – Either the ID of a server or a Serverinstance.Returns: None
-
revert_server_resize(server)¶ Revert a server resize
Parameters: server – Either the ID of a server or a Serverinstance.Returns: None
-
create_server_image(server, name, metadata=None)¶ Create an image from a server
Parameters: - server – Either the ID of a server or a
Serverinstance. - name (str) – The name of the image to be created.
- metadata (dict) – A dictionary of metadata to be set on the image.
Returns: None
- server – Either the ID of a server or a
-
add_security_group_to_server(server, security_group)¶ Add a security group to a server
Parameters: - server – Either the ID of a server or a
Serverinstance. - security_group – Either the ID of a security group or a
SecurityGroupinstance.
Returns: None
- server – Either the ID of a server or a
-
remove_security_group_from_server(server, security_group)¶ Add a security group to a server
Parameters: - server – Either the ID of a server or a
Serverinstance. - security_group – Either the ID of a security group or a
SecurityGroupinstance.
Returns: None
- server – Either the ID of a server or a
-
create_server_interface(server, **attrs)¶ Create a new server interface from attributes
Parameters: - server – The server can be either the ID of a server or a
Serverinstance that the interface belongs to. - attrs (dict) – Keyword arguments which will be used to create
a
ServerInterface, comprised of the properties on the ServerInterface class.
Returns: The results of server interface creation
Return type: - server – The server can be either the ID of a server or a
-
delete_server_interface(server_interface, server=None, ignore_missing=True)¶ Delete a server interface
Parameters: - server_interface – The value can be either the ID of a server interface or a
ServerInterfaceinstance. - server – This parameter need to be specified when ServerInterface
ID is given as value. It can be either the ID of a
server or a
Serverinstance that the interface belongs to. - ignore_missing (bool) – When set to
FalseResourceNotFoundwill be raised when the server interface does not exist. When set toTrue, no exception will be set when attempting to delete a nonexistent server interface.
Returns: None- server_interface – The value can be either the ID of a server interface or a
-
get_server_interface(server_interface, server=None)¶ Get a single server interface
Parameters: - server_interface – The value can be the ID of a server interface or a
ServerInterfaceinstance. - server – This parameter need to be specified when ServerInterface
ID is given as value. It can be either the ID of a
server or a
Serverinstance that the interface belongs to.
Returns: One
ServerInterfaceRaises: ResourceNotFoundwhen no resource can be found.- server_interface – The value can be the ID of a server interface or a
-
server_interfaces(server)¶ Return a generator of server interfaces
Parameters: server – The server can be either the ID of a server or a Server.Returns: A generator of ServerInterface objects Return type: ServerInterface
-
server_ips(server, network_label=None)¶ Return a generator of server IPs
Parameters: - server – The server can be either the ID of a server or a
Server. - network_label – The name of a particular network to list IP addresses from.
Returns: A generator of ServerIP objects
Return type: - server – The server can be either the ID of a server or a
-
availability_zones(details=False)¶ Return a generator of availability zones
Parameters: details (bool) – Return extra details about the availability zones. This defaults to False as it generally requires extra permission. Returns: A generator of availability zone Return type: :class:`~openstack.compute.v2.availability_zone. AvailabilityZone`
-
get_server_metadata(server)¶ Return a dictionary of metadata for a server
Parameters: server – Either the ID of a server or a ServerorServerDetailinstance.Returns: A Serverwith only the server’s metadata. All keys and values are Unicode text.Return type: Server
-
set_server_metadata(server, **metadata)¶ Update metadata for a server
Parameters: - server – Either the ID of a server or a
ServerorServerDetailinstance. - metadata (kwargs) – Key/value pairs to be updated in the server’s metadata. No other metadata is modified by this call. All keys and values are stored as Unicode.
Returns: A
Serverwith only the server’s metadata. All keys and values are Unicode text.Return type: - server – Either the ID of a server or a
-
delete_server_metadata(server, keys)¶ Delete metadata for a server
Note: This method will do a HTTP DELETE request for every key in keys.
Parameters: Return type: None
-
create_server_group(**attrs)¶ Create a new server group from attributes
Parameters: attrs (dict) – Keyword arguments which will be used to create a ServerGroup, comprised of the properties on the ServerGroup class.Returns: The results of server group creation Return type: ServerGroup
-
delete_server_group(server_group, ignore_missing=True)¶ Delete a server group
Parameters: - server_group – The value can be either the ID of a server group
or a
ServerGroupinstance. - ignore_missing (bool) – When set to
FalseResourceNotFoundwill be raised when the server group does not exist. When set toTrue, no exception will be set when attempting to delete a nonexistent server group.
Returns: None- server_group – The value can be either the ID of a server group
or a
-
find_server_group(name_or_id, ignore_missing=True)¶ Find a single server group
Parameters: - name_or_id – The name or ID of a server group.
- ignore_missing (bool) – When set to
FalseResourceNotFoundwill be raised when the resource does not exist. When set toTrue, None will be returned when attempting to find a nonexistent resource.
Returns: One
ServerGroupobject or None
-
get_server_group(server_group)¶ Get a single server group
Parameters: server_group – The value can be the ID of a server group or a ServerGroupinstance.Returns: A ServerGroupobject.Raises: ResourceNotFoundwhen no resource can be found.
-
server_groups(**query)¶ Return a generator of server groups
Parameters: **query (kwargs) – Optional query parameters to be sent to limit the resources being returned. Returns: A generator of ServerGroup objects Return type: ServerGroup
-
hypervisors()¶ Return a generator of hypervisor
Returns: A generator of hypervisor Return type: class: ~openstack.compute.v2.hypervisor.Hypervisor
-
find_hypervisor(name_or_id, ignore_missing=True)¶ Find a hypervisor from name or id to get the corresponding info
Parameters: name_or_id – The name or id of a hypervisor Returns: One: class:~openstack.compute.v2.hypervisor.Hypervisor object or None
-
get_hypervisor(hypervisor)¶ Get a single hypervisor
Parameters: hypervisor – The value can be the ID of a hypervisor or a Hypervisorinstance.Returns: A Hypervisorobject.Raises: ResourceNotFoundwhen no resource can be found.
-
get_service(service)¶ Get a single service
Parameters: service – The value can be the ID of a serivce or a Serviceinstance.Returns: A Serviceobject.Raises: ResourceNotFoundwhen no resource can be found.
-
force_service_down(service, host, binary)¶ Force a service down
Parameters: - service – Either the ID of a service or a
Serviceinstance. - host (str) – The host where service runs.
- binary (str) – The name of service.
Returns: None
- service – Either the ID of a service or a
-
disable_service(service, host, binary, disabled_reason=None)¶ Disable a service
Parameters: - service – Either the ID of a service or a
Serviceinstance. - host (str) – The host where service runs.
- binary (str) – The name of service.
- disabled_reason (str) – The reason of force down a service.
Returns: None
- service – Either the ID of a service or a
-
enable_service(service, host, binary)¶ Enable a service
Parameters: - service – Either the ID of a service or a
Serviceinstance. - host (str) – The host where service runs.
- binary (str) – The name of service.
Returns: None
- service – Either the ID of a service or a
-
services()¶ Return a generator of service
Returns: A generator of service Return type: class: ~openstack.compute.v2.service.Service
-