Exemple #1
0
def _check_import(isamAppliance, id, filename, check_mode=False):
    """
    Checks if file on the Appliance exists and if so, whether it is different from filename
    """
    tmpdir = get_random_temp_dir()
    tmp_original_file = os.path.join(tmpdir, os.path.basename(id))
    if _check(isamAppliance, id):
        export_file(isamAppliance,
                    id,
                    tmp_original_file,
                    check_mode=False,
                    force=True)
        logger.debug("file already exists on appliance")
        if files_same(tmp_original_file, filename):
            logger.debug("files are the same, so we don't want to do anything")
            shutil.rmtree(tmpdir)
            return False
        else:
            logger.debug(
                "files are different, so we delete existing file in preparation for import"
            )
            delete(isamAppliance, id, check_mode=check_mode, force=True)
            shutil.rmtree(tmpdir)
            return True
    else:
        logger.debug(
            "file does not exist on appliance, so we'll want to import")
        shutil.rmtree(tmpdir)
        return True
Exemple #2
0
def _check_import(isamAppliance, filename, check_mode=False):
    """
    Checks if file on the Appliance exists and if so, whether it is different from filename
    """
    (d, f) = os.path.split(
        filename
    )  # this means the name of the bundle has to match name of file to import
    ret_obj = get(isamAppliance, f)
    tmpdir = tempfile.gettempdir()
    if ret_obj['data']:
        tmp_original_file = os.path.join(tmpdir, ret_obj['data']['filename'])
        export_bundle(isamAppliance,
                      ret_obj['data']['filename'],
                      tmp_original_file,
                      check_mode=False,
                      force=True)
        logger.debug("file already exists on appliance")
        if files_same(tmp_original_file, filename):
            logger.debug("files are the same, so we don't want to do anything")
            return False
        else:
            logger.debug("files are different, so we replace existing file")
            bundle_id = ret_obj['data']['id']
            return bundle_id
    else:
        logger.debug(
            "file does not exist on appliance, so we'll want to create a bundle and then import"
        )
        create_ret_obj = create(isamAppliance,
                                filename,
                                check_mode,
                                force=True)
        if create_ret_obj:
            bundle_id = get(isamAppliance, f)['data']['id']
            return bundle_id
def _check_import(isamAppliance, filename):
    """
    Checks if file on the Appliance exists and if so, whether it is different from filename
    """
    warnings = []
    (d, f) = os.path.split(filename)  # this means the name of the bundle has to match name of file to import
    ret_obj = get(isamAppliance, f)
    tmpdir = get_random_temp_dir()
    if ret_obj['data'] != {} and ret_obj['data']['extensions'] != []:
        tmp_original_file = os.path.join(tmpdir, ret_obj['data']['filename'])
        export_bundle(isamAppliance, ret_obj['data']['filename'], tmp_original_file, check_mode=False, force=True)
        logger.debug("file already exists on appliance")
        if files_same(tmp_original_file, filename):
            logger.debug("files are the same, so we don't want to do anything")
            shutil.rmtree(tmpdir)
            return warnings, False
        else:
            logger.debug("files are different, so we replace existing file")
            bundle_id = ret_obj['data']['id']
            shutil.rmtree(tmpdir)
            return warnings, bundle_id
    elif ret_obj['data'] != {} and ret_obj['data']['extensions'] == []:
        bundle_id = ret_obj['data']['id']
        return warnings, bundle_id
    else:
        warnings.append("Bundle does not exist on appliance, create a bundle first and then import.")
        return warnings, False
Exemple #4
0
def _check_import(isamAppliance, id, filepath):
    """
    Checks if the file to be imported is the same as the file that's already on the instance
    """
    tmpdir = get_random_temp_dir()
    tmp_original_file = os.path.join(tmpdir, os.path.basename("tempfile.txt"))

    export_file(isamAppliance, instance_id=id, filepath=tmp_original_file, check_mode=False, force=True)

    if files_same(tmp_original_file, filepath):
        logger.debug("files are the same, so we don't want to do anything")
        shutil.rmtree(tmpdir)
        return False
    else:
        logger.debug("files are different, so we return True to indicate the new file should be imported")
        shutil.rmtree(tmpdir)
        return True