1

I was trying to create a driver for openstack using apache libcloud. It doesn't raise any error even if the user credentials are wrong. So When i checked the faq i found an answer as given in the link Apache libcloud FAQ

But it doesn't seem to be effective since querying each time to check whether the user is authenticated will reduce the performance if the query returns a bulk of data.

When i checked the response i got from the api there is a field called driver.connection.auth_user_info and i found that the field is empty if the user is not authenticated. So can i use this method as a standard? Any help is appreciated

midhun
  • 157
  • 2
  • 2
  • 10

1 Answers1

1

An openstack driver for libcloud is already available:

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

os = get_driver(Provider.OPENSTACK)
params = {'key': 'username', 'ex_force_service_region':'regionOne', 
   'ex_force_service_name':'nova', 'ex_force_auth_version':'2.0_password',
   'ex_force_auth_url':'http://127.0.0.1:5000',
   'ex_force_service_type':'compute', 'secret':'password',
   'ex_tenant_name':'tenant'}
driver = os(**params)

But libcloud does not check the credentials by just creating the driver object. Instead, the creds will be validated only when a request is sent. If the internal exception InvalidCredsError is thrown the credentials are invalid, and an own variable could be set:

from libcloud.common.types import InvalidCredsError

validcreds = False

try:
    nodes = driver.list_nodes()
    if nodes.count >= 0:
        validcreds = True
except InvalidCredsError:
    print "Invalid credentials"
except Exception as e:
    print str(e)

I would not rely on the internal variable auth_user_info because it could change over time.

admirableadmin
  • 2,669
  • 1
  • 24
  • 41
  • when there are many nodes for that user this query will be expensive right? – midhun Jan 29 '15 at 12:19
  • The solution you provided is already there in the FAQ link and i was asking for any better solution – midhun Jan 29 '15 at 12:25
  • By storing the result of your **first time** credential check, there is no need to repeat it **each time**. To reduce the response you can use any other command like `driver.list_sizes()`or `driver.list_images()`. Later you only check the variable, so you get a performance enhancement. – admirableadmin Jan 29 '15 at 12:51
  • Okay. I was trying to memcache the driver object so that i can use it without querying it for each time. But it raises `expected string or Unicode object, NoneType found` and type of my object is ` ` – midhun Jan 30 '15 at 05:46