summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2015-09-22 14:20:37 -0500
committerMonty Taylor <mordred@inaugust.com>2015-09-22 14:20:37 -0500
commit1ea54cc61e02a1546d734a00b3453d9a54cf53af (patch)
tree7eac60df02d5fc002a27d680aad4d9ede8167b19
parent6830ac0da4afb488f888c80a5797d7aaa7be482a (diff)
Add post about openstackclient
-rw-r--r--src/posts/multi-cloud-with-python-openstackclient.hbs122
1 files changed, 122 insertions, 0 deletions
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 @@
1<!doctype html>
2<html>
3 <head>
4 <title>python-openstackclient and os-client-config</title>
5 <meta name="description" content="How to use multiple clouds like a pro" />
6 </head>
7 <body>
8 <p>Sometimes it's the little things.</p>
9 <p>Sometime this last year we added support to
10 <a href='http://docs.openstack.org/developer/python-openstackclient/'>
11 python-openstackclient
12 </a>
13 for using
14 <a href='http://docs.openstack.org/developer/os-client-config/'>
15 os-client-config</a>
16 based configuration. Doesn't that sound
17 exciting? It should - because it means you can put your 15 OpenStack
18 public cloud accounts into ~/.config/openstack/clouds.yaml and refer to
19 them by name. Like this:</p>
20 <pre><code>
21clouds:
22 vexxhost:
23 profile: vexxhost
24 auth:
25 project_name: d8af8a8f-a573-48e6-898a-af333b970a2d
26 username: 0b8c435b-cc4d-4e05-8a47-a2ada0539af1
27 password: XXXXXXXXXXXXXXXXXX
28 region_name: ca-ymq-1
29 ovh:
30 profile: ovh
31 auth:
32 username: 6WjmCk3Kbe5v
33 password: XXXXXXXXXXXXXXXXX
34 project_name: 3614264792735868
35 regions:
36 - SBG1
37 - GRA1
38 </code></pre>
39
40 <p>The profile entry in the file is a reference to
41 <a href='http://docs.openstack.org/developer/os-client-config/vendor-support.html'>known cloud vendors</a> so that you can take advantage of us
42 knowing things like their AUTH_URL and whether they use tasks or PUT
43 for image uploads</p>
44
45 <p>The neat thing about all that is that you can then just say:</p>
46
47 <pre><code>
48openstack --os-cloud=vexxhost server list
49openstack --os-cloud=vexxhost --os-region-name=SBG1 server list
50 </code></pre>
51
52 <p>to interact with your cloud accounts. The exact same config file
53 can also drive your ansible playbooks, so you cn do:</p>
54 <pre><code>
55---
56- hosts: localhost
57 connection: local
58 gather_facts: False
59 tasks:
60 - os_keypair:
61 cloud: vexxhost
62 name: mordred
63 state: present
64 </code></pre>
65
66 <p>Followed by:</p>
67 <pre><code>
68openstack --os-cloud=vexxhost openstack keypair show mordred
69 </code></pre>
70
71 <p>When you need to poke around manually.</p>
72
73 <h3>That's still too much typing</h3>
74
75 <p>If you're like me, that's still too much of a pain. So I added the
76 following to my bashrc:</p>
77
78 <pre><code>
79if [ "$color_prompt" = yes ]; then
80 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\]\$ '
81else
82 PS1='${debian_chroot:+($debian_chroot)}${OS_CLOUD:+${OS_CLOUD}:}${OS_REGION_NAME:+${OS_REGION_NAME}:}\u@\h:\w\$ '
83fi
84
85function use {
86 declare -a CloudRegion=(${1//:/ })
87 export OS_CLOUD=${CloudRegion[0]}
88 export OS_REGION_NAME=${CloudRegion[1]}
89}
90 </code></pre>
91
92 <p>Which got me this:</p>
93 <pre><code>
94mordred@camelot:~/src/openstack-infra/shade$ use vexxhostvexxhost:mordred@camelot:~/src/openstack-infra/shade$ openstack keypair show mordred
95+-------------+-------------------------------------------------+
96| Field | Value |
97+-------------+-------------------------------------------------+
98| created_at | 2015-04-13T13:30:12.000000 |
99| deleted | False |
100| deleted_at | None |
101| fingerprint | 6b:8c:bd:93:e6:05:c7:1b:2f:fd:3c:11:b5:da:a6:52 |
102| id | 68 |
103| name | mordred |
104| updated_at | None |
105| user_id | e9b21dc437d149858faee0898fb08e92 |
106+-------------+-------------------------------------------------+
107vexxhost:mordred@camelot:~/src/openstack-infra/shade$ use ovh:GRA1ovh:GRA1:mordred@camelot:~/src/openstack-infra/shade$ openstack keypair show mordred
108+-------------+-------------------------------------------------+
109| Field | Value |
110+-------------+-------------------------------------------------+
111| created_at | 2015-09-22T19:15:01.000000 |
112| deleted | False |
113| deleted_at | None |
114| fingerprint | 6b:8c:bd:93:e6:05:c7:1b:2f:fd:3c:11:b5:da:a6:52 |
115| id | 84923 |
116| name | mordred |
117| updated_at | None |
118| user_id | e84b8554e09e4d9a9403b5c0b1184850 |
119+-------------+-------------------------------------------------+
120 </code></pre>
121</body>
122</html>