Пример #1
0
 def _cast_with_consumer(self, method_name, **kwargs):
     try:
         rpc.cast_with_consumer(self.context, self._get_routing_key(), {
             'method': method_name,
             'args': kwargs
         })
     except Exception as e:
         LOG.error(e)
         raise exception.GuestError(original_message=str(e))
Пример #2
0
 def _cast(self, method_name, **kwargs):
     LOG.debug("Casting %s" % method_name)
     try:
         self.cast(self.context, self.make_msg(method_name, **kwargs),
                   topic=kwargs.get('topic'),
                   version=kwargs.get('version'))
     except Exception as e:
         LOG.error(e)
         raise exception.GuestError(original_message=str(e))
Пример #3
0
    def _cast_with_consumer(self, method_name, **kwargs):
        try:
            conn = rpc.create_connection(new=True)
            conn.create_consumer(self._get_routing_key(), None, fanout=False)
        except Exception as e:
            LOG.error(e)
            raise exception.GuestError(original_message=str(e))
        finally:
            if conn:
                conn.close()

        # leave the cast call out of the hackity consumer create
        self._cast(method_name, **kwargs)
Пример #4
0
def pkg_version(package_name):
    cmd_list = ["dpkg", "-l", package_name]
    p = commands.getstatusoutput(' '.join(cmd_list))
    # check the command status code
    if not p[0] == 0:
        return None
    # Need to capture the version string
    # check the command output
    std_out = p[1]
    patterns = [
        '.*No packages found matching.*', "\w\w\s+(\S+)\s+(\S+)\s+(.*)$"
    ]
    for line in std_out.split("\n"):
        for p in patterns:
            regex = re.compile(p)
            matches = regex.match(line)
            if matches:
                line = matches.group()
                parts = line.split()
                if not parts:
                    msg = _("returned nothing")
                    LOG.error(msg)
                    raise exception.GuestError(msg)
                if len(parts) <= 2:
                    msg = _("Unexpected output.")
                    LOG.error(msg)
                    raise exception.GuestError(msg)
                if parts[1] != package_name:
                    msg = _("Unexpected output:[1] = %s" % str(parts[1]))
                    LOG.error(msg)
                    raise exception.GuestError(msg)
                if parts[0] == 'un' or parts[2] == '<none>':
                    return None
                return parts[2]
    msg = _("version() saw unexpected output from dpkg!")
    LOG.error(msg)
    raise exception.GuestError(msg)
Пример #5
0
    def _call(self, method_name, timeout_sec, **kwargs):
        LOG.debug("Calling %s with timeout %s" % (method_name, timeout_sec))
        try:
            result = self.call(self.context,
                               self.make_msg(method_name, **kwargs),
                               timeout=timeout_sec)

            LOG.debug("Result is %s" % result)
            return result
        except Exception as e:
            LOG.error(e)
            raise exception.GuestError(original_message=str(e))
        except Timeout as t:
            if t is not timeout:
                raise
            else:
                raise exception.GuestTimeout()
Пример #6
0
    def _call(self, method_name, timeout_sec, **kwargs):
        LOG.debug("Calling %s" % method_name)

        timeout = Timeout(timeout_sec)
        try:
            result = rpc.call(self.context, self._get_routing_key(), {
                'method': method_name,
                'args': kwargs
            })
            LOG.debug("Result is %s" % result)
            return result
        except Exception as e:
            LOG.error(e)
            raise exception.GuestError(original_message=str(e))
        except Timeout as t:
            if t is not timeout:
                raise
            else:
                raise exception.GuestTimeout()
        finally:
            timeout.cancel()