Sometimes it's the little things.

Sometime this last year we added support to python-openstackclient for using os-client-config based configuration. Doesn't that sound exciting? It should - because it means you can put your 15 OpenStack public cloud accounts into ~/.config/openstack/clouds.yaml and refer to them by name. Like this:


clouds:
  vexxhost:
    profile: vexxhost
    auth:
      project_name: d8af8a8f-a573-48e6-898a-af333b970a2d
      username: 0b8c435b-cc4d-4e05-8a47-a2ada0539af1
      password: XXXXXXXXXXXXXXXXXX
    region_name: ca-ymq-1
  ovh:
    profile: ovh
    auth:
      username: 6WjmCk3Kbe5v
      password: XXXXXXXXXXXXXXXXX
      project_name: 3614264792735868
    regions:
    - SBG1
    - GRA1
    

The profile entry in the file is a reference to known cloud vendors so that you can take advantage of us knowing things like their AUTH_URL and whether they use tasks or PUT for image uploads

The neat thing about all that is that you can then just say:


openstack --os-cloud=vexxhost server list
openstack --os-cloud=vexxhost --os-region-name=SBG1 server list
    

to interact with your cloud accounts. The exact same config file can also drive your ansible playbooks, so you cn do:


---
- hosts: localhost
  connection: local
  gather_facts: False
  tasks:
  - os_keypair:
      cloud: vexxhost
      name: mordred
      state: present
      public_key_file: ~/.ssh/id_rsa.pub
    

Followed by:


openstack --os-cloud=vexxhost openstack keypair show mordred
    

When you need to poke around manually.

That's still too much typing

If you're like me, that's still too much of a pain. So I added the following to my bashrc:


if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}${OS_CLOUD:+${OS_CLOUD}:}${OS_REGION_NAME:+${OS_REGION_NAME}:}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}${OS_CLOUD:+${OS_CLOUD}:}${OS_REGION_NAME:+${OS_REGION_NAME}:}\u@\h:\w\$ '
fi

function use {
  declare -a CloudRegion=(${1//:/ })
  export OS_CLOUD=${CloudRegion[0]}
  export OS_REGION_NAME=${CloudRegion[1]}
}
    

Which got me this:


mordred@camelot:~/src/openstack-infra/shade$ use vexxhost
vexxhost:mordred@camelot:~/src/openstack-infra/shade$ openstack keypair show mordred
+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| created_at  | 2015-04-13T13:30:12.000000                      |
| deleted     | False                                           |
| deleted_at  | None                                            |
| fingerprint | 6b:8c:bd:93:e6:05:c7:1b:2f:fd:3c:11:b5:da:a6:52 |
| id          | 68                                              |
| name        | mordred                                         |
| updated_at  | None                                            |
| user_id     | e9b21dc437d149858faee0898fb08e92                |
+-------------+-------------------------------------------------+
vexxhost:mordred@camelot:~/src/openstack-infra/shade$ use ovh:GRA1
ovh:GRA1:mordred@camelot:~/src/openstack-infra/shade$ openstack keypair show mordred
+-------------+-------------------------------------------------+
| Field       | Value                                           |
+-------------+-------------------------------------------------+
| created_at  | 2015-09-22T19:15:01.000000                      |
| deleted     | False                                           |
| deleted_at  | None                                            |
| fingerprint | 6b:8c:bd:93:e6:05:c7:1b:2f:fd:3c:11:b5:da:a6:52 |
| id          | 84923                                           |
| name        | mordred                                         |
| updated_at  | None                                            |
| user_id     | e84b8554e09e4d9a9403b5c0b1184850                |
+-------------+-------------------------------------------------+