Report this

What is the reason for this report?

how to set quota with python in openstack

Posted on September 8, 2016

got error when set quota in RDO or production environment of openstack

already set insecure = True, but can not set quota

>>> nc.quotas.update(my_tenant.id, floating_ips=1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/novaclient/v2/quotas.py", line 57, in update
    return self._update(url, body, 'quota_set')
  File "/usr/lib/python2.7/site-packages/novaclient/base.py", line 182, in _update
    _resp, body = self.api.client.put(url, body=body)
  File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 452, in put
    return self._cs_request(url, 'PUT', **kwargs)
  File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 402, in _cs_request
    self.authenticate()
  File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 555, in authenticate
    auth_url = self._v2_auth(auth_url)
  File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 646, in _v2_auth
    return self._authenticate(url, body)
  File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 659, in _authenticate
    **kwargs)
  File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 397, in _time_request
    resp, body = self.request(url, method, **kwargs)
  File "/usr/lib/python2.7/site-packages/novaclient/client.py", line 391, in request
    raise exceptions.from_response(resp, body, url, method)
novaclient.exceptions.Unauthorized: The request you have made requires authentication. (HTTP 401)


   from keystoneclient.v2_0.client import Client
import os
import csv
import sys
import logging
import time
from nova import db
from nova import config
from nova import context
import argparse
import novaclient.v1_1.client as nvclient


def get_nova_credentials_v2():
    d = {}
    d['version'] = '2'
    d['username'] = os.environ['OS_USERNAME']
    d['password'] = os.environ['OS_PASSWORD']
    d['auth_url'] = os.environ['OS_AUTH_URL']
    d['tenant_name'] = os.environ['OS_TENANT_NAME']
    d['insecure'] = "True"
    return d


credentials = get_nova_credentials_v2()
keystone_client = Client(**credentials)
tenants = keystone_client.tenants.list()
rolelist = keystone_client.roles.list()
userlist = keystone_client.users.list()
my_admin = [x for x in rolelist if x.name=="admin"][0]
my_member = [x for x in rolelist if x.name=="_member_"][0]
my_admin_user = [x for x in userlist if x.name=="admin"][0]

my_tenant = [x for x in tenants if x.name=="hello"][0]
nc = nvclient.Client(None, None, None, auth_url=os.environ['OS_AUTH_URL'], tenant_id=my_tenant.id, auth_token=keystone_client.auth_token, insecure='True')
nc.quotas.update(my_tenant.id, floating_ips=1)


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

While I am no expert on OpenStack (DO uses KVM) a little bit of digging leads me to believe that while “insecure=true” can be useful when running with self-signed certificates, preventing their use from causing errors you will likely still need to specify an authenticated user in order to set quota.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.