Exemplo n.º 1
0
def update(context, id, job_id, etag, name, type, url, data):
    put_data = utils.sanitize_kwargs(name=name, type=type, url=url, data=data)
    uri = "%s/jobs/%s/%s/%s" % (context.dci_cs_api, job_id, RESOURCE, id)
    return context.session.put(uri,
                               timeout=base.HTTP_TIMEOUT,
                               json=put_data,
                               headers={"If-match": etag})
Exemplo n.º 2
0
def schedule(context, topic_id, components=None):
    uri = "%s/%s/schedule" % (context.dci_cs_api, RESOURCE)
    data = {"topic_id": topic_id, "components_ids": components}
    data = utils.sanitize_kwargs(**data)
    r = context.session.post(uri, json=data)
    if r.status_code == 201:
        context.last_job_id = r.json()["job"]["id"]
    return r
Exemplo n.º 3
0
def update(context, resource, **kwargs):
    """Update a specific resource"""
    etag = kwargs.pop('etag')
    id = kwargs.pop('id')
    data = utils.sanitize_kwargs(**kwargs)
    uri = '%s/%s/%s' % (context.dci_cs_api, resource, id)
    r = context.session.put(uri, headers={'If-match': etag}, json=data)
    return r
Exemplo n.º 4
0
def update(context, resource, **kwargs):
    """Update a specific resource"""
    etag = kwargs.pop("etag")
    id = kwargs.pop("id")
    data = utils.sanitize_kwargs(**kwargs)
    uri = "%s/%s/%s" % (context.dci_cs_api, resource, id)
    r = context.session.put(
        uri, timeout=HTTP_TIMEOUT, headers={"If-match": etag}, json=data
    )
    return r
Exemplo n.º 5
0
def list(context, resource, **kwargs):
    """List all resources"""
    data = utils.sanitize_kwargs(**kwargs)
    id = data.pop('id', None)
    subresource = data.pop('subresource', None)

    if subresource:
        uri = '%s/%s/%s/%s' % (context.dci_cs_api, resource, id, subresource)
    else:
        uri = '%s/%s' % (context.dci_cs_api, resource)

    return context.session.get(uri, params=data)
Exemplo n.º 6
0
def list(context, resource, **kwargs):
    """List all resources"""
    data = utils.sanitize_kwargs(**kwargs)
    id = data.pop("id", None)
    subresource = data.pop("subresource", None)

    if subresource:
        uri = "%s/%s/%s/%s" % (context.dci_cs_api, resource, id, subresource)
    else:
        uri = "%s/%s" % (context.dci_cs_api, resource)

    return context.session.get(uri, timeout=HTTP_TIMEOUT, params=data)
Exemplo n.º 7
0
def create(
    context,
    name,
    content=None,
    file_path=None,
    mime="text/plain",
    jobstate_id=None,
    md5=None,
    job_id=None,
    test_id=None,
):
    """Method to create a file on the Control-Server

    This method allows one to upload a file to the Control-Server. The file
    to be uploaded can be specified in two different ways either by specifying
    its content directly or or by specifying the file_path where the file is
    located.

    content can be in the form of: string, bytes or a file-descriptor.

    """

    if content and file_path:
        raise Exception("content and file_path are mutually exclusive")
    elif not content and not file_path:
        raise Exception(
            "At least one of content or file_path must be specified")

    headers = {
        "DCI-NAME": name,
        "DCI-MIME": mime,
        "DCI-JOBSTATE-ID": jobstate_id,
        "DCI-MD5": md5,
        "DCI-JOB-ID": job_id,
        "DCI-TEST-ID": test_id,
    }
    headers = utils.sanitize_kwargs(**headers)
    uri = "%s/%s" % (context.dci_cs_api, RESOURCE)

    if content:
        if not hasattr(content, "read"):
            if not isinstance(content, bytes):
                content = content.encode("utf-8")
            content = io.BytesIO(content)
        return context.session.post(uri, headers=headers, data=content)
    else:
        if not os.path.exists(file_path):
            raise FileErrorException()
        with open(file_path, "rb") as f:
            return context.session.post(uri, headers=headers, data=f)
Exemplo n.º 8
0
def iter(context, resource, **kwargs):
    """List all resources"""
    data = utils.sanitize_kwargs(**kwargs)
    id = data.pop("id", None)
    subresource = data.pop("subresource", None)
    data["limit"] = data.get("limit", 20)

    if subresource:
        uri = "%s/%s/%s/%s" % (context.dci_cs_api, resource, id, subresource)
        resource = subresource
    else:
        uri = "%s/%s" % (context.dci_cs_api, resource)

    data["offset"] = 0
    while True:
        j = context.session.get(uri, timeout=HTTP_TIMEOUT, params=data).json()
        if len(j[resource]):
            for i in j[resource]:
                yield i
        else:
            break
        data["offset"] += data["limit"]
Exemplo n.º 9
0
def create(context, job_id, name, type, url, data):
    data = utils.sanitize_kwargs(name=name, type=type, url=url, data=data)
    uri = "%s/jobs/%s/%s" % (context.dci_cs_api, job_id, RESOURCE)
    return context.session.post(uri, timeout=base.HTTP_TIMEOUT, json=data)
Exemplo n.º 10
0
def create(context, resource, **kwargs):
    """Create a resource"""
    data = utils.sanitize_kwargs(**kwargs)
    uri = '%s/%s' % (context.dci_cs_api, resource)
    r = context.session.post(uri, data=json.dumps(data))
    return r
Exemplo n.º 11
0
def create(context, resource, **kwargs):
    """Create a resource"""
    data = utils.sanitize_kwargs(**kwargs)
    uri = "%s/%s" % (context.dci_cs_api, resource)
    r = context.session.post(uri, timeout=HTTP_TIMEOUT, json=data)
    return r