Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_raw(self, *args, **kwargs):
response = self._request(*args, **kwargs)
if not response.body:
raise exceptions.PyLXDException('Null Body')
elif response.status == 200:
return response.body
else:
raise exceptions.PyLXDException('Failed to get raw response')
def get_raw(self, *args, **kwargs):
response = self._request(*args, **kwargs)
if not response.body:
raise exceptions.PyLXDException('Null Body')
elif response.status == 200:
return response.body
else:
raise exceptions.PyLXDException('Failed to get raw response')
def get_object(self, *args, **kwargs):
response = self._request(*args, **kwargs)
if not response.json:
raise exceptions.PyLXDException('Null Data')
elif response.status == 200 or (
response.status == 202 and
response.json.get('status_code') == 100):
return response.status, response.json
else:
utils.get_lxd_error(response.status, response.json)
def host_ping(self):
try:
return self.connection.get_status('GET', '/1.0')
except Exception as e:
msg = 'LXD service is unavailable. %s' % e
raise exceptions.PyLXDException(msg)
def container_defined(self, container):
_, data = self.connection.get_object('GET', '/1.0/containers')
try:
containers = data["metadata"]
except KeyError:
raise exceptions.PyLXDException("no metadata in GET containers?")
container_url = "/1.0/containers/%s" % container
for ct in containers:
if ct == container_url:
return True
return False
def get_certificate(self):
try:
(state, data) = self.connection.get_object('GET', '/1.0')
data = data.get('metadata')
return data['environment']['certificate']
except exceptions.PyLXDException as e:
print('Handling run-time error: {}'.format(e))
def get_status(self, *args, **kwargs):
response = self._request(*args, **kwargs)
if not response.json:
raise exceptions.PyLXDException('Null Data')
elif response.json.get('error'):
utils.get_lxd_error(response.status, response.json)
elif response.status == 200 or (
response.status == 202 and
response.json.get('status_code') == 100):
return True
return False