HTTP Helpers

These are DIY shims that access OpenStack services’ APIs without requiring much more than Python requests. The objects they return are not intelligent, but are simple lists and dictionaries.

Auth Management

Tools to convert credentials into authentication and authorization in raw Python, as opposed to the Python APIs provided by keystoneauth1 or the like. They were largely created out of frustration with the apparent moving target and inconsistencies of the OS client APIs, which was also exacerbated by the Blazar client being fairly nacent.

Compare and contrast

ccmanage.auth which does use the Python APIs.


Inject an arg into the user’s parser. Intented to pair with Auth.from_env_or_args(): after argparse parses the args, feed that the args namespace.

hammers.osapi.load_osrc(fn, get_pass=False)[source]

Parse a Bash RC file dumped out by the dashboard to a dict. Used to load the file specified by add_arguments().

class hammers.osapi.Auth(rc)[source]

The Auth object consumes credentials and provides tokens and endpoints. Create either directly by providing a mapping with the keys in required_os_vars or via the Auth.from_env_or_args() method.

classmethod from_env_or_args(*, args=None, env=True)[source]

Loads the RC values from the file in the provided args namespace, falling back to the environment vars if env is true. add_arguments() is a helper function that will add the “osrc” argument to an argparse parser.

Returns an Auth object that’s ready for use.


Authenticate with Keystone to get a token and endpoint listing


Find the endpoint for a given service type. Examples include compute for Nova, reservation for Blazar, or image for Glance.


Read-only property that returns an active token, reauthenticating if it has expired. Most services accept this in the HTTP request header under the key X-Auth-Token.

Service API Wrappers

For the below, the auth argument is an instance of hammers.osapi.Auth.

Blazar (Reservations), host_id)[source]

Retrieves host by ID.


Retrieves all hosts, returning a dictionary keyed by ID.

hammers.osrest.blazar.host_update(auth, host_id, values_payload)[source]

Updates host data, lease_id)[source]

Retrieves a lease by ID


Retrieves all leases, returning a dictionary keyed by ID

hammers.osrest.blazar.lease_delete(auth, lease_id)[source]

Deletes a lease by ID

Glance (Image Store)

Glance API shims. See Glance HTTP API

hammers.osrest.glance.image_properties(auth, image_id, *, add=None, remove=None, replace=None)[source]

Add/remove/replace properties on the image. Some standard properties can be modified (name, visibility), some can’t (id, checksum), but custom fields can be whatever.

  • add (mapping) – properties to add
  • remove (iterable) – properties to delete
  • replace (mapping) – properties to replace by key
hammers.osrest.glance.image_create(auth, name, *, disk_format='qcow2', container_format='bare', visibility='private', extra=None)[source]

Creates empty image entry, ready to be filled by an upload command.

If provided, extra is a mapping to set custom properties.

hammers.osrest.glance.image(auth, id=None, name=None)[source]

Looks up image by id or name. If name is not unique given the scope of authentication (e.g. private image owned by someone else may be hidden), an error is raised.

hammers.osrest.glance.images(auth, query=None)[source]

Retrieves all images, filtered by query, if provided.

Doesn’t support pagination. Don’t request too many.

For querying, accepts a dictionary. If the value is a non-string iterable, the key is repeated in the query with each element in the iterable.

hammers.osrest.glance.image_delete(auth, id)[source]

Deletes image by ID

hammers.osrest.glance.image_upload_curl(auth, id, filepath)[source]

Generates an cURL command to upload an image file at filepath to be associated with the Glance image. Includes authentication header, so is stateless and can be run most anywhere.

hammers.osrest.glance.image_download_curl(auth, id, filepath=None)[source]

Generates a cURL command to download an image file to filepath. If filepath is not provided, dumps to ~/<image name>.img. The request is authenticated, so can be run most anywhere.

Ironic (Bare Metal)

Shims for Ironic. See Ironic HTTP API Docs.

hammers.osrest.ironic.node_update(auth, node, * add=None, remove=None, replace=None)[source]

Add/remove/replace properties on the node.

Parameters:replace (mapping) – properties to replace by key
hammers.osrest.ironic.node(auth, node)[source]

Get node by ID or the uuid key out of a dictionary.

hammers.osrest.ironic.nodes(auth, details=False)[source]

Retrieves all nodes, with more info if details is true.

hammers.osrest.ironic.node_set_state(auth, node, state)[source]

Set provision state of node to state.


Retrieves all Ironic ports, returns a dictionary keyed by the port ID

Keystone (Authentication)

Keystone API shims. Requires v3 API. See Keystone HTTP API

hammers.osrest.keystone.project(auth, id)[source]

Retrieve project by ID

hammers.osrest.keystone.projects(auth, **params)[source]

Retrieve multiple projects, optionally filtered by params. Keyed by ID.

Example params: name, enabled, or stuff from

hammers.osrest.keystone.project_lookup(auth, name_or_id)[source]

Tries to find a single project by name or ID. Raises an error if none or multiple projects found.

hammers.osrest.keystone.user(auth, id)[source]

Retrieve information about a user by ID

hammers.osrest.keystone.users(auth, enabled=None, name=None)[source]

Retrieve multiple users, optionally filtered.

hammers.osrest.keystone.user_lookup(auth, name_or_id)[source]

Tries to find a single user by name or ID. Raises an error if none or multiple users are found.

Neutron (Networking)


Get all floating IPs, returns a dictionary keyed by ID.

hammers.osrest.neutron.floatingip_delete(auth, floatingip)[source]

Frees a floating IP by ID, net)[source]

Gets a network by ID, or mapping containing an 'id' key.


Get all networks. Returns dictionary keyed by ID.


Get all ports. Returns a dictionary keyed by port ID.

hammers.osrest.neutron.port_delete(auth, port)[source]

Deletes a port by ID, or mapping containing an 'id' key.

hammers.osrest.neutron.subnet(auth, subnet)[source]

Get subnet info. Accepts ID or mapping containing an 'id' key.


Get all subnets.

Nova (Compute)