Example #1
0
async def watchdog(instance_id):
    while True:
        await asyncio.sleep(int(config.watchdog_delay))
        instance = Instance(instance_id)

        if instance.status in WATCH_STATUS:
            logger.info(
                f'Instance {instance.name} is {instance.status}. Working..')
            await instance.async_operation_complete(instance.start())
Example #2
0
async def async_snapshots_cleaner(instance):
    vm = Instance(instance)
    logger.info(
        f'Search and deleting snapshots older than {config.lifetime} days for instance {vm.name}'
    )
    snapshots = vm.get_old_snapshots()

    if not snapshots:
        logger.info(
            f'Snapshots older than {config.lifetime} days not found for instance {vm.name}'
        )
        return

    for snapshot in snapshots:
        await vm.async_operation_complete(vm.delete_snapshot(data=snapshot))
Example #3
0
def snapshots_cleaner():
    logger.info(
        f'Search and deleting snapshots older than {config.lifetime} days')
    for instance in INSTANCES:
        vm = Instance(instance)
        snapshots = vm.get_old_snapshots()

        if not snapshots:
            logger.info(
                f'Snapshots older than {config.lifetime} days not found for instance {vm.name}'
            )
            continue

        for snapshot in snapshots:
            delete_snap = vm.delete_snapshot(data=snapshot)
            if vm.operation_complete(delete_snap):
                continue
Example #4
0
async def async_snapshots_creater(instance):
    vm = Instance(instance)
    logger.info(f'Preparing instance {vm.name} to create a snapshot')
    if vm.get_data():
        if vm.status not in NEGATIVE_STATES:
            stop_vm = vm.operation_complete(vm.stop())
            STOPPED_INSTANCES.append(instance)
            if stop_vm:
                await vm.async_operation_complete(vm.create_snapshot())

        else:
            logger.info(f'Instance {vm.name} already stopped.')
            await vm.async_operation_complete(vm.create_snapshot())
Example #5
0
logger.info(f'Watchdog delay is {config.watchdog_delay} seconds')

# Instances generator from config
try:
    TARGETS = [t for t in config.targets_list if t != '']
except Exception as err:
    logger.error(err)

if not TARGETS:
    msg = 'Targets is empty. Please type targets into config file. If you have multiple targets, separate them with a space'
    logger.warning(msg)
    quit()

# Delete non-existent instances
for instance_id in TARGETS:
    if Instance(instance_id).name is None:
        TARGETS.remove(instance_id)


async def watchdog(instance_id):
    while True:
        await asyncio.sleep(int(config.watchdog_delay))
        instance = Instance(instance_id)

        if instance.status in WATCH_STATUS:
            logger.info(
                f'Instance {instance.name} is {instance.status}. Working..')
            await instance.async_operation_complete(instance.start())


def run():
Example #6
0
def instance_status():
    logger.info('Getting instances status')
    for instance in INSTANCES:
        vm = Instance(instance)
        if vm.name is not None:
            logger.info(vm)
Example #7
0
async def instance_run(instance):
    vm = Instance(instance)
    if vm.status not in POSITIVE_STATES:
        await vm.async_operation_complete(vm.start())
Example #8
0
def snapshots_creater():
    logger.info('Preparing instances to create a snapshot')
    for instance in INSTANCES:
        vm = Instance(instance)

        if vm.get_data():
            if vm.status not in NEGATIVE_STATES:
                stop_vm = vm.stop()
                if vm.operation_complete(stop_vm):
                    snap_create = vm.create_snapshot()
                if vm.operation_complete(snap_create):
                    if vm.status not in POSITIVE_STATES:
                        start_vm = vm.start()
                        if vm.operation_complete(start_vm):
                            continue

            else:
                logger.info(f'Instance {vm.name} already stopped.')
                create_snap = vm.create_snapshot()
                if vm.operation_complete(create_snap):
                    continue