Ejemplo n.º 1
0
    def send_job(self, job_message):
        """Submits a job.

        :Args:
            - job_message (dict): A job specification formatted as a
              dictionary.

        :Returns:
            - A :class:`.Response` object containing a dictionary of the newly
              submitted job's ID and URL if successful. Otherwise the
              Response will contain the :exc:`.RestCallException`.

        :Raises:
            - :class:`.RestCallException` if new job dictionary is
              malformed / missing necessary keys.
        """
        self._log.debug("send_job, job_message={0}".format(job_message))
        url = self.url("jobs")

        try:
            post_resp = rest_client.post(self._auth, url, self.headers, message=job_message)

        except RestCallException as exp:
            return Response(False, exp)

        else:
            if utils.valid_keys(post_resp, ["jobId", "link"]):
                return Response(True, post_resp)

            return Response(False, RestCallException(KeyError, "incorrectly formatted job response", post_resp))
Ejemplo n.º 2
0
    def add_pool(self, target_size=0, max_tasks=1, communication=False, certs=[]):
        """
        Add a new pool.

        :Kwargs:
            - target_size (int): The target size of the pool. The default is 0.
            - max_tasks (int): Max tasks that can run on a single TVM.
              The default is 1.
            - communication (bool): Indicates whether tasks running on TVMs
              in the pool need to ba able to communicate directly with each
              other. The default is ``False``.
            - certs (list): A list of certificates that need to be installed
              on the TVMs of the pool. The maximum number of certs that can
              be installed on a pool is 10.

        :Returns:
            - A :class:`.Response` object a dict with the new pool id and
              a link to the newly created pool.
              ``{'id': '', 'link': ''}``
            - If the call failed or if the response is incomplete/malformed
              a :class:`.Response` object with a :class:`.RestCallException`.
        """
        self._log.debug("add_pool")
        url = self.url("pools")

        if len(certs) > 10:
            certs = certs[0:10]

        try:
            message = {
                "targetDedicated": str(int(target_size)),
                "maxTasksPerTVM": str(int(max_tasks)),
                "communication": bool(communication),
                "certificateReferences": list(certs),
            }

        except ValueError as exp:
            return Response(False, RestCallException(ValueError, str(exp), exp))

        try:
            resp = rest_client.post(self._auth, url, self.headers, message)

        except RestCallException as exp:
            return Response(False, exp)

        if utils.valid_keys(resp, ["poolId", "link"]):
            return Response(True, resp)

        return Response(False, RestCallException(KeyError, "incorrectly formatted pool response", resp))
Ejemplo n.º 3
0
    def get_job(self, job_id=None, url=None):
        """
        Gets information about a job.
        Job info can be retrieved by supplying **either** the job's ID
        **or** a URL to the job. If both are supplied, URL is used.

        :Kwargs:
            - job_id (str): ID of the job on which info is requested.
            - url (str): A complete URL to the job info.

        :Returns:
            - A :class:`.Response` object containing the job details as a
              dictionary, if successful. Otherwise the Response will
              contain the :exc:`.RestCallException`.

        :Raises:
            - :class:`.RestCallException` if neither job ID or URL are
              supplied.
            - :class:`.RestCallException` if job details dictionary is
              malformed / missing necessary keys
        """
        self._log.debug("get_job, job_id={0}, url={1}".format(job_id, url))
        if not url and job_id:
            url = self.url("jobs/{jobid}").format(jobid=job_id)

        elif not url and not job_id:
            return Response(False, RestCallException(AttributeError, "Either job_id or url must be set", None))

        try:
            get_resp = rest_client.get(self._auth, url, self.headers)

        except RestCallException as exp:
            return Response(False, exp)

        else:
            if utils.valid_keys(get_resp, ["id", "name", "type"]):
                return Response(True, get_resp)
            return Response(False, RestCallException(KeyError, "incorrectly formatted job response", get_resp))