Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not instance:
Logger.error('Instance Id is not specified')
return None
target_in_active = list(filter(lambda inst: inst.id == instance, active))
if len(target_in_active) > 0:
Logger.error('The instance is already active')
return None
target_in_not_actives = list(filter(lambda inst: inst.id == instance, not_active))
if len(target_in_not_actives) == 0:
Logger.error('The instance is not running')
return None
if len(target_in_not_actives) > 1:
Logger.error('Instances consistancy error: more than one instance with the same id')
return None
return target_in_not_actives
def _verify_md5(self, req, fname):
"""
Verify md5 of a downloaded file if server supports 'content-md5' header.
"""
md5 = file_md5(fname)[0]
content_md5 = self._get_header(req, 'content-md5')
if content_md5 == None:
return True
if md5 != content_md5:
Logger.error('Checksum mismatch')
return False
Logger.debug('Checksum matches')
return True
def unset_target(self, target_conf_file_path):
if not os.path.exists(target_conf_file_path):
Logger.error('Target conf file {} does not exists'.format(
target_conf_file_path))
return 1
if not os.path.isfile(target_conf_file_path):
Logger.error('Target conf file {} exists but it is not a regular file'.format(
target_conf_file_path))
return 1
if open(target_conf_file_path).read() == '':
return 0
os.remove(target_conf_file_path)
open(target_conf_file_path, 'a').close()
return self.commit_if_needed('DVC target unset')
def _push_key(self, key, path):
""" push, aws version """
name = os.path.relpath(path, self._cloud_settings.cache.cache_dir)
cb = self.create_cb_push(name, path)
try:
self.s3.Object(key.bucket, key.name).upload_file(path, Callback=cb)
except Exception as exc:
Logger.error('Failed to upload "{}": {}'.format(path, exc))
return None
progress.finish_target(name)
return path
def _get_target_in_not_active(instance, active, not_active):
if not instance:
Logger.error('Instance Id is not specified')
return None
target_in_active = list(filter(lambda inst: inst.id == instance, active))
if len(target_in_active) > 0:
Logger.error('The instance is already active')
return None
target_in_not_actives = list(filter(lambda inst: inst.id == instance, not_active))
if len(target_in_not_actives) == 0:
Logger.error('The instance is not running')
return None
if len(target_in_not_actives) > 1:
Logger.error('Instances consistancy error: more than one instance with the same id')
return None
return target_in_not_actives
def _get_target_in_not_active(instance, active, not_active):
if not instance:
Logger.error('Instance Id is not specified')
return None
target_in_active = list(filter(lambda inst: inst.id == instance, active))
if len(target_in_active) > 0:
Logger.error('The instance is already active')
return None
target_in_not_actives = list(filter(lambda inst: inst.id == instance, not_active))
if len(target_in_not_actives) == 0:
Logger.error('The instance is not running')
return None
if len(target_in_not_actives) > 1:
Logger.error('Instances consistancy error: more than one instance with the same id')
return None
return target_in_not_actives
def _import(self, bucket, i, path):
inp = os.path.join(self.storage_path, i)
tmp_file = self.tmp_file(path)
try:
copyfile(inp, tmp_file)
except Exception as exc:
Logger.error('Failed to copy "{}": {}'.format(i, exc))
return None
os.rename(tmp_file, path)
return path
def _get_target_in_not_active(instance, active, not_active):
if not instance:
Logger.error('Instance Id is not specified')
return None
target_in_active = list(filter(lambda inst: inst.id == instance, active))
if len(target_in_active) > 0:
Logger.error('The instance is already active')
return None
target_in_not_actives = list(filter(lambda inst: inst.id == instance, not_active))
if len(target_in_not_actives) == 0:
Logger.error('The instance is not running')
return None
if len(target_in_not_actives) > 1:
Logger.error('Instances consistancy error: more than one instance with the same id')
return None