X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetstack%2Fopenstack%2Fclient.py;h=d776ec97fb7f7f9ab897b3920a449a3430fe47ed;hb=c68a3b476e191e88ba481b434b15993dae07dde7;hp=b21c34137ba6c05f16ac7791457687d836a0ce04;hpb=b0d9742e1a7746ea0d8cbf78d85cab38883a8edc;p=plstackapi.git diff --git a/planetstack/openstack/client.py b/planetstack/openstack/client.py index b21c341..d776ec9 100644 --- a/planetstack/openstack/client.py +++ b/planetstack/openstack/client.py @@ -1,8 +1,10 @@ +import urlparse try: from keystoneclient.v2_0 import client as keystone_client - from glance import client as glance_client + #from glance import client as glance_client + import glanceclient from novaclient.v1_1 import client as nova_client - from quantumclient.v2_0 import client as quantum_client + from neutronclient.v2_0 import client as quantum_client from nova.db.sqlalchemy import api as nova_db_api from nova.context import get_admin_context has_openstack = True @@ -36,16 +38,20 @@ def parse_novarc(filename): return opts class Client: - def __init__(self, username=None, password=None, tenant=None, url=None, config=None, *args, **kwds): - if config: - config = Config(config) - else: - config = Config() + def __init__(self, username=None, password=None, tenant=None, url=None, token=None, endpoint=None, controller=None, admin=True, *args, **kwds): + + deployment = controller + self.has_openstack = has_openstack - self.username = config.nova_admin_user - self.password = config.nova_admin_password - self.tenant = config.nova_admin_tenant - self.url = config.nova_url + self.url = deployment.auth_url + if admin: + self.username = deployment.admin_user + self.password = deployment.admin_password + self.tenant = deployment.admin_tenant + else: + self.username = None + self.password = None + self.tenant = None if username: self.username = username @@ -55,9 +61,13 @@ class Client: self.tenant = tenant if url: self.url = url + if token: + self.token = token + if endpoint: + self.endpoint = endpoint - if '@' in self.username: - self.username = self.username[:self.username.index('@')] + #if '@' in self.username: + # self.username = self.username[:self.username.index('@')] class KeystoneClient(Client): def __init__(self, *args, **kwds): @@ -66,7 +76,8 @@ class KeystoneClient(Client): self.client = keystone_client.Client(username=self.username, password=self.password, tenant_name=self.tenant, - auth_url=self.url) + auth_url=self.url + ) @require_enabled def connect(self, *args, **kwds): @@ -81,7 +92,7 @@ class GlanceClient(Client): def __init__(self, *args, **kwds): Client.__init__(self, *args, **kwds) if has_openstack: - self.client = glance_client.get_client(host='0.0.0.0', + self.client = glanceclient.get_client(host='0.0.0.0', username=self.username, password=self.password, tenant=self.tenant, @@ -90,6 +101,16 @@ class GlanceClient(Client): def __getattr__(self, name): return getattr(self.client, name) +class GlanceClientNew(Client): + def __init__(self, version, endpoint, token, *args, **kwds): + Client.__init__(self, *args, **kwds) + if has_openstack: + self.client = glanceclient.Client(version, endpoint=endpoint, token=token) + + @require_enabled + def __getattr__(self, name): + return getattr(self.client, name) + class NovaClient(Client): def __init__(self, *args, **kwds): Client.__init__(self, *args, **kwds) @@ -117,7 +138,7 @@ class NovaDB(Client): Client.__init__(self, *args, **kwds) if has_openstack: self.ctx = get_admin_context() - api.FLAGS(default_config_files=['/etc/nova/nova.conf']) + nova_db_api.FLAGS(default_config_files=['/etc/nova/nova.conf']) self.client = nova_db_api @@ -154,10 +175,16 @@ class OpenStackClient: def __init__ ( self, *args, **kwds) : # instantiate managers self.keystone = KeystoneClient(*args, **kwds) - self.glance = GlanceClient(*args, **kwds) + url_parsed = urlparse.urlparse(self.keystone.url) + hostname = url_parsed.netloc.split(':')[0] + token = self.keystone.client.tokens.authenticate(username=self.keystone.username, password=self.keystone.password, tenant_name=self.keystone.tenant) + #self.glance = GlanceClient(*args, **kwds) + + self.glanceclient = GlanceClientNew('1', endpoint='http://%s:9292' % hostname, token=token.id, **kwds) self.nova = NovaClient(*args, **kwds) - self.nova_db = NovaDB(*args, **kwds) + # self.nova_db = NovaDB(*args, **kwds) self.quantum = QuantumClient(*args, **kwds) + @require_enabled def connect(self, *args, **kwds):