Compute API

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.

Server Operations

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
create_server(**attrs)

Create a new Server from attributes

Parameters:attrs (dict) – Keyword arguments which will be used to create a Server.
Returns:The results of Server creation
Return type:Server
update_server(server, **attrs)

Update a server

Parameters:server – Either the ID of a server or a Server instance.
Attrs kwargs:The attributes to update on the server represented by server.
Returns:The updated server
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 Server instance.
  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the server does not exist. When set to True, no exception will be set when attempting to delete a nonexistent server
  • force (bool) – When set to True, the server deletion will be forced immediately.
Returns:

None

get_server(server)

Get a single Server

Parameters:server – The value can be the ID of a server or a Server instance.
Returns:One Server
Raises:ResourceNotFound when no resource can be found.
find_server(name_or_id, ignore_missing=True)

Find a single Server

Parameters:
  • name_or_id – The name or ID of an Server.
  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the resource does not exist. When set to True, None will be returned when attempting to find a nonexistent resource.
Returns:

One Server or None

servers(details=True, **query)

Retrieve a generator of servers

Parameters:
  • details (bool) – When set to False Server instances will be returned. The default, True, will cause ServerDetail instances 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.

get_server_metadata(server)

Return a dictionary of metadata for a server

Parameters:server – Either the ID of a server or a Server or ServerDetail instance.
Returns:A Server with 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 Server or ServerDetail instance.
  • 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 Server with only the server’s metadata. All keys and values are Unicode text.

Return type:

Server

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:
  • server – Either the ID of a server or a Server or ServerDetail instance.
  • keys – The keys to delete
Return type:

None

wait_for_server(server, status='ACTIVE', failures=['ERROR'], interval=2, wait=120)
create_server_image(server, name, metadata=None)

Create an image from a server

Parameters:
  • server – Either the ID of a server or a Server instance.
  • name (str) – The name of the image to be created.
  • metadata (dict) – A dictionary of metadata to be set on the image.
Returns:

None

backup_server(server, name, backup_type, rotation)

Backup a server

Parameters:
  • server – Either the ID of a server or a Server instance.
  • name – The name of the backup image.
  • backup_type – The type of the backup, for example, daily.
  • rotation – The rotation of the back up image, the oldest image will be removed when image count exceed the rotation count.
Returns:

None

Network Actions

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
add_fixed_ip_to_server(server, network_id)

Adds a fixed IP address to a server instance.

Parameters:
  • server – Either the ID of a server or a Server instance.
  • network_id – The ID of the network from which a fixed IP address is about to be allocated.
Returns:

None

remove_fixed_ip_from_server(server, address)

Removes a fixed IP address from a server instance.

Parameters:
  • server – Either the ID of a server or a Server instance.
  • address – The fixed IP address to be disassociated from the server.
Returns:

None

add_floating_ip_to_server(server, address, fixed_address=None)

Adds a floating IP address to a server instance.

Parameters:
  • server – Either the ID of a server or a Server instance.
  • address – The floating IP address to be added to the server.
  • fixed_address – The fixed IP address to be associated with the floating IP address. Used when the server is connected to multiple networks.
Returns:

None

remove_floating_ip_from_server(server, address)

Removes a floating IP address from a server instance.

Parameters:
  • server – Either the ID of a server or a Server instance.
  • address – The floating IP address to be disassociated from the server.
Returns:

None

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 Server instance.
  • security_group – Either the ID of a security group or a SecurityGroup instance.
Returns:

None

remove_security_group_from_server(server, security_group)

Remove a security group from a server

Parameters:
  • server – Either the ID of a server or a Server instance.
  • security_group – Either the ID of a security group or a SecurityGroup instance.
Returns:

None

Starting, Stopping, etc.

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
start_server(server)

Starts a stopped server and changes its state to ACTIVE.

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
stop_server(server)

Stops a running server and changes its state to SHUTOFF.

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
suspend_server(server)

Suspends a server and changes its status to SUSPENDED.

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
resume_server(server)

Resumes a suspended server and changes its status to ACTIVE.

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
reboot_server(server, reboot_type)

Reboot a server

Parameters:
  • server – Either the ID of a server or a Server instance.
  • reboot_type (str) – The type of reboot to perform. “HARD” and “SOFT” are the current options.
Returns:

None

shelve_server(server)

Shelves a server.

All associated data and resources are kept but anything still in memory is not retained. Policy defaults enable only users with administrative role or the owner of the server to perform this operation. Cloud provides could change this permission though.

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
unshelve_server(server)

Unselves or restores a shelved server.

Policy defaults enable only users with administrative role or the owner of the server to perform this operation. Cloud provides could change this permission though.

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
lock_server(server)

Locks a server.

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
unlock_server(server)

Unlocks a locked server.

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
pause_server(server)

Pauses a server and changes its status to PAUSED.

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
unpause_server(server)

Unpauses a paused server and changes its status to ACTIVE.

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
rescue_server(server, admin_pass=None, image_ref=None)

Puts a server in rescue mode and changes it status to RESCUE.

Parameters:
  • server – Either the ID of a server or a Server instance.
  • admin_pass – The password for the rescued server. If you omit this parameter, the operation generates a new password.
  • image_ref – The image reference to use to rescue your server. This can be the image ID or its full URL. If you omit this parameter, the base image reference will be used.
Returns:

None

unrescue_server(server)

Unrescues a server and changes its status to ACTIVE.

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
evacuate_server(server, host=None, admin_pass=None, force=None)

Evacuates a server from a failed host to a new host.

Parameters:
  • server – Either the ID of a server or a Server instance.
  • host – An optional parameter specifying the name or ID of the host to which the server is evacuated.
  • admin_pass – An optional parameter specifying the administrative password to access the evacuated or rebuilt server.
  • force – Force an evacuation by not verifying the provided destination host by the scheduler. (New in API version 2.29).
Returns:

None

migrate_server(server)

Migrate a server from one host to another

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
get_server_console_output(server, length=None)

Return the console output for a server.

Parameters:
  • server – Either the ID of a server or a Server instance.
  • length – Optional number of line to fetch from the end of console log. All lines will be returned if this is not specified.
Returns:

The console output as a dict. Control characters will be escaped to create a valid JSON string.

live_migrate_server(server, host=None, force=False)

Migrate a server from one host to target host

Parameters:
  • server – Either the ID of a server or a Server instance.
  • host – The host to which to migrate the server
  • force – Force a live-migration by not verifying the provided destination host by the scheduler.
Returns:

None

Modifying a Server

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
resize_server(server, flavor)

Resize a server

Parameters:
  • server – Either the ID of a server or a Server instance.
  • flavor – Either the ID of a flavor or a Flavor instance.
Returns:

None

confirm_server_resize(server)

Confirm a server resize

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
revert_server_resize(server)

Revert a server resize

Parameters:server – Either the ID of a server or a Server instance.
Returns:None
rebuild_server(server, name, admin_password, **attrs)

Rebuild a server

Parameters:
  • server – Either the ID of a server or a Server instance.
  • 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 – 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 Server instance.

reset_server_state(server, state)

Reset the state of server

Parameters:
  • server – The server can be either the ID of a server or a Server.
  • state – The state of the server to be set, active or error are valid.
Returns:

None

change_server_password(server, new_password)

Change the administrator password

Parameters:
  • server – Either the ID of a server or a Server instance.
  • new_password (str) – The new password to be set.
Returns:

None

get_server_password(server)

Get the administrator password

Parameters:server – Either the ID of a server or a Server instance.
Returns:encrypted password.

Image Operations

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
images(details=True, **query)

Return a generator of images

Parameters:
  • details (bool) – When True, returns ImageDetail objects, otherwise Image. Default: ``True``
  • **query (kwargs) – Optional query parameters to be sent to limit the resources being returned.
Returns:

A generator of image objects

get_image(image)

Get a single image

Parameters:image – The value can be the ID of an image or a Image instance.
Returns:One Image
Raises:ResourceNotFound when no resource can be found.
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 False ResourceNotFound will be raised when the resource does not exist. When set to True, None will be returned when attempting to find a nonexistent resource.
Returns:

One Image or None

delete_image(image, ignore_missing=True)

Delete an image

Parameters:
  • image – The value can be either the ID of an image or a Image instance.
  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the image does not exist. When set to True, no exception will be set when attempting to delete a nonexistent image.
Returns:

None

get_image_metadata(image)

Return a dictionary of metadata for an image

Parameters:image – Either the ID of an image or a Image or ImageDetail instance.
Returns:A Image with 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 Image or ImageDetail instance.
  • 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 Image with only the image’s metadata. All keys and values are Unicode text.

Return type:

Image

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 Image or ImageDetail instance.
  • keys – The keys to delete.
Return type:

None

Flavor Operations

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
create_flavor(**attrs)

Create a new Flavor from attributes

Parameters:attrs (dict) – Keyword arguments which will be used to create a Flavor.
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 Flavor instance.
  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the flavor does not exist. When set to True, no exception will be set when attempting to delete a nonexistent flavor.
Returns:

None

get_flavor(flavor)

Get a single Flavor

Parameters:flavor – The value can be the ID of a flavor or a Flavor instance.
Returns:One Flavor
Raises:ResourceNotFound when no resource can be found.
find_flavor(name_or_id, ignore_missing=True)

Find a single Flavor

Parameters:
  • name_or_id – The name or ID of an Flavor.
  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the resource does not exist. When set to True, None will be returned when attempting to find a nonexistent resource.
Returns:

One Flavor or None

flavors(details=True, **query)

Retrieve a generator of all Flavor

Parameters:
  • details (bool) – When True, returns FlavorDetail objects, otherwise Flavor. Default: ``True``
  • **query (kwargs) – Optional query parameters to be sent to limit the flavors being returned.
Returns:

A generator of Flavor instances.

Return type:

Flavor

Service Operations

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
services()

Return a generator of service

Returns:A generator of service
Return type:class: ~openstack.compute.v2.service.Service
enable_service(service, host, binary)

Enable a service

Parameters:
  • service – Either the ID of a service or a Service instance.
  • host (str) – The host where service runs.
  • binary (str) – The name of service.
Returns:

None

disable_service(service, host, binary, disabled_reason=None)

Disable a service

Parameters:
  • service – Either the ID of a service or a Service instance.
  • 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

force_service_down(service, host, binary)

Force a service down

Parameters:
  • service – Either the ID of a service or a Service instance.
  • host (str) – The host where service runs.
  • binary (str) – The name of service.
Returns:

None

Volume Attachment Operations

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
create_volume_attachment(server, **attrs)

Create a new volume attachment from attributes

Parameters:
  • server – The server can be either the ID of a server or a Server instance.
  • attrs (dict) – Keyword arguments which will be used to create a VolumeAttachment, comprised of the properties on the VolumeAttachment class.
Returns:

The results of volume attachment creation

Return type:

VolumeAttachment

update_volume_attachment(volume_attachment, server, **attrs)

update a volume attachment

Parameters:
  • volume_attachment – The value can be either the ID of a volume attachment or a VolumeAttachment instance.
  • server – This parameter need to be specified when VolumeAttachment ID is given as value. It can be either the ID of a server or a Server instance that the attachment belongs to.
  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the volume attachment does not exist. When set to True, no exception will be set when attempting to delete a nonexistent volume attachment.
Returns:

None

delete_volume_attachment(volume_attachment, server, ignore_missing=True)

Delete a volume attachment

Parameters:
  • volume_attachment – The value can be either the ID of a volume attachment or a VolumeAttachment instance.
  • server – This parameter need to be specified when VolumeAttachment ID is given as value. It can be either the ID of a server or a Server instance that the attachment belongs to.
  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the volume attachment does not exist. When set to True, no exception will be set when attempting to delete a nonexistent volume attachment.
Returns:

None

get_volume_attachment(volume_attachment, server, ignore_missing=True)

Get a single volume attachment

Parameters:
  • volume_attachment – The value can be the ID of a volume attachment or a VolumeAttachment instance.
  • server – This parameter need to be specified when VolumeAttachment ID is given as value. It can be either the ID of a server or a Server instance that the attachment belongs to.
  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the volume attachment does not exist. When set to True, no exception will be set when attempting to delete a nonexistent volume attachment.
Returns:

One VolumeAttachment

Raises:

ResourceNotFound when no resource can be found.

volume_attachments(server)

Return a generator of volume attachments

Parameters:server – The server can be either the ID of a server or a Server.
Returns:A generator of VolumeAttachment objects
Return type:VolumeAttachment

Keypair Operations

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
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 Keypair instance.
  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the keypair does not exist. When set to True, no exception will be set when attempting to delete a nonexistent keypair.
Returns:

None

get_keypair(keypair)

Get a single keypair

Parameters:keypair – The value can be the ID of a keypair or a Keypair instance.
Returns:One Keypair
Raises:ResourceNotFound when 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 False ResourceNotFound will be raised when the resource does not exist. When set to True, None will be returned when attempting to find a nonexistent resource.
Returns:

One Keypair or None

keypairs()

Return a generator of keypairs

Returns:A generator of keypair objects
Return type:Keypair

Server IPs

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
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:

ServerIP

Server Group Operations

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
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 ServerGroup instance.
  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the server group does not exist. When set to True, no exception will be set when attempting to delete a nonexistent server group.
Returns:

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 ServerGroup instance.
Returns:A ServerGroup object.
Raises:ResourceNotFound when no resource can be found.
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 False ResourceNotFound will be raised when the resource does not exist. When set to True, None will be returned when attempting to find a nonexistent resource.
Returns:

One ServerGroup object or None

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

Server Interface Operations

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
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 Server instance 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:

ServerInterface

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 ServerInterface instance.
  • 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 Server instance that the interface belongs to.
  • ignore_missing (bool) – When set to False ResourceNotFound will be raised when the server interface does not exist. When set to True, no exception will be set when attempting to delete a nonexistent server interface.
Returns:

None

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 ServerInterface instance.
  • 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 Server instance that the interface belongs to.
Returns:

One ServerInterface

Raises:

ResourceNotFound when no resource can be found.

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

Availability Zone Operations

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
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:                        AvailabilityZone

Limits Operations

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
get_limits()

Retrieve limits that are applied to the project’s account

Returns:A Limits object, including both AbsoluteLimits and RateLimits
Return type:Limits

Hypervisor Operations

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
get_hypervisor(hypervisor)

Get a single hypervisor

Parameters:hypervisor – The value can be the ID of a hypervisor or a Hypervisor instance.
Returns:A Hypervisor object.
Raises:ResourceNotFound when no resource can be found.
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
hypervisors()

Return a generator of hypervisor

Returns:A generator of hypervisor
Return type:class: ~openstack.compute.v2.hypervisor.Hypervisor

Extension Operations

class openstack.compute.v2._proxy.Proxy(session=None, task_manager=None, *args, **kwargs)
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 False ResourceNotFound will be raised when the resource does not exist. When set to True, None will be returned when attempting to find a nonexistent resource.
Returns:

One Extension or None

extensions(details=True, **query)

Retrieve a generator of all Extension

Parameters:
  • details (bool) – When True, returns Extension objects, otherwise Extension. Default: ``True``
  • **query (kwargs) – Optional query parameters to be sent to limit the flavors being returned.
Returns:

A generator of Extension instances.

Return type:

Extension

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.