<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">I just looked at the code and it appears this is not possible through the os_networks extension. This appears to be an oversight. It should probably allow a project to be passed in.<div><br></div><div>Bug report here: <a href="https://bugs.launchpad.net/nova/+bug/1161441">https://bugs.launchpad.net/nova/+bug/1161441</a></div><div><br></div><div>That said, the first time a user boots an instance, he automatically gets assigned a network, so in many cases it isn't needed.</div><div><br></div><div>Another option would be to modify the code you mentioned to allow a workaround:</div><div><br></div><div><div class="line" id="LC933"><span class="k">if</span> <span class="p">(</span><span class="n">context</span> <span class="ow">and</span> not <a href="http://context.is">context.is</a>_admin and <span class="n">project_id</span> <span class="ow">and</span> <span class="p">(</span><span class="n">project_id</span> <span class="o">!=</span> <span class="n">context</span><span class="o">.</span><span class="n">project_id</span><span class="p">)):</span></div><div class="line" id="LC933"><span class="p"><br></span></div><div class="line" id="LC933"><span class="p">Vish</span></div><div class="line" id="LC933"><span class="p"><br></span></div><div><div><div>On Mar 28, 2013, at 1:46 AM, Ajiva Fan <<a href="mailto:aji.zqfan@gmail.com">aji.zqfan@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">hello everyone:<br><br>i have a very simple question which confuses me for a long time:<br>how should i add a network to a project via rest api?<br><br>1) i'm admin of the whole cloud env essex, (i think the folsom is same in this case)<br>
2) using nova-network:vlan (if using flatdhcp, the associate action is meanless)<br>3) a user project "user-project" is created, and the admin:admin is not that project's admin (and even not a member of it)<br>
4) a network "user-network" is created, but not associated with "user-project"<br>5) how to associate the "user-network" with "user-project" ?<br><br>i know i can use "nova-manage" via nova-client in the control node, <br>
but what i need to know is how to do this operation via rest api, like curl or in horizon?<br><br>the rest api is: <a href="http://api.openstack.org/api-ref.html">http://api.openstack.org/api-ref.html</a><br><div class="span1">
<span class="label success">POST</span></div>
<div class="span5">v2/{tenant_id}/os-networks/add <br>with a body identifier the network's id<br><br>the problem is that, even i have admin:admin token, i *cannot* associate the "user-network" with "user-project", <br>
because from the source code of folsom(and essex) nova, in the <a href="http://nova.api.openstack.wsgi.py/">nova.api.openstack.wsgi.py</a> of line 931, i find this:<br></div><div class="line" id="LC931"><span class="n"><br>
project_id</span> <span class="o">=</span> <span class="n">action_args</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">"project_id"</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span></div>
<div class="line" id="LC932"> <span class="n">context</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">environ</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">'nova.context'</span><span class="p">)</span></div>
<div class="line" id="LC933"> <span class="k">if</span> <span class="p">(</span><span class="n">context</span> <span class="ow">and</span> <span class="n">project_id</span> <span class="ow">and</span> <span class="p">(</span><span class="n">project_id</span> <span class="o">!=</span> <span class="n">context</span><span class="o">.</span><span class="n">project_id</span><span class="p">)):</span></div>
<div class="line" id="LC934"> <span class="n">msg</span> <span class="o">=</span> <span class="n">_</span><span class="p">(</span><span class="s">"Malformed request url"</span><span class="p">)</span></div>
<div class="line" id="LC935"> <span class="k">return</span> <span class="n">Fault</span><span class="p">(</span><span class="n">webob</span><span class="o">.</span><span class="n">exc</span><span class="o">.</span><span class="n">HTTPBadRequest</span><span class="p">(</span><span class="n">explanation</span><span class="o">=</span><span class="n">msg</span><span class="p">))<br>
<br>since nova.context.project_id is the project admin_id, and the project_id is extract from the url, <br>so the webob.exc is returned.<br><br>please help me, i read a lot, (both document and source code, i just cannot understand or just miss something important)<br>
but still don't know how to do it.<br></span></div><br>ps: i have sent a mail to openstack-dev on mar 8, but no one reply me. is my question nonsense?<br>Note this mail is not the exactly same as previous one since i've more knowledge of it but the main problem is same<br>
_______________________________________________<br>Mailing list: <a href="https://launchpad.net/~openstack">https://launchpad.net/~openstack</a><br>Post to : <a href="mailto:openstack@lists.launchpad.net">openstack@lists.launchpad.net</a><br>Unsubscribe : <a href="https://launchpad.net/~openstack">https://launchpad.net/~openstack</a><br>More help : <a href="https://help.launchpad.net/ListHelp">https://help.launchpad.net/ListHelp</a><br></blockquote></div><br></div></div></body></html>