summaryrefslogtreecommitdiff
path: root/src/posts
diff options
context:
space:
mode:
Diffstat (limited to 'src/posts')
-rw-r--r--src/posts/simple-openstack-clients.hbs130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/posts/simple-openstack-clients.hbs b/src/posts/simple-openstack-clients.hbs
new file mode 100644
index 0000000..6d7b6e4
--- /dev/null
+++ b/src/posts/simple-openstack-clients.hbs
@@ -0,0 +1,130 @@
1<!doctype html>
2<html>
3 <head>
4 <title>Simple OpenStack access with os-client-config</title>
5 <meta name="description" content="Easy consumption of OpenStack Clouds" />
6 </head>
7 <body>
8 <p>Simple things should be simple, and nowhere is that more true than in
9 constructing objects to interface with clouds. What you wnat to do is just
10 interact with the cloud - what you often are required to do is generate
11 sequences of object constructions because there are a bunch of things you
12 <em>might</em> have wanted to do.</p>
13
14 <p>In the spirit of making the simple things simple, we recently added a
15 couple of simple helper factory functions to
16 <a href='http://docs.openstack.org/developer/os-client-config/'>
17 os-client-config</a>: One to create Client objects, and one to create
18 mounted Session objects. Both functions fully support the breadth of
19 config options afforded by os-client-config, including environment
20 variables, config files and command line options.</p>
21
22 <p>Examples are probably best</p>
23
24 <h3>Client Library Client Objects</h3>
25
26 <p>Make a nova client object that uses env vars for auth info:</p>
27
28 <pre><code>
29client = os_client_config.make_client('compute')
30 </code></pre>
31
32 <p>Make a glance client object for the cloud named 'mtvexx' in my
33 clouds.yaml file:</p>
34
35 <pre><code>
36client = os_client_config.make_client('image', cloud='mtvxx')
37 </code></pre>
38
39 <p>Make a neutron client by passing in all of the values directly:</p>
40
41 <pre><code>
42client = os_client_config.make_client(
43 'network',
44 auth_url=OS_AUTH_URL, username=OS_USERNAME,
45 password=OS_PASSWORD, project_name=OS_PROJECT_NAME,
46 region_name=OS_REGION_NAME)
47 </code></pre>
48
49 <p>Make a barbican client from env vars with all the standard arguments
50 passed on the comand line:</p>
51
52 <pre><code>
53import argparse
54client = os_client_config.make_client(
55 'key-manager', options=argparse.ArgumentParser())
56 </code></pre>
57
58 <p>That likely covers most of the common end-user use cases with using
59 OpenStack Client Libraries. If you need more flexibility, you can always
60 create an os-client-config CloudConfig object and call
61 get_legacy_client, but I'm a big believer in one step instead of three
62 if you can get away with it:</p>
63
64 <pre><code>
65config = os_client_config.OpenStackConfig()
66cloud_config = config.get_one_cloud(cloud='vexxhost')
67client = cloud_config.get_legacy_client('compute')
68 </code></pre>
69
70 <h3>Mounted Keystone Session</h3>
71
72 <p>What if what you want to do is make some direct REST calls to an
73 OpenStack service, but you want to be able to do env vars or argparse or
74 clouds.yaml files to configure your authentication?</p>
75
76 <p>Well - you're in luck!</p>
77
78 <p>Make a Session object for nova that uses env vars for auth info:</p>
79
80 <pre><code>
81client = os_client_config.session_client('compute')
82 </code></pre>
83
84 <p>That will get you a keystoneauth Session object that has been "mounted" on the compute service. So you can do this:</p>
85
86 <pre><code>
87response = session.get('/servers')
88server_list = response.json()['servers']
89 </code></pre>
90
91 <p>The same argument sequence used for <em>make_client</em> works for
92 <em>session_client</em>.
93
94 <p>Make a glance Session object for the cloud named 'mtvexx' in my
95 clouds.yaml file:</p>
96
97 <pre><code>
98session = os_client_config.session_client('image', cloud='mtvxx')
99 </code></pre>
100
101 <p>Make a neutron Session object by passing in all of the values
102 directly:</p>
103
104 <pre><code>
105session = os_client_config.session_client(
106 'network',
107 auth_url=OS_AUTH_URL, username=OS_USERNAME,
108 password=OS_PASSWORD, project_name=OS_PROJECT_NAME,
109 region_name=OS_REGION_NAME)
110 </code></pre>
111
112 <p>Make a barbican Session object from env vars with all the standard
113 arguments passed on the comand line:</p>
114
115 <pre><code>
116import argparse
117session = os_client_config.session_client(
118 'key-manager', options=argparse.ArgumentParser())
119 </code></pre>
120
121 <p>Do it all without syntactic help:</p>
122
123 <pre><code>
124config = os_client_config.OpenStackConfig()
125cloud_config = config.get_one_cloud(cloud='vexxhost')
126session = cloud_config.get_session_client('compute')
127 </code></pre>
128
129</body>
130</html>