
Glance returns pagination links like "/v2/images?marker=". keystoneauth Adapter treats absolute links like that as if they are rooted on the service url. Since the catalog has https://image.example.com/v2 in it, the Adapter will be mounted on that, which means /v2/images will be treated as "https://image.example.com/v2/v2/iamges - which is not correct. Doing a urljoin would also be incorrect in an OpenStack context, because the service could be on a sub-url, such as https://example.com/image, meaning the v2 API endpoint would be https://example.com/image/v2 - which means a straight urljoin of https://example.com/image/v2 and /v2/images?marker= would result in https://example.com/v2/images?marker= which is wrong since it strips the /image path prefix. The most correct things for glance to do would be to return a full absolute url - or a full relative URL. Constructing the absolute url shade-side is hard for the above reasons - we don't have the right context. Strip /v1/ or /v2/ from the front of the next links (yay!) to turn it into a relative url - thereby letting adapter.get(endpoint) do the correct thing. While doing this, update the catalog fixture in the test suite to have a trailing /v2 so that we can be sure we're doing the correct thing in our unit tests. Also add suburl fixtures to ensure that we work with suburls. Change-Id: I6fc8484ed62a029a8ba8ff1d31a37ba69e3000cf
Introduction
shade is a simple client library for interacting with OpenStack clouds. The key word here is simple. Clouds can do many many many things - but there are probably only about 10 of them that most people care about with any regularity. If you want to do complicated things, you should probably use the lower level client libraries - or even the REST API directly. However, if what you want is to be able to write an application that talks to clouds no matter what crazy choices the deployer has made in an attempt to be more hipster than their self-entitled narcissist peers, then shade is for you.
shade started its life as some code inside of ansible. ansible has a bunch of different OpenStack related modules, and there was a ton of duplicated code. Eventually, between refactoring that duplication into an internal library, and adding logic and features that the OpenStack Infra team had developed to run client applications at scale, it turned out that we'd written nine-tenths of what we'd need to have a standalone library.
Example
Sometimes an example is nice.
Create a
clouds.yml
file:clouds: mordred: region_name: RegionOne auth: username: 'mordred' password: XXXXXXX project_name: 'shade' auth_url: 'https://montytaylor-sjc.openstack.blueboxgrid.com:5001/v2.0'
Please note: os-client-config will look for a file called
clouds.yaml
in the following locations:- Current Directory
~/.config/openstack
/etc/openstack
More information at https://pypi.python.org/pypi/os-client-config
Create a server with shade, configured with the
clouds.yml
file:import shade # Initialize and turn on debug logging shade.simple_logging(debug=True) # Initialize cloud # Cloud configs are read with os-client-config cloud = shade.openstack_cloud(cloud='mordred') # Upload an image to the cloud image = cloud.create_image( 'ubuntu-trusty', filename='ubuntu-trusty.qcow2', wait=True) # Find a flavor with at least 512M of RAM flavor = cloud.get_flavor_by_ram(512) # Boot a server, wait for it to boot, and then do whatever is needed # to get a public ip for it. cloud.create_server( 'my-server', image=image, flavor=flavor, wait=True, auto_ip=True)