Installing OSC With pipx

Another one that really belongs in a separate “tips & tricks” section of the blog, which unfortunately does not yet exist. I use openstackclient (OSC) pretty extensively day-to-day. Fedora provides a relatively up-to-date version of the package, but OSC has been evolving very rapidly of late and Fedora’s packagers just can’t be that fast 😁. The solution, therefore, is to install from pip. Installing things globally, even if that’s global to the user, is a bad idea though: there are too many opportunities for dependency updates to break other packages. I want to use a virtualenv. The obvious solution is to use pipx, which is specifically designed for this use case. From the homepage:

pipx is a tool to help you install and run end-user applications written in Python. It’s roughly similar to macOS’s brew, JavaScript’s npx, and Linux’s apt.

It’s closely related to pip. In fact, it uses pip, but is focused on installing and managing Python packages that can be run from the command line directly as applications.

pipx itself is available in the Fedora repos so if Fedora is you distro of choice then you can install it with dnf:

❯ sudo dnf install pipx

Once that’s in place, you can install OSC with pipx:

❯ pipx install python-openstackclient

Unlike openstacksdk, however, the python-openstackclient package doesn’t provide support for OpenStack services beyond the core ones: Identity (keystone), Compute (nova), Image (glance), Block Storage (cinder), Network (neutron) and Object Storage (swift). For services like the Share Filesystem-as-a-Service (manila), Load Balancer-as-a-Service (octavia) or Placement service, you need to install additional packages (python-manilaclient, python-octaviaclient, and osc-placement, respectively).

❯ openstack loadbalancer list
openstack: 'loadbalancer list' is not an openstack command. See 'openstack --help'.
Did you mean one of these?
  container create
  container delete
  container list
  container save
  container set
  container show
  container unset

It took me a beat to figure out but pipx provides an easy mechanism to do this: the inject command. For example, to install python-octaviaclient in the same virtualenv, run:

❯ pipx inject python-openstackclient python-octaviaclient

You can repeat this for additional dependencies:

❯ pipx inject python-openstackclient osc-placement python-neutronclient python-manilaclient python-ironicclient python-barbicanclient python-designateclient
❯ pipx list --include-injected
venvs are in /home/stephenfin/.local/pipx/venvs
apps are exposed on your $PATH at /home/stephenfin/.local/bin
   package python-openstackclient 6.2.0, installed using Python 3.11.2
    - openstack
    Injected Packages:
      - osc-placement 4.1.0
      - python-barbicanclient 5.5.0
      - python-designateclient 5.2.0
      - python-ironicclient 5.1.0
      - python-manilaclient 4.3.0
      - python-neutronclient 9.0.0
      - python-octaviaclient 3.4.0

With that done, you should have access to all the commands. 💪

comments powered by Disqus