How to use the freezer.utils.winutils function in freezer

To help you get started, we’ve selected a few freezer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstack / freezer / tests / unit / utils / test_winutils.py View on Github external
def test_is_windows(self):
        fake_os = Os()
        os.name = fake_os
        assert winutils.is_windows() is False
github openstack / freezer / freezer / scheduler / freezer_scheduler.py View on Github external
sys.exit(1)
    else:
        if winutils.is_windows():
            print("--no-api mode is not available on windows")
            return 69  # os.EX_UNAVAILABLE

    freezer_utils.create_dir(CONF.jobs_dir, do_log=False)
    freezer_scheduler = FreezerScheduler(apiclient=apiclient,
                                         interval=int(CONF.interval),
                                         job_path=CONF.jobs_dir,
                                         concurrent_jobs=CONF.concurrent_jobs)

    if CONF.no_daemon:
        print('Freezer Scheduler running in no-daemon mode')
        LOG.debug('Freezer Scheduler running in no-daemon mode')
        if winutils.is_windows():
            daemon = win_daemon.NoDaemon(daemonizable=freezer_scheduler)
        else:
            daemon = linux_daemon.NoDaemon(daemonizable=freezer_scheduler)
    else:
        if winutils.is_windows():
            daemon = win_daemon.Daemon(daemonizable=freezer_scheduler,
                                       interval=int(CONF.interval),
                                       job_path=CONF.jobs_dir,
                                       insecure=CONF.insecure,
                                       concurrent_jobs=CONF.concurrent_jobs)
        else:
            daemon = linux_daemon.Daemon(daemonizable=freezer_scheduler)

    if CONF.action == 'start':
        daemon.start()
    elif CONF.action == 'stop':
github openstack / freezer / freezer / snapshot / vss.py View on Github external
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\VolSnap


    Freezer create a shadow copy for each time the client runs it's been
    removed after the backup is complete.

    :param volume: The letter of the windows volume e.g. c:\\
    :return: shadow_id: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
    :return: shadow_path: shadow copy path
    """
    shadow_path = None
    shadow_id = None

    vss_delete_symlink(windows_volume)

    with winutils.DisableFileSystemRedirection():
        path = os.path.dirname(os.path.abspath(__file__))
        script = '{0}\\scripts\\vss.ps1'.format(path)
        (out, err) = utils.create_subprocess(
            ['powershell.exe', '-executionpolicy', 'unrestricted',
             '-command', script, '-volume', windows_volume])
        if err != '':
            raise Exception('[*] Error creating a new shadow copy on {0}'
                            ', error {1}' .format(windows_volume, err))

        for line in out.split('\n'):
            if 'symbolic' in line:
                shadow_path = line.split('>>')[1].strip()
            if '__RELPATH' in line:
                shadow_id = line.split('=')[1].strip().lower() + '}'
                shadow_id = shadow_id[1:]
github openstack / freezer / freezer / engine / rsync / rsync.py View on Github external
def __init__(
            self, compression, symlinks, exclude, storage,
            max_segment_size, encrypt_key=None,
            dry_run=False, **kwargs):
        self.compression_algo = compression
        self.encrypt_pass_file = encrypt_key
        self.dereference_symlink = symlinks
        self.exclude = exclude
        self.storage = storage
        self.is_windows = winutils.is_windows()
        self.dry_run = dry_run
        self.max_segment_size = max_segment_size
        # Compression and encryption objects
        self.compressor = None
        self.cipher = None
        super(RsyncEngine, self).__init__(storage=storage)
github openstack / freezer / freezer / common / config.py View on Github external
backup_args.nova_inst_name):
        backup_media = 'nova'
    elif backup_args.engine_name == 'glance':
        if (backup_args.project_id or backup_args.glance_image_id or
                backup_args.glance_image_name or
                backup_args.glance_image_name_filter):
            backup_media = 'glance'
    elif backup_args.cinderbrick_vol_id:
        backup_media = 'cinderbrick'

    backup_args.__dict__['backup_media'] = backup_media

    backup_args.__dict__['time_stamp'] = None

    if backup_args.upload_limit != -1 or backup_args.download_limit != -1 and \
            not winutils.is_windows():
        # handle --config option with tmp config file
        if backup_args.config:
            conf_file = tempfile.NamedTemporaryFile(prefix='freezer_job_',
                                                    delete=False)
            # remove the limits from the new file
            if 'upload_limit' in conf.default:
                conf.default.pop('upload_limit')
            elif 'download_limit' in conf.default:
                conf.default.pop('download_limit')

            utils.save_config_to_file(conf.default, conf_file,
                                      'default')
            # replace the original file with the tmp one
            conf_index = sys.argv.index('--config') + 1
            sys.argv[conf_index] = conf_file.name
github openstack / freezer / freezer / scheduler / win_service.py View on Github external
def main(self):
        from freezer.scheduler.freezer_scheduler import FreezerScheduler
        from freezerclient.v1.client import Client

        servicemanager.LogMsg(
            servicemanager.EVENTLOG_INFORMATION_TYPE,
            servicemanager.PYS_SERVICE_STARTED,
            (self._svc_name_, ''))

        winutils.set_environment(self.home)

        if os.environ.get('SERVICE_INSECURE'):
            self.insecure = True

        # Add support for keystone v2 and v3
        credentials = {}
        if os.environ['OS_IDENTITY_API_VERSION'] == 2:
            credentials = {
                'version': 2,
                'username': os.environ['OS_USERNAME'],
                'password': os.environ['OS_PASSWORD'],
                'auth_url': os.environ['OS_AUTH_URL'],
                'endpoint': os.environ['OS_BACKUP_URL'],
                'tenant_name': os.environ['OS_TENANT_NAME'],
                'insecure': self.insecure
            }
github openstack / freezer / freezer / utils / utils.py View on Github external
def tar_path():
    """This function returns tar binary path"""
    from freezer.utils import winutils
    if winutils.is_windows():
        path_to_binaries = os.path.dirname(os.path.abspath(__file__))
        return '{0}\\bin\\tar.exe'.format(path_to_binaries)

    tar = (get_executable_path('gnutar') or get_executable_path('gtar') or
           get_executable_path('tar'))
    if not tar:
        raise Exception('Please install gnu tar (gtar) as it is a '
                        'mandatory requirement to use freezer.')
    return tar
github openstack / freezer / freezer / engine / tar / tar.py View on Github external
def __init__(
            self, compression, symlinks, exclude, storage,
            max_segment_size, encrypt_key=None,
            dry_run=False, **kwargs):
        """
            :type storage: freezer.storage.base.Storage
        :return:
        """
        self.compression_algo = compression
        self.encrypt_pass_file = encrypt_key
        self.dereference_symlink = symlinks
        self.exclude = exclude
        self.storage = storage
        self.is_windows = winutils.is_windows()
        self.dry_run = dry_run
        self.max_segment_size = max_segment_size
        super(TarEngine, self).__init__(storage=storage)
github openstack / freezer / freezer / engine / tar / tar.py View on Github external
raise Exception("Cannot restore encrypted backup without key")

            tar_command = tar_builders.TarCommandRestoreBuilder(
                restore_resource,
                metadata.get('compression', self.compression_algo),
                self.is_windows)

            if self.encrypt_pass_file:
                tar_command.set_encryption(self.encrypt_pass_file)

            if self.dry_run:
                tar_command.set_dry_run()

            command = tar_command.build()

            if winutils.is_windows():
                # on windows, chdir to restore path.
                os.chdir(restore_resource)

            tar_process = subprocess.Popen(
                command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
                stderr=subprocess.PIPE, shell=True, executable='/bin/bash')
            # Start loop reading the pipe and pass the data to the tar
            # std input. If EOFError exception is raised, the loop end
            # the std err will be checked for errors.
            try:
                while True:
                    tar_process.stdin.write(read_pipe.recv_bytes())
            except EOFError:
                LOG.info('Pipe closed as EOF reached. '
                         'Data transmitted successfully')
            finally:
github openstack / freezer / freezer / scheduler / win_daemon.py View on Github external
def start(self, log_file=None):
        """Initialize freezer-scheduler instance inside a windows service
        """
        setup_logging(log_file)

        utils.create_dir(self.home)

        if self.insecure:
            os.environ['SERVICE_INSECURE'] = 'True'

        # send arguments info to the windows service
        os.environ['SERVICE_JOB_PATH'] = self.job_path
        os.environ['SERVICE_INTERVAL'] = str(self.interval)
        os.environ['SERVICE_CONCURRENT_JOBS'] = str(self.concurrent_jobs)

        winutils.save_environment(self.home)

        print('Freezer Service is starting')
        win32serviceutil.StartService(self.service_name)