{"id":5013,"date":"2014-05-20T16:59:58","date_gmt":"2014-05-20T14:59:58","guid":{"rendered":"http:\/\/blog.zhaw.ch\/icclab\/?p=5013"},"modified":"2014-07-07T18:14:56","modified_gmt":"2014-07-07T16:14:56","slug":"authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions","status":"publish","type":"post","link":"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/","title":{"rendered":"Authenticating the python ceilometer client against the Openstack APIs &#8211; bloody lambda functions!"},"content":{"rendered":"<p>We were doing some work with Ceilometer &#8211; it appears in a few of our activities &#8211; and I was trying to get up to speed with it. Playing with the python Ceilometer client proved a little more difficult then envisaged &#8211; mostly due to deficiencies in documentation. Here\u2019s a small note on an issue I faced with authentication.<\/p>\n<p><!--more--><\/p>\n<p>The starting point for the work was to use the approach <a href=\"http:\/\/docs.openstack.org\/developer\/python-ceilometerclient\/\">proposed the documentation<\/a> to obtain a list of meters. This was done after a basic install of the libraries locally (pip install python-ceilometerclient) to work against a remote set of APIs which are known to be stable and working.<\/p>\n<p>Using this basic setup, authentication would not work when the following approach to creation of the client (see full code below) was used; this is very much in line with the approaches of other Openstack client libraries.<\/p>\n<pre><code>\r\nfrom ceilometerclient import client\r\nceilometer = Client('2', endpoint=OS_IMAGE_ENDPOINT, token=OS_AUTH_TOKEN)\r\n<\/code>\r\n<\/pre>\n<p>The following error was produced:<\/p>\n<pre><code>\r\n\u201cFile \"\/usr\/local\/lib\/python2.7\/dist-packages\/ceilometerclient\/common\/http.py\", line 137, in _http_request\r\nauth_token = self.auth_token()\r\nTypeError: 'unicode' object is not callable\u201d\r\n<\/code>\r\n<\/pre>\n<p>The problem turned out to be one of <a href=\"http:\/\/www.secnetix.de\/olli\/Python\/lambda_functions.hawk\">lambda<\/a> functions &#8211; it was not obvious that we should make the token an anonymous function: once we called it with lambda, everything worked fine.<\/p>\n<pre><code>\r\nceilometer = client.Client('2',endpoint = ceilo_endpoint, token = lambda: token)\r\n<\/code>\r\n<\/pre>\n<p>Subsequently, one of our colleagues (thanks <a href=\"http:\/\/blog.zhaw.ch\/icclab\/florian-dudouet\/\">Florian<\/a>!) noted that there is a simpler approach which uses get_client. (See the second file below for how we used this).<\/p>\n<p>Now we\u2019re trying to do something useful with it!<\/p>\n<p>&#8212;&#8211;<\/p>\n<pre><code>\r\n#!\/usr\/bin\/python\r\n# -*- coding: utf-8 -*-\r\n# list meters - client initialized with lambda\u2019d auth_token\r\nfrom ceilometerclient import client\r\nfrom os import environ as env\r\nimport keystoneclient.v2_0.client as ksclient\r\n\r\n#getting the credentials\r\nkeystone = {}\r\nkeystone['username']=env['OS_USERNAME']\r\nkeystone['password']=env['OS_PASSWORD']\r\nkeystone['auth_url']=env['OS_AUTH_URL']\r\nkeystone['tenant_name']=env['OS_TENANT_NAME']\r\n\r\n#creating a keystone client\r\nceilometer_client = client._get_ksclient(**keystone)\r\ntoken = ceilometer_client.auth_token\r\n\r\n#creating an endpoint\r\nceilo_endpoint = client._get_endpoint(ceilometer_client, **keystone)\r\n\r\n#creating a ceilometer client\r\nceilometer = client.Client('2',endpoint = ceilo_endpoint, token = token)\r\n\r\n#tests\r\nmeters = ceilometer.meters.list()\r\nprint meters\r\n<\/code>\r\n<\/pre>\n<p>&#8212;&#8212;<\/p>\n<pre><code>\r\n#!\/usr\/bin\/python\r\n# -*- coding: utf-8 -*-\r\n# list meters - client initialized with get_client\r\n#imports\r\nfrom ceilometerclient import client\r\nfrom os import environ as env\r\nfrom ceilometerclient.common import utils\r\n\r\n#getting the credentials\r\nkeystone = {}\r\nkeystone['os_username']=env['OS_USERNAME']\r\nkeystone['os_password']=env['OS_PASSWORD']\r\nkeystone['os_auth_url']=env['OS_AUTH_URL']\r\nkeystone['os_tenant_name']=env['OS_TENANT_NAME']\r\n\r\n#creating an authenticated client\r\nceilometer_client = client.get_client(2,**keystone)\r\n\r\n#now you should be able to use the API\r\nmeters = ceilometer_client.meters.list()\r\nprint meters\r\n<\/code>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We were doing some work with Ceilometer &#8211; it appears in a few of our activities &#8211; and I was trying to get up to speed with it. Playing with the python Ceilometer client proved a little more difficult then envisaged &#8211; mostly due to deficiencies in documentation. Here\u2019s a small note on an issue [&hellip;]<\/p>\n","protected":false},"author":101,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[1,21],"tags":[],"features":[],"class_list":["post-5013","post","type-post","status-publish","format-standard","hentry","category-allgemein","category-openstack-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.2 (Yoast SEO v27.2) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Authenticating the python ceilometer client against the Openstack APIs - bloody lambda functions! - Service Engineering (ICCLab &amp; SPLab)<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Authenticating the python ceilometer client against the Openstack APIs - bloody lambda functions!\" \/>\n<meta property=\"og:description\" content=\"We were doing some work with Ceilometer &#8211; it appears in a few of our activities &#8211; and I was trying to get up to speed with it. Playing with the python Ceilometer client proved a little more difficult then envisaged &#8211; mostly due to deficiencies in documentation. Here\u2019s a small note on an issue [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/\" \/>\n<meta property=\"og:site_name\" content=\"Service Engineering (ICCLab &amp; SPLab)\" \/>\n<meta property=\"article:published_time\" content=\"2014-05-20T14:59:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-07-07T16:14:56+00:00\" \/>\n<meta name=\"author\" content=\"Bruno Grazioli\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bruno Grazioli\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/\"},\"author\":{\"name\":\"Bruno Grazioli\",\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/#\/schema\/person\/769a2455bfa3cbcc87857218f19abeba\"},\"headline\":\"Authenticating the python ceilometer client against the Openstack APIs &#8211; bloody lambda functions!\",\"datePublished\":\"2014-05-20T14:59:58+00:00\",\"dateModified\":\"2014-07-07T16:14:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/\"},\"wordCount\":238,\"commentCount\":3,\"articleSection\":[\"*.*\",\"OpenStack\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/\",\"url\":\"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/\",\"name\":\"Authenticating the python ceilometer client against the Openstack APIs - bloody lambda functions! - Service Engineering (ICCLab &amp; SPLab)\",\"isPartOf\":{\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/#website\"},\"datePublished\":\"2014-05-20T14:59:58+00:00\",\"dateModified\":\"2014-07-07T16:14:56+00:00\",\"author\":{\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/#\/schema\/person\/769a2455bfa3cbcc87857218f19abeba\"},\"breadcrumb\":{\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Startseite\",\"item\":\"https:\/\/blog.zhaw.ch\/icclab\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Authenticating the python ceilometer client against the Openstack APIs &#8211; bloody lambda functions!\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/#website\",\"url\":\"https:\/\/blog.zhaw.ch\/icclab\/\",\"name\":\"Service Engineering (ICCLab &amp; SPLab)\",\"description\":\"A Blog of the ZHAW Zurich University of Applied Sciences\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blog.zhaw.ch\/icclab\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/blog.zhaw.ch\/icclab\/#\/schema\/person\/769a2455bfa3cbcc87857218f19abeba\",\"name\":\"Bruno Grazioli\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/07d475be0415d5914aa49599b3295e4d972f971e46f5d7ab89d474327ab7b5f0?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/07d475be0415d5914aa49599b3295e4d972f971e46f5d7ab89d474327ab7b5f0?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/07d475be0415d5914aa49599b3295e4d972f971e46f5d7ab89d474327ab7b5f0?s=96&d=mm&r=g\",\"caption\":\"Bruno Grazioli\"},\"url\":\"https:\/\/blog.zhaw.ch\/icclab\/author\/gaea\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Authenticating the python ceilometer client against the Openstack APIs - bloody lambda functions! - Service Engineering (ICCLab &amp; SPLab)","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/","og_locale":"en_US","og_type":"article","og_title":"Authenticating the python ceilometer client against the Openstack APIs - bloody lambda functions!","og_description":"We were doing some work with Ceilometer &#8211; it appears in a few of our activities &#8211; and I was trying to get up to speed with it. Playing with the python Ceilometer client proved a little more difficult then envisaged &#8211; mostly due to deficiencies in documentation. Here\u2019s a small note on an issue [&hellip;]","og_url":"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/","og_site_name":"Service Engineering (ICCLab &amp; SPLab)","article_published_time":"2014-05-20T14:59:58+00:00","article_modified_time":"2014-07-07T16:14:56+00:00","author":"Bruno Grazioli","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Bruno Grazioli","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/#article","isPartOf":{"@id":"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/"},"author":{"name":"Bruno Grazioli","@id":"https:\/\/blog.zhaw.ch\/icclab\/#\/schema\/person\/769a2455bfa3cbcc87857218f19abeba"},"headline":"Authenticating the python ceilometer client against the Openstack APIs &#8211; bloody lambda functions!","datePublished":"2014-05-20T14:59:58+00:00","dateModified":"2014-07-07T16:14:56+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/"},"wordCount":238,"commentCount":3,"articleSection":["*.*","OpenStack"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/","url":"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/","name":"Authenticating the python ceilometer client against the Openstack APIs - bloody lambda functions! - Service Engineering (ICCLab &amp; SPLab)","isPartOf":{"@id":"https:\/\/blog.zhaw.ch\/icclab\/#website"},"datePublished":"2014-05-20T14:59:58+00:00","dateModified":"2014-07-07T16:14:56+00:00","author":{"@id":"https:\/\/blog.zhaw.ch\/icclab\/#\/schema\/person\/769a2455bfa3cbcc87857218f19abeba"},"breadcrumb":{"@id":"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.zhaw.ch\/icclab\/authenticating-the-python-ceilometer-client-against-the-openstack-apis-bloody-lambda-functions\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Startseite","item":"https:\/\/blog.zhaw.ch\/icclab\/"},{"@type":"ListItem","position":2,"name":"Authenticating the python ceilometer client against the Openstack APIs &#8211; bloody lambda functions!"}]},{"@type":"WebSite","@id":"https:\/\/blog.zhaw.ch\/icclab\/#website","url":"https:\/\/blog.zhaw.ch\/icclab\/","name":"Service Engineering (ICCLab &amp; SPLab)","description":"A Blog of the ZHAW Zurich University of Applied Sciences","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.zhaw.ch\/icclab\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.zhaw.ch\/icclab\/#\/schema\/person\/769a2455bfa3cbcc87857218f19abeba","name":"Bruno Grazioli","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/07d475be0415d5914aa49599b3295e4d972f971e46f5d7ab89d474327ab7b5f0?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/07d475be0415d5914aa49599b3295e4d972f971e46f5d7ab89d474327ab7b5f0?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/07d475be0415d5914aa49599b3295e4d972f971e46f5d7ab89d474327ab7b5f0?s=96&d=mm&r=g","caption":"Bruno Grazioli"},"url":"https:\/\/blog.zhaw.ch\/icclab\/author\/gaea\/"}]}},"_links":{"self":[{"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/posts\/5013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/users\/101"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/comments?post=5013"}],"version-history":[{"count":8,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/posts\/5013\/revisions"}],"predecessor-version":[{"id":5370,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/posts\/5013\/revisions\/5370"}],"wp:attachment":[{"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/media?parent=5013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/categories?post=5013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/tags?post=5013"},{"taxonomy":"features","embeddable":true,"href":"https:\/\/blog.zhaw.ch\/icclab\/wp-json\/wp\/v2\/features?post=5013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}