Пример #1
0
 def event_enospc_cb(self, conn, dom, path, dev, action, reason, args):
     if reason == "enospc":
         info = {
             "vm": dom.name(),
             "srcPath": path,
             "devAlias": dev,
         }
         add_notification("KCHEVENT0004W", info, '/plugins/kimchi')
         msg = WokMessage("KCHEVENT0004W", info, '/plugins/kimchi')
         wok_log.warning(msg.get_text())
Пример #2
0
 def reload(self, name):
     add_notification('WOKCONFIG0001I', plugin_name='/')
     # If we proceed with the cherrypy.engine.restart() right after
     # adding the notification, the server will reboot and the
     # opened UIs will most likely not see the notification at all. The
     # notification interval is set in wok.main.js as:
     #
     # wok.NOTIFICATION_INTERVAL = 2000
     #
     # Inserting a time.sleep(2) here will ensure that all opened
     # UI had the chance to see the reload notification.
     wok_log.info('Reloading WoK in two seconds ...')
     time.sleep(2)
     cherrypy.engine.restart()
Пример #3
0
    def _execute_task(self, cb, params):
        cmd = params["command"]
        add_notification("GINFW0007I", plugin_name="/plugins/ginger")
        cb("Firmware update is initializing. " "System will reboot in order to flash the firmware.")

        # update_flash may take some time to restart host. Sleep to make sure
        # user notification will show up
        # FIXME this timer is based on a UI constraint. This is not a good
        # design.
        time.sleep(3)
        output, error, rc = run_command(cmd, out_cb=cb)

        if rc:
            if params["operation"] == "update":
                raise OperationFailed("GINFW0004E", {"error": error})
            else:
                raise OperationFailed("GINFW0008E", {"error": error})

        cb("OK", True)
Пример #4
0
    def _execute_task(self, cb, params):
        cmd = params['command']
        add_notification('GINFW0007I', plugin_name='/plugins/ginger')
        cb('Firmware update is initializing. '
           'System will reboot in order to flash the firmware.')

        # update_flash may take some time to restart host. Sleep to make sure
        # user notification will show up
        # FIXME this timer is based on a UI constraint. This is not a good
        # design.
        time.sleep(3)
        output, error, rc = run_command(cmd, out_cb=cb)

        if rc:
            if params['operation'] == 'update':
                raise OperationFailed('GINFW0004E', {'error': error})
            else:
                raise OperationFailed('GINFW0008E', {'error': error})

        cb('OK', True)
Пример #5
0
    def _execute_task(self, cb, params):
        cmd = params['command']
        add_notification('GINFW0007I', plugin_name='/plugins/ginger')
        cb('Firmware update is initializing. '
           'System will reboot in order to flash the firmware.')

        # update_flash may take some time to restart host. Sleep to make sure
        # user notification will show up
        # FIXME this timer is based on a UI constraint. This is not a good
        # design.
        time.sleep(3)
        output, error, rc = run_command(cmd, out_cb=cb)

        if rc:
            if params['operation'] == 'update':
                raise OperationFailed('GINFW0004E', {'error': error})
            else:
                raise OperationFailed('GINFW0008E', {'error': error})

        cb('OK', True)
Пример #6
0
 def _get_new_connection(self):
     retries = 5
     while True:
         retries = retries - 1
         try:
             return libvirt.open(self.uri)
         except libvirt.libvirtError:
             wok_log.error('Unable to connect to libvirt.')
             if not retries:
                 wok_log.error(
                     'Unable to establish connection '
                     'with libvirt. Please check '
                     'your libvirt URI which is often '
                     'defined in '
                     '/etc/libvirt/libvirt.conf'
                 )
                 add_notification(
                     'KCHCONN0001E', plugin_name='/plugins/kimchi'
                 )
                 return None
         time.sleep(2)
Пример #7
0
    def get(self, conn_id=0):
        """
        Return current connection to libvirt or open a new one.  Wrap all
        callable libvirt methods so we can catch connection errors and handle
        them by restarting the server.
        """
        def wrapMethod(f):
            def wrapper(*args, **kwargs):
                try:
                    ret = f(*args, **kwargs)
                    return ret
                except libvirt.libvirtError as e:
                    edom = e.get_error_domain()
                    ecode = e.get_error_code()
                    EDOMAINS = (libvirt.VIR_FROM_REMOTE,
                                libvirt.VIR_FROM_RPC)
                    ECODES = (libvirt.VIR_ERR_SYSTEM_ERROR,
                              libvirt.VIR_ERR_INTERNAL_ERROR,
                              libvirt.VIR_ERR_NO_CONNECT,
                              libvirt.VIR_ERR_INVALID_CONN)
                    if edom in EDOMAINS and ecode in ECODES:
                        wok_log.error('Connection to libvirt broken. '
                                      'Recycling. ecode: %d edom: %d' %
                                      (ecode, edom))
                        with LibvirtConnection._connectionLock:
                            self._connections[conn_id] = None
                    raise
            wrapper.__name__ = f.__name__
            wrapper.__doc__ = f.__doc__
            return wrapper

        if not is_libvirtd_up():
            wok_log.error('Libvirt service is not active.')
            add_notification('KCHCONN0002E', plugin_name='/plugins/kimchi')
            return None

        with LibvirtConnection._connectionLock:
            conn = self._connections.get(conn_id)
            if not conn:
                retries = 5
                while True:
                    retries = retries - 1
                    try:
                        conn = libvirt.open(self.uri)
                        break
                    except libvirt.libvirtError:
                        wok_log.error('Unable to connect to libvirt.')
                        if not retries:
                            wok_log.error("Unable to establish connection "
                                          "with libvirt. Please check "
                                          "your libvirt URI which is often "
                                          "defined in "
                                          "/etc/libvirt/libvirt.conf")
                            add_notification("KCHCONN0001E",
                                             plugin_name="/plugins/kimchi")
                            return None
                    time.sleep(2)

                for name in dir(libvirt.virConnect):
                    method = getattr(conn, name)
                    if callable(method) and not name.startswith('_'):
                        setattr(conn, name, wrapMethod(method))

                for cls in self.wrappables:
                    for name in dir(cls):
                        method = getattr(cls, name)
                        if callable(method) and not name.startswith('_'):
                            setattr(cls, name, wrapMethod(method))

                self._connections[conn_id] = conn
                # In case we're running into troubles with keeping the
                # connections alive we should place here:
                # conn.setKeepAlive(interval=5, count=3)
                # However the values need to be considered wisely to not affect
                # hosts which are hosting a lot of virtual machines
            return conn
Пример #8
0
 def event_enospc_cb(self, conn, dom, path, dev, action, reason, args):
     if reason == 'enospc':
         info = {'vm': dom.name(), 'srcPath': path, 'devAlias': dev}
         add_notification('KCHEVENT0004W', info, '/plugins/kimchi')
         msg = WokMessage('KCHEVENT0004W', info, '/plugins/kimchi')
         wok_log.warning(msg.get_text())
Пример #9
0
 def event_enospc_cb(self, conn, dom, path, dev, action, reason, args):
     if reason == 'enospc':
         info = {'vm': dom.name(), 'srcPath': path, 'devAlias': dev}
         add_notification('KCHEVENT0004W', info, '/plugins/kimchi')
         msg = WokMessage('KCHEVENT0004W', info, '/plugins/kimchi')
         wok_log.warning(msg.get_text())
Пример #10
0
    def get(self, conn_id=0):
        """
        Return current connection to libvirt or open a new one.  Wrap all
        callable libvirt methods so we can catch connection errors and handle
        them by restarting the server.
        """

        def wrapMethod(f):
            def wrapper(*args, **kwargs):
                try:
                    ret = f(*args, **kwargs)
                    return ret
                except libvirt.libvirtError as e:
                    edom = e.get_error_domain()
                    ecode = e.get_error_code()
                    EDOMAINS = (libvirt.VIR_FROM_REMOTE, libvirt.VIR_FROM_RPC)
                    ECODES = (
                        libvirt.VIR_ERR_SYSTEM_ERROR,
                        libvirt.VIR_ERR_INTERNAL_ERROR,
                        libvirt.VIR_ERR_NO_CONNECT,
                        libvirt.VIR_ERR_INVALID_CONN,
                    )
                    if edom in EDOMAINS and ecode in ECODES:
                        wok_log.error(
                            'Connection to libvirt broken. '
                            'Recycling. ecode: %d edom: %d' % (ecode, edom)
                        )
                        with LibvirtConnection._connectionLock:
                            self._connections[conn_id] = None
                    raise

            wrapper.__name__ = f.__name__
            wrapper.__doc__ = f.__doc__
            return wrapper

        if not is_libvirtd_up():
            wok_log.error('Libvirt service is not active.')
            add_notification('KCHCONN0002E', plugin_name='/plugins/kimchi')
            return None
        elif notificationsStore.get('KCHCONN0002E') is not None:
            try:
                del_notification('KCHCONN0002E')
            except Exception:
                # If notification was not found, just ignore
                pass

        with LibvirtConnection._connectionLock:
            conn = self._connections.get(conn_id)
            if not conn:
                conn = self._get_new_connection()

                for name in dir(libvirt.virConnect):
                    method = getattr(conn, name)
                    if callable(method) and not name.startswith('_'):
                        setattr(conn, name, wrapMethod(method))

                for cls in self.wrappables:
                    for name in dir(cls):
                        method = getattr(cls, name)
                        if callable(method) and not name.startswith('_'):
                            setattr(cls, name, wrapMethod(method))

                self._connections[conn_id] = conn
                # In case we're running into troubles with keeping the
                # connections alive we should place here:
                # conn.setKeepAlive(interval=5, count=3)
                # However the values need to be considered wisely to not affect
                # hosts which are hosting a lot of virtual machines
            return conn
Пример #11
0
    def get(self, conn_id=0):
        """
        Return current connection to libvirt or open a new one.  Wrap all
        callable libvirt methods so we can catch connection errors and handle
        them by restarting the server.
        """
        def wrapMethod(f):
            def wrapper(*args, **kwargs):
                try:
                    ret = f(*args, **kwargs)
                    return ret
                except libvirt.libvirtError as e:
                    edom = e.get_error_domain()
                    ecode = e.get_error_code()
                    EDOMAINS = (libvirt.VIR_FROM_REMOTE, libvirt.VIR_FROM_RPC)
                    ECODES = (libvirt.VIR_ERR_SYSTEM_ERROR,
                              libvirt.VIR_ERR_INTERNAL_ERROR,
                              libvirt.VIR_ERR_NO_CONNECT,
                              libvirt.VIR_ERR_INVALID_CONN)
                    if edom in EDOMAINS and ecode in ECODES:
                        wok_log.error('Connection to libvirt broken. '
                                      'Recycling. ecode: %d edom: %d' %
                                      (ecode, edom))
                        with LibvirtConnection._connectionLock:
                            self._connections[conn_id] = None
                    raise

            wrapper.__name__ = f.__name__
            wrapper.__doc__ = f.__doc__
            return wrapper

        if not is_libvirtd_up():
            wok_log.error('Libvirt service is not active.')
            add_notification('KCHCONN0002E', plugin_name='/plugins/kimchi')
            return None

        with LibvirtConnection._connectionLock:
            conn = self._connections.get(conn_id)
            if not conn:
                retries = 5
                while True:
                    retries = retries - 1
                    try:
                        conn = libvirt.open(self.uri)
                        break
                    except libvirt.libvirtError:
                        wok_log.error('Unable to connect to libvirt.')
                        if not retries:
                            wok_log.error("Unable to establish connection "
                                          "with libvirt. Please check "
                                          "your libvirt URI which is often "
                                          "defined in "
                                          "/etc/libvirt/libvirt.conf")
                            add_notification("KCHCONN0001E",
                                             plugin_name="/plugins/kimchi")
                            return None
                    time.sleep(2)

                for name in dir(libvirt.virConnect):
                    method = getattr(conn, name)
                    if callable(method) and not name.startswith('_'):
                        setattr(conn, name, wrapMethod(method))

                for cls in self.wrappables:
                    for name in dir(cls):
                        method = getattr(cls, name)
                        if callable(method) and not name.startswith('_'):
                            setattr(cls, name, wrapMethod(method))

                self._connections[conn_id] = conn
                # In case we're running into troubles with keeping the
                # connections alive we should place here:
                # conn.setKeepAlive(interval=5, count=3)
                # However the values need to be considered wisely to not affect
                # hosts which are hosting a lot of virtual machines
            return conn