Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.ssl_key = extra_parms["ssl_key"]
self.ssl_cert = extra_parms["ssl_cert"]
for _endpoint in access.split(',') :
_endpoint_name, _endpoint_ip = hostname2ip(_endpoint.split('//')[1].split(':')[0], True)
if _endpoint_ip not in self.lxdconn :
self.lxdconn[_endpoint_ip] = Client(endpoint = _endpoint, cert = (self.ssl_cert, self.ssl_key), verify = False)
self.lxdconn[_endpoint_ip].authenticate(credentials)
if not self.lxdconn[_endpoint_ip].trusted :
_fmsg = "Unable to authenticate"
_status = 101
_status -= 100
except LXDError.ClientConnectionFailed, obj:
_status = 18127
_fmsg = str(obj.message)
except LXDError.LXDAPIException, obj:
_status = 18127
_fmsg = str(obj)
except Exception, e :
_status = 23
_fmsg = str(e)
finally :
if _status :
_msg = self.get_description() + " connection to endpoint \"" + _endpoint_ip + "\" failed: " + _fmsg
cberr(_msg)
raise CldOpsException(_msg, _status)
key
)
)
log.debug((
'Trying to connecto to "{0}" '
'with cert "{1}", key "{2}" and '
'verify_cert "{3!s}"'.format(
remote_addr, cert, key, verify_cert)
))
client = pylxd.Client(
endpoint=remote_addr,
cert=(cert, key,),
verify=verify_cert
)
except pylxd.exceptions.ClientConnectionFailed:
raise CommandExecutionError(
"Failed to connect to '{0}'".format(remote_addr)
)
except TypeError as e:
# Happens when the verification failed.
raise CommandExecutionError(
('Failed to connect to "{0}",'
' looks like the SSL verification failed, error was: {1}'
).format(remote_addr, six.text_type(e))
)
_connection_pool[pool_key] = client
return client
else:
path = '/var/lib/lxd/unix.socket'
endpoint = 'http+unix://{}'.format(parse.quote(path, safe=''))
self.api = _APINode(endpoint, timeout=timeout)
self.api = self.api[version]
# Verify the connection is valid.
try:
response = self.api.get()
if response.status_code != 200:
raise exceptions.ClientConnectionFailed()
self.host_info = response.json()['metadata']
except (requests.exceptions.ConnectionError,
requests.exceptions.InvalidURL) as e:
raise exceptions.ClientConnectionFailed(str(e))
self.cluster = managers.ClusterManager(self)
self.certificates = managers.CertificateManager(self)
self.containers = managers.ContainerManager(self)
self.images = managers.ImageManager(self)
self.networks = managers.NetworkManager(self)
self.operations = managers.OperationManager(self)
self.profiles = managers.ProfileManager(self)
self.storage_pools = managers.StoragePoolManager(self)
else:
if 'LXD_DIR' in os.environ:
path = os.path.join(os.environ.get('LXD_DIR'), 'unix.socket')
elif os.path.exists('/var/snap/lxd/common/lxd/unix.socket'):
path = '/var/snap/lxd/common/lxd/unix.socket'
else:
path = '/var/lib/lxd/unix.socket'
endpoint = 'http+unix://{}'.format(parse.quote(path, safe=''))
self.api = _APINode(endpoint, timeout=timeout)
self.api = self.api[version]
# Verify the connection is valid.
try:
response = self.api.get()
if response.status_code != 200:
raise exceptions.ClientConnectionFailed()
self.host_info = response.json()['metadata']
except (requests.exceptions.ConnectionError,
requests.exceptions.InvalidURL) as e:
raise exceptions.ClientConnectionFailed(str(e))
self.cluster = managers.ClusterManager(self)
self.certificates = managers.CertificateManager(self)
self.containers = managers.ContainerManager(self)
self.images = managers.ImageManager(self)
self.networks = managers.NetworkManager(self)
self.operations = managers.OperationManager(self)
self.profiles = managers.ProfileManager(self)
self.storage_pools = managers.StoragePoolManager(self)