<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:p="urn:schemas-microsoft-com:office:powerpoint" xmlns:a="urn:schemas-microsoft-com:office:access" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" xmlns:b="urn:schemas-microsoft-com:office:publisher" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:odc="urn:schemas-microsoft-com:office:odc" xmlns:oa="urn:schemas-microsoft-com:office:activation" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:q="http://schemas.xmlsoap.org/soap/envelope/" xmlns:rtc="http://microsoft.com/officenet/conferencing" xmlns:D="DAV:" xmlns:Repl="http://schemas.microsoft.com/repl/" xmlns:mt="http://schemas.microsoft.com/sharepoint/soap/meetings/" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:ppda="http://www.passport.com/NameSpace.xsd" xmlns:ois="http://schemas.microsoft.com/sharepoint/soap/ois/" xmlns:dir="http://schemas.microsoft.com/sharepoint/soap/directory/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" xmlns:udc="http://schemas.microsoft.com/data/udc" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sub="http://schemas.microsoft.com/sharepoint/soap/2002/1/alerts/" xmlns:ec="http://www.w3.org/2001/04/xmlenc#" xmlns:sp="http://schemas.microsoft.com/sharepoint/" xmlns:sps="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:udcs="http://schemas.microsoft.com/data/udc/soap" xmlns:udcxf="http://schemas.microsoft.com/data/udc/xmlfile" xmlns:udcp2p="http://schemas.microsoft.com/data/udc/parttopart" xmlns:wf="http://schemas.microsoft.com/sharepoint/soap/workflow/" xmlns:dsss="http://schemas.microsoft.com/office/2006/digsig-setup" xmlns:dssi="http://schemas.microsoft.com/office/2006/digsig" xmlns:mdssi="http://schemas.openxmlformats.org/package/2006/digital-signature" xmlns:mver="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:mrels="http://schemas.openxmlformats.org/package/2006/relationships" xmlns:spwp="http://microsoft.com/sharepoint/webpartpages" xmlns:ex12t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:ex12m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:pptsl="http://schemas.microsoft.com/sharepoint/soap/SlideLibrary/" xmlns:spsl="http://microsoft.com/webservices/SharePointPortalServer/PublishedLinksService" xmlns:Z="urn:schemas-microsoft-com:" xmlns:st="" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 12 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-IE">Just wanted to start a discussion on the issue I hit yesterday when implementing volume usage metering (https://blueprints.launchpad.net/nova/+spec/volume-usage-metering)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">Here is what I found:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">I create a periodic task in nova/compute/manager.py, the function looks like this<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">    @manager.periodic_task<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">    def _poll_volume_usage(self, context, start_time=None, stop_time=None):<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">        if not start_time:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">            start_time = utils.last_completed_audit_period()[1]<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">        curr_time = time.time()<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">        if curr_time - self._last_vol_usage_poll > FLAGS.volume_poll_interval:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">            self._last_vol_usage_poll = curr_time<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">            LOG.info(_("Updating volume usage cache"))<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">            <b>volumes = self.volume_api.get_all(context)<o:p></o:p></b></span></p>
<p class="MsoNormal"><span lang="EN-IE">            try:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">                vol_usage = self.driver.get_all_volume_usage(context, volumes,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">                        start_time, stop_time)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">            except NotImplementedError:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">                return<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">            for usage in vol_usage:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">                self.db.vol_usage_update(context, usage['volume'], start_time,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">                                         usage['rd_req'], usage['rd_bytes'],<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">                                         usage['wr_req'], usage['wr_bytes'])<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">The issue is with the call “self.volume_api.get_all(context)”, in my blueprint I was going to use self.db.volume_get_all_by_host(ctxt, self.host) but because nova db doesn’t contain volume info anymore, we need to talk
 to cinder to get the info.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">_poll_volume_usage is passed and admin context when ran. The admin context doesn’t contain a service_catalog or any authentication info from Keystone, bascically just a context that says is_admin=True.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">So when  “self.volume_api.get_all(context)” is called passing in the admin context, the instantiation of a python cinder client fails as the service catalog is empty.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">Even if the service catalog was populated, I still think we’d fail as we wouldn’t have a Auth token to talk to cinder.
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 ERROR nova.manager [-] Error during ComputeManager._poll_volume_usage: 'NoneType' object is not iterable<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 TRACE nova.manager Traceback (most recent call last):<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 TRACE nova.manager   File "/opt/stack/nova/nova/manager.py", line 173, in periodic_tasks<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 TRACE nova.manager     task(self, context)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 TRACE nova.manager   File "/opt/stack/nova/nova/compute/manager.py", line 2639, in _poll_volume_usage<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 TRACE nova.manager     volumes = self.volume_api.get_all(context)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 TRACE nova.manager   File "/opt/stack/nova/nova/volume/cinder.py", line 125, in get_all<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 TRACE nova.manager     items = cinderclient(context).volumes.list(detailed=True)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 TRACE nova.manager   File "/opt/stack/nova/nova/volume/cinder.py", line 45, in cinderclient<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 TRACE nova.manager     url = sc.url_for(service_type='volume', service_name='cinder')<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 TRACE nova.manager   File "/opt/stack/python-cinderclient/cinderclient/service_catalog.py", line 53, in url_for<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 TRACE nova.manager     for service in catalog:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 TRACE nova.manager TypeError: 'NoneType' object is not iterable<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">2012-08-01 14:05:01 TRACE nova.manager<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">One possible solution to this is to have a cinder admin user with read only(read all data from cinder db) access created in Keystone (Glance does something very similar when talking to swift)? It keeps the user data in
 a conf file on the glance nodes.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">So before we call “self.volume_api.get_all(context)”, we can generate a cinder admin context using the info in a conf file.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">I think this could be done in another blueprint as I feel there are other use cases where a cinder admin user is required (Any cinder auditing in nova would require the admin user).<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">For now I propose, to make progress in my implementation of just adding stats collection on detach and not implementing the periodic task for now.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE">This would be volume usage metering part 1 say, as a proof of concept and when a general consensus/implementation is reached around the cinder admin user, I can implement the periodic task as part ?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-IE"><o:p> </o:p></span></p>
</div>
</body>
</html>