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.
-
hammers.osapi.
add_arguments
(parser)[source]¶ 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 theAuth.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.
-
endpoint
(type)[source]¶ Find the endpoint for a given service type. Examples include
compute
for Nova,reservation
for Blazar, orimage
for Glance.
-
token
¶ 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
.
-
classmethod
Service API Wrappers¶
For the below, the auth argument is an instance of
hammers.osapi.Auth
.
Blazar (Reservations)¶
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.
Parameters: - 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.
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.
nodes
(auth, details=False)[source]¶ Retrieves all nodes, with more info if details is true.
Keystone (Authentication)¶
Keystone API shims. Requires v3 API. See Keystone HTTP API
-
hammers.osrest.keystone.
projects
(auth, **params)[source]¶ Retrieve multiple projects, optionally filtered by params. Keyed by ID.
Example params:
name
,enabled
, or stuff from https://developer.openstack.org/api-ref/identity/v3/?expanded=list-projects-detail#list-projects
-
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.
Neutron (Networking)¶
-
hammers.osrest.neutron.
floatingips
(auth)[source]¶ Get all floating IPs, returns a dictionary keyed by ID.
-
hammers.osrest.neutron.
network
(auth, net)[source]¶ Gets a network by ID, or mapping containing an
'id'
key.
-
hammers.osrest.neutron.
port_delete
(auth, port)[source]¶ Deletes a port by ID, or mapping containing an
'id'
key.