[openstack-dev] [nova-network]add a network to project via rest api

Ajiva Fan aji.zqfan at gmail.com
Fri Mar 8 10:07:02 UTC 2013


hello, stackers

i find the api from http://api.openstack.org/api-ref.html
POST   v2/{tenant_id}/os-networks/add  Add a network to a project.

so, how do i add a network to a project
if tenant is admin tenant, is ok
but if tenant is not admin tenant, then i cannot use token of admin
user in admin tenant to add a network to other tenant, am i right?

so the https://github.com/openstack/nova/blob/master/nova/api/openstack/compute/contrib/os_networks.py
just fetch network id from request body and fetch project from
context, which exactly means from url.

why the contributors of os_networks.py don't fetch
{"network-id":"","project-id":""} from body, so i can easily add a
network to any project,

the fix is easy, just change the line 134
      project_id = context.project_id
to
      project_id = body.get("project-id") or context.project_id

so, can any one explain to me that if there is some reason (such as
security?) block me to do this, how could i add a network to any
project id i want. because i'm admin of the whole system, i can add it
to the project via CLI, but i don't know how to add it via REST

ps:
i tried admin:admin and admin:None token, but admin is not a member of
that tenant (for example "fan-project" in my case), so i got {"error":
{"message": "Invalid tenant", "code": 401, "title": "Not Authorized"}}



More information about the OpenStack-dev mailing list