Exemplo n.º 1
0
class ProgressDaemon(object):
    def __init__(self):
        self.conn = Connection(settings.PROGRESSD_HOST,
                               port=settings.PROGRESSD_PORT)

    def _request(self, method, url, **kwargs):
        try:
            return self.conn.json_request(method, url, **kwargs)
        except ConnectionError:
            raise RvbdException(
                "Error connecting to appfwk service 'progressd': "
                "try restarting the service (sudo service progressd restart) "
                "or contact your administrator for assistance."
            )

    def get(self, id_, attr=None):
        r = self._request('GET', '/jobs/items/%d/' % id_)
        if attr:
            return r[attr]
        return r

    def post(self, **kwargs):
        return self._request('POST', '/jobs/', body=kwargs)

    def put(self, id_, **kwargs):
        self._request('PUT', '/jobs/items/%d/' % id_, body=kwargs)

    def delete(self, id_):
        self._request('DELETE', '/jobs/items/%d/' % id_)

    def reset(self):
        self._request('POST', '/jobs/reset/')
Exemplo n.º 2
0
class ProgressDaemon(object):
    def __init__(self):
        self.conn = Connection(settings.PROGRESSD_HOST,
                               port=settings.PROGRESSD_PORT)

    def _request(self, method, url, **kwargs):
        try:
            return self.conn.json_request(method, url, **kwargs)
        except ConnectionError:
            raise RvbdException(
                "Error connecting to appfwk service 'progressd': "
                "try restarting the service (sudo service progressd restart) "
                "or contact your administrator for assistance.")

    def get(self, id_, attr=None):
        r = self._request('GET', '/jobs/items/%d/' % id_)
        if attr:
            return r[attr]
        return r

    def post(self, **kwargs):
        return self._request('POST', '/jobs/', body=kwargs)

    def put(self, id_, **kwargs):
        self._request('PUT', '/jobs/items/%d/' % id_, body=kwargs)

    def delete(self, id_):
        self._request('DELETE', '/jobs/items/%d/' % id_)

    def reset(self):
        self._request('POST', '/jobs/reset/')
Exemplo n.º 3
0
class ProgressDaemon(object):
    def __init__(self):
        self.conn = Connection(settings.PROGRESSD_HOST,
                               port=settings.PROGRESSD_PORT)

    def _request(self, method, url, **kwargs):
        try:
            return self.conn.json_request(method, url, **kwargs)
        except ConnectionError:
            # In case progressd is restarting due to daily logrotate
            # resending the request after 10 seconds
            logger.warning("Waiting %s seconds before reconnecting progressd"
                           % settings.PROGRESSD_CONN_TIMEOUT)
            time.sleep(settings.PROGRESSD_CONN_TIMEOUT)
            try:
                return self.conn.json_request(method, url, **kwargs)
            except ConnectionError:
                raise RvbdException(
                    "Error connecting to appfwk service 'progressd': "
                    "try restarting the service "
                    "(sudo service progressd restart) "
                    "or contact your administrator for assistance."
                )

    def get(self, id_, attr=None):
        r = self._request('GET', '/jobs/items/%d/' % id_)
        if attr:
            return r[attr]
        return r

    def post(self, **kwargs):
        return self._request('POST', '/jobs/', body=kwargs)

    def put(self, id_, **kwargs):
        self._request('PUT', '/jobs/items/%d/' % id_, body=kwargs)

    def delete(self, id_):
        self._request('DELETE', '/jobs/items/%d/' % id_)

    def reset(self):
        self._request('POST', '/jobs/reset/')
Exemplo n.º 4
0
class ProgressDaemon(object):
    def __init__(self):
        self.conn = Connection(settings.PROGRESSD_HOST,
                               port=settings.PROGRESSD_PORT)

    def _request(self, method, url, **kwargs):
        try:
            return self.conn.json_request(method, url, **kwargs)
        except ConnectionError:
            # In case progressd is restarting due to daily logrotate
            # resending the request after 10 seconds
            logger.warning("Waiting %s seconds before reconnecting progressd" %
                           settings.PROGRESSD_CONN_TIMEOUT)
            time.sleep(settings.PROGRESSD_CONN_TIMEOUT)
            try:
                return self.conn.json_request(method, url, **kwargs)
            except ConnectionError:
                raise RvbdException(
                    "Error connecting to appfwk service 'progressd': "
                    "try restarting the service "
                    "(sudo service progressd restart) "
                    "or contact your administrator for assistance.")

    def get(self, id_, attr=None):
        r = self._request('GET', '/jobs/items/%d/' % id_)
        if attr:
            return r[attr]
        return r

    def post(self, **kwargs):
        return self._request('POST', '/jobs/', body=kwargs)

    def put(self, id_, **kwargs):
        self._request('PUT', '/jobs/items/%d/' % id_, body=kwargs)

    def delete(self, id_):
        self._request('DELETE', '/jobs/items/%d/' % id_)

    def reset(self):
        self._request('POST', '/jobs/reset/')
Exemplo n.º 5
0
    def get_job_function(self, kwargs):
        # allow for alternate methods to call table commands in future
        # possibly direct API calls, or REST calls against running server

        if self.options.rest_server:
            if 'table-name' in kwargs:
                # find id of table-name
                name = kwargs['table-name']
                baseurl = '/data/tables/'
                verify = not self.options.insecure

                conn = Connection(self.options.rest_server,
                                  auth=get_auth(self.options.authfile),
                                  verify=verify)

                tableurl = None
                url = baseurl
                logger.debug('Getting available tables from server ...')
                while tableurl is None:
                    r = conn.json_request('GET', url)
                    results = r['results']
                    urls = [t['url'] for t in results if t['name'] == name]
                    if len(urls) > 1:
                        msg = ('ERROR: Multiple tables found for name %s: %s' %
                               (name, urls))
                        logger.debug(msg)
                        raise ValueError(msg)
                    elif len(urls) == 1:
                        # parse out just the path component of the url
                        logger.debug('Found table url: %s' % urls)
                        fullurl = urljoin(urls[0], 'jobs/')
                        tableurl = urlsplit(fullurl).path
                    else:
                        url = r['next']
                        if url is None:
                            msg = ('ERROR: No table found for "%s"' % name)
                            logger.debug(msg)
                            raise ValueError(msg)

                job_params = {
                    'func': run_table_via_rest,
                    'args': [self.options.rest_server, tableurl,
                             self.options.authfile, verify]
                }
            elif 'report-slug' in kwargs:
                # find id of report
                slug = kwargs['report-slug']
                namespace = kwargs['report-namespace']
                baseurl = urljoin(self.options.rest_server, '/report/')
                verify = not self.options.insecure

                conn = Connection(self.options.rest_server,
                                  auth=get_auth(self.options.authfile),
                                  verify=verify)
                title = None

                logger.debug('Getting available reports from server ...')
                r = conn.json_request('GET', baseurl)
                for report in r:
                    if slug in report.values():
                        title = report['title']
                        break

                if title is None:
                    msg = ('No report found for slug %s namespace %s'
                           % (slug, namespace))
                    logger.error(msg)
                    raise ValueError(msg)

                job_params = {
                    'func': run_report_via_rest,
                    'args': [self.options.rest_server, slug,
                             namespace, title, self.options.authfile, verify]
                }
            else:
                raise ValueError('Invalid config, no "table-name" or '
                                 '"report-slug"/"report-namespace" specified')
        else:
            job_params = {'func': run_table,
                          'args': ['table']}
        logger.debug('Calculated job params: %s' % job_params)
        return job_params
Exemplo n.º 6
0
    def get_job_function(self, kwargs):
        # allow for alternate methods to call table commands in future
        # possibly direct API calls, or REST calls against running server

        if self.options.rest_server:
            if 'table-name' in kwargs:
                # find id of table-name
                name = kwargs['table-name']
                baseurl = '/data/tables/'
                verify = not self.options.insecure

                conn = Connection(self.options.rest_server,
                                  auth=get_auth(self.options.authfile),
                                  verify=verify)

                tableurl = None
                url = baseurl
                logger.debug('Getting available tables from server ...')
                while tableurl is None:
                    r = conn.json_request('GET', url)
                    results = r['results']
                    urls = [t['url'] for t in results if t['name'] == name]
                    if len(urls) > 1:
                        msg = ('ERROR: Multiple tables found for name %s: %s' %
                               (name, urls))
                        logger.debug(msg)
                        raise ValueError(msg)
                    elif len(urls) == 1:
                        # parse out just the path component of the url
                        logger.debug('Found table url: %s' % urls)
                        fullurl = urljoin(urls[0], 'jobs/')
                        tableurl = urlsplit(fullurl).path
                    else:
                        url = r['next']
                        if url is None:
                            msg = ('ERROR: No table found for "%s"' % name)
                            logger.debug(msg)
                            raise ValueError(msg)

                job_params = {
                    'func': run_table_via_rest,
                    'args': [self.options.rest_server, tableurl,
                             self.options.authfile, verify]
                }
            elif 'report-slug' in kwargs:
                # find id of report
                slug = kwargs['report-slug']
                namespace = kwargs['report-namespace']
                baseurl = urljoin(self.options.rest_server, '/report/')
                verify = not self.options.insecure

                conn = Connection(self.options.rest_server,
                                  auth=get_auth(self.options.authfile),
                                  verify=verify)
                title = None

                logger.debug('Getting available reports from server ...')
                r = conn.json_request('GET', baseurl)
                for report in r:
                    if slug in report.values():
                        title = report['title']
                        break

                if title is None:
                    msg = ('No report found for slug %s namespace %s'
                           % (slug, namespace))
                    logger.error(msg)
                    raise ValueError(msg)

                job_params = {
                    'func': run_report_via_rest,
                    'args': [self.options.rest_server, slug,
                             namespace, title, self.options.authfile, verify]
                }
            else:
                raise ValueError('Invalid config, no "table-name" or '
                                 '"report-slug"/"report-namespace" specified')
        else:
            job_params = {'func': run_table,
                          'args': ['table']}
        logger.debug('Calculated job params: %s' % job_params)
        return job_params