[CORD-1360] Using new config
Change-Id: I2689f6f5781c0ad040a5e953fcacb224d22ef655
diff --git a/xos/synchronizer/client.py b/xos/synchronizer/client.py
index d1383f4..872ab89 100644
--- a/xos/synchronizer/client.py
+++ b/xos/synchronizer/client.py
@@ -1,17 +1,20 @@
import urlparse
+
try:
from keystoneauth1.identity import v2 as keystoneauth_v2
from keystoneauth1 import session as keystone_session
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.v2 import client as nova_client
- from neutronclient.v2_0 import client as neutron_client
+ from neutronclient.v2_0 import client as neutron_client
+
has_openstack = True
except:
has_openstack = False
-from xos.config import Config
+from xosconfig import Config
+
def require_enabled(callable):
def wrapper(*args, **kwds):
@@ -19,8 +22,10 @@
return callable(*args, **kwds)
else:
return None
+
return wrapper
+
def parse_novarc(filename):
opts = {}
f = open(filename, 'r')
@@ -37,9 +42,11 @@
f.close()
return opts
+
class Client:
- def __init__(self, username=None, password=None, tenant=None, url=None, token=None, endpoint=None, controller=None, cacert=None, admin=True, *args, **kwds):
-
+ def __init__(self, username=None, password=None, tenant=None, url=None, token=None, endpoint=None, controller=None,
+ cacert=None, admin=True, *args, **kwds):
+
self.has_openstack = has_openstack
self.url = controller.auth_url
if admin:
@@ -60,17 +67,15 @@
if url:
self.url = url
if token:
- self.token = token
+ self.token = token
if endpoint:
self.endpoint = endpoint
if cacert:
self.cacert = cacert
else:
- self.cacert = getattr(Config(), "nova_ca_ssl_cert", "None")
+ self.cacert = Config.get("nova.ca_ssl_cert")
- #if '@' in self.username:
- # self.username = self.username[:self.username.index('@')]
class KeystoneClient(Client):
def __init__(self, *args, **kwds):
@@ -98,46 +103,49 @@
Client.__init__(self, *args, **kwds)
if has_openstack:
self.client = glanceclient.get_client(host='0.0.0.0',
- username=self.username,
- password=self.password,
- tenant=self.tenant,
- auth_url=self.url,
- cacert=self.cacert
- )
+ username=self.username,
+ password=self.password,
+ tenant=self.tenant,
+ auth_url=self.url,
+ cacert=self.cacert
+ )
+
@require_enabled
def __getattr__(self, name):
return getattr(self.client, name)
+
class GlanceClient(Client):
def __init__(self, version, endpoint, token, cacert=None, *args, **kwds):
Client.__init__(self, *args, **kwds)
if has_openstack:
- self.client = glanceclient.Client(version,
- endpoint=endpoint,
- token=token,
- cacert=cacert
- )
+ self.client = glanceclient.Client(version,
+ endpoint=endpoint,
+ token=token,
+ cacert=cacert
+ )
@require_enabled
def __getattr__(self, name):
- return getattr(self.client, name)
+ return getattr(self.client, name)
+
class NovaClient(Client):
def __init__(self, *args, **kwds):
Client.__init__(self, *args, **kwds)
if has_openstack:
self.client = nova_client.client.Client(
- "2",
- username=self.username,
- api_key=self.password,
- project_id=self.tenant,
- auth_url=self.url,
- region_name='',
- extensions=[],
- service_type='compute',
- service_name='',
- cacert=self.cacert
- )
+ "2",
+ username=self.username,
+ api_key=self.password,
+ project_id=self.tenant,
+ auth_url=self.url,
+ region_name='',
+ extensions=[],
+ service_type='compute',
+ service_name='',
+ cacert=self.cacert
+ )
@require_enabled
def connect(self, *args, **kwds):
@@ -147,6 +155,7 @@
def __getattr__(self, name):
return getattr(self.client, name)
+
class NovaDB(Client):
def __init__(self, *args, **kwds):
Client.__init__(self, *args, **kwds)
@@ -155,7 +164,6 @@
nova_db_api.FLAGS(default_config_files=['/etc/nova/nova.conf'])
self.client = nova_db_api
-
@require_enabled
def connect(self, *args, **kwds):
self.__init__(*args, **kwds)
@@ -164,6 +172,7 @@
def __getattr__(self, name):
return getattr(self.client, name)
+
class NeutronClient(Client):
def __init__(self, *args, **kwds):
Client.__init__(self, *args, **kwds)
@@ -174,6 +183,7 @@
auth_url=self.url,
ca_cert=self.cacert
)
+
@require_enabled
def connect(self, *args, **kwds):
self.__init__(*args, **kwds)
@@ -182,24 +192,26 @@
def __getattr__(self, name):
return getattr(self.client, name)
+
class OpenStackClient:
"""
A simple native shell to the openstack backend services.
This class can receive all nova calls to the underlying testbed
"""
- def __init__ ( self, *args, **kwds) :
+ def __init__(self, *args, **kwds):
# instantiate managers
self.keystone = KeystoneClient(*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)
-# glance_endpoint = self.keystone.client.service_catalog.url_for(service_type='image', endpoint_type='publicURL')
-# self.glanceclient = GlanceClient('1', endpoint=glance_endpoint, token=token.id, **kwds)
+ token = self.keystone.client.tokens.authenticate(username=self.keystone.username,
+ password=self.keystone.password,
+ tenant_name=self.keystone.tenant)
+ # glance_endpoint = self.keystone.client.service_catalog.url_for(service_type='image', endpoint_type='publicURL')
+ # self.glanceclient = GlanceClient('1', endpoint=glance_endpoint, token=token.id, **kwds)
self.nova = NovaClient(*args, **kwds)
# self.nova_db = NovaDB(*args, **kwds)
self.neutron = NeutronClient(*args, **kwds)
-
@require_enabled
def connect(self, *args, **kwds):