From 1ea54cc61e02a1546d734a00b3453d9a54cf53af Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Tue, 22 Sep 2015 14:20:37 -0500 Subject: Add post about openstackclient --- .../multi-cloud-with-python-openstackclient.hbs | 122 +++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 src/posts/multi-cloud-with-python-openstackclient.hbs (limited to 'src') diff --git a/src/posts/multi-cloud-with-python-openstackclient.hbs b/src/posts/multi-cloud-with-python-openstackclient.hbs new file mode 100644 index 0000000..d4d3566 --- /dev/null +++ b/src/posts/multi-cloud-with-python-openstackclient.hbs @@ -0,0 +1,122 @@ + + + + python-openstackclient and os-client-config + + + +

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
+    
+ +

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 vexxhostvexxhost: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:GRA1ovh: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                |
++-------------+-------------------------------------------------+
+    
+ + -- cgit v1.2.3