Esempio n. 1
0
    def migrate(self, storage_pool, live_migrate=False, **kwargs):
        if self.dry_run:
            logging.info(
                f"Would {'live ' if live_migrate else ''}migrate volume '{self['name']}' to '{storage_pool['name']}'"
            )
            return True

        migrate_result = self._ops.cs.migrateVolume(
            volumeid=self['id'],
            storageid=storage_pool['id'],
            livemigrate=live_migrate)

        if not self._ops.wait_for_volume_migration_job(
                volume_id=self['id'], job_id=migrate_result['jobid'], **
                kwargs):
            logging.error(f"Migration job '{migrate_result['jobid']}' failed")
            return False

        logging.debug(f"Migration job '{migrate_result['jobid']}' completed")
        self.refresh()

        logging.info(
            f"Successfully migrated volume '{self['name']}' to '{storage_pool['name']}'"
        )
        return True
Esempio n. 2
0
    def destroy(self):
        if self.dry_run:
            logging.info(f"Would destroy system VM '{self['name']}'")
            return True

        logging.info(f"Destroying system VM '{self['name']}'")
        response = self._ops.cs.destroySystemVm(id=self['id'])
        if not self._ops.wait_for_job(response['jobid']):
            logging.error(f"Failed to destroy system VM '{self['name']}'")
            return False

        return True
Esempio n. 3
0
    def start(self, host=None):
        if self.dry_run:
            logging.info(f"Would start system VM '{self['name']}")
            return True

        logging.info(f"Starting system VM '{self['name']}'")
        response = self._ops.cs.startSystemVm(id=self['id'])
        if not self._ops.wait_for_job(response['jobid']):
            logging.error(f"Failed to start system VM '{self['name']}'")
            return False

        return True
Esempio n. 4
0
    def reboot(self):
        if self.dry_run:
            logging.info(f"Would reboot router '{self['name']}")
            return True

        logging.info(f"Rebooting router '{self['name']}'", self.log_to_slack)

        response = self._ops.cs.rebootRouter(id=self['id'])
        if not self._ops.wait_for_job(response['jobid']):
            logging.error(f"Failed to reboot router '{self['name']}'")
            return False

        return True
Esempio n. 5
0
    def restart(self):
        if self.dry_run:
            logging.info(f"Would restart VPC '{self['name']} with clean up")
            return True

        logging.info(f"Restarting VPC '{self['name']}' with clean up'",
                     self.log_to_slack)

        response = self._ops.cs.restartVPC(id=self['id'])
        if not self._ops.wait_for_job(response['jobid']):
            logging.error(
                f"Failed to restart VPC '{self['name']}' with cleanup'")
            return False

        return True
Esempio n. 6
0
    def stop(self):
        if self.dry_run:
            logging.info(
                f"Would shut down system VM '{self['name']}' on host '{self['hostname']}'"
            )
            return True

        logging.info(f"Stopping system VM '{self['name']}'")
        response = self._ops.cs.stopSystemVm(id=self['id'])
        if not self._ops.wait_for_job(response['jobid']):
            logging.error(
                f"Failed to shutdown system VM '{self['name']}' on host '{self['hostname']}'"
            )
            return False

        return True
Esempio n. 7
0
    def get_snapshots(self):
        volume_snapshots = []
        try:
            if 'projectid' in self:
                volume_snapshots = self._ops.cs.listSnapshots(
                    fetch_list=True,
                    volumeid=self['id'],
                    listall='true',
                    projectid=-1)
            else:
                volume_snapshots = self._ops.cs.listSnapshots(
                    fetch_list=True, volumeid=self['id'], listall='true')

        except CloudStackException as e:
            logging.error(f'Exception {str(e)}')

        return volume_snapshots