X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fopenstack%2Fclient.py;h=40a3f85db88874a76d52bb7ee53972cb40765ebf;hb=1505f3a42ea06ef30959e9e54fa7298eb55d83ee;hp=11d9221c176943e862e7238633a632c54316d88a;hpb=2507c4bc6a6c840ee5fd1099aad520a60d459cfe;p=sfa.git diff --git a/sfa/openstack/client.py b/sfa/openstack/client.py index 11d9221c..40a3f85d 100644 --- a/sfa/openstack/client.py +++ b/sfa/openstack/client.py @@ -1,6 +1,7 @@ from sfa.util.sfalogging import logger +from keystoneclient.v2_0 import client as keystone_client from glance import client as glance_client -from novaclient.v1_1.client import Client +from novaclient.v1_1 import client as nova_client from sfa.util.config import Config @@ -13,7 +14,7 @@ def parse_novarc(filename): parts = line.split('=') if len(parts) > 1: value = parts[1].replace("\'", "") - value = value.replace('\"', '') + value = value.replace('\"', '') opts[parts[0]] = value except: pass @@ -21,16 +22,47 @@ def parse_novarc(filename): return opts +class KeystoneClient: + + def __init__(self, username=None, password=None, tenant=None, url=None, config=None): + if not config: + config = Config() + opts = parse_novarc(config.SFA_NOVA_NOVARC) + if username: + opts['OS_USERNAME'] = username + if password: + opts['OS_PASSWORD'] = password + if tenant: + opts['OS_TENANT_NAME'] = tenant + if url: + opts['OS_AUTH_URL'] = url + self.opts = opts + self.client = keystone_client.Client(username=opts.get('OS_USERNAME'), + password=opts.get('OS_PASSWORD'), + tenant_name=opts.get( + 'OS_TENANT_NAME'), + auth_url=opts.get('OS_AUTH_URL')) + + def connect(self, *args, **kwds): + self.__init__(*args, **kwds) + + def __getattr__(self, name): + return getattr(self.client, name) + + class GlanceClient: + def __init__(self, config=None): if not config: config = Config() opts = parse_novarc(config.SFA_NOVA_NOVARC) - self.client = glance_client.get_client(host='0.0.0.0', - username=opts.get('OS_USERNAME'), - password=opts.get('OS_PASSWORD'), - tenant=opts.get('OS_TENANT_NAME'), + username=opts.get( + 'OS_USERNAME'), + password=opts.get( + 'OS_PASSWORD'), + tenant=opts.get( + 'OS_TENANT_NAME'), auth_url=opts.get('OS_AUTH_URL')) def __getattr__(self, name): @@ -38,23 +70,32 @@ class GlanceClient: class NovaClient: - def __init__(self, config=None): + + def __init__(self, username=None, password=None, tenant=None, url=None, config=None): if not config: config = Config() opts = parse_novarc(config.SFA_NOVA_NOVARC) - - self.client = Client(username=opts.get('OS_USERNAME'), - api_key=opts.get('OS_PASSWORD'), - project_id=opts.get('OS_TENANT_NAME'), - auth_url=opts.get('OS_AUTH_URL'), - region_name='', - extensions=[], - service_type='compute', - service_name='', - ) - + if username: + opts['OS_USERNAME'] = username + if password: + opts['OS_PASSWORD'] = password + if tenant: + opts['OS_TENANT_NAME'] = tenant + if url: + opts['OS_AUTH_URL'] = url + self.opts = opts + self.client = nova_client.Client(username=opts.get('OS_USERNAME'), + api_key=opts.get('OS_PASSWORD'), + project_id=opts.get('OS_TENANT_NAME'), + auth_url=opts.get('OS_AUTH_URL'), + region_name='', + extensions=[], + service_type='compute', + service_name='', + ) + + def connect(self, *args, **kwds): + self.__init__(*args, **kwds) def __getattr__(self, name): return getattr(self.client, name) - -