Example #1
0
def add_target(options, engines, weight=1, stage='private'):
    """ Add a target.

    :param options: dict, describing target's options.
    :param engine: list, eg. ["openmm_60_opencl", "openmm_50_cuda"]
    :param stage: str, stage of the target, allowed values are 'disabled',
        'private', 'public'
    :param weight: int, the weight of the target relative to your other targets

    """
    body = {}
    body['options'] = options
    body['engines'] = engines
    assert type(engines) == list
    body['stage'] = stage
    body['weight'] = weight
    url = 'https://' + login_cc + '/targets'
    global auth_token
    headers = {'Authorization': auth_token}
    reply = requests.post(url,
                          data=json.dumps(body),
                          verify=is_domain(login_cc),
                          headers=headers)
    if reply.status_code != 200:
        print(reply.status_code, reply.text)
        raise Exception('Cannot add target')
    target_id = reply.json()['target_id']
    target = Target(target_id)
    return target
Example #2
0
    def add_stream(self, files, scv, tags=None):
        """ Add a stream to the target belonging to a particular scv.

        :param files: dict, filenames and binaries matching the core's
            requirements.
        :param scv: str, which particular SCV to add the stream to.
        :param tags: dict, a dictionary of tag files to include, such as pdbs

        """
        assert isinstance(files, dict)
        body = {
            'target_id': self.id,
            'files': files,
        }
        if tags:
            body['tags'] = tags
        if scv:
            global scvs
            global auth_token
            refresh_scvs()
            url = 'https://' + scvs[scv]['host'] + '/streams'
            headers = {'Authorization': auth_token}
            reply = requests.post(url,
                                  headers=headers,
                                  data=json.dumps(body),
                                  verify=is_domain(self.uri))
        else:
            reply = self._post('/streams', json.dumps(body))
        if reply.status_code != 200:
            print(reply.text)
            raise Exception('Bad status code')
        else:
            return Stream(json.loads(reply.text)['stream_id'])
Example #3
0
def list_engines():
    global login_cc
    global auth_token
    url = 'https://' + login_cc + '/engines/keys'
    headers = {'Authorization': auth_token}
    reply = requests.get(url, verify=is_domain(login_cc), headers=headers)
    if reply.status_code != 200:
        raise Exception('Cannot get engines')
Example #4
0
 def _get(self, path, host=None, headers=None, timeout=2):
     if headers is None:
         headers = {}
     headers['Authorization'] = auth_token
     if host is None:
         host = self.uri
     url = 'https://' + host + path
     return requests.get(url,
                         headers=headers,
                         verify=is_domain(self.uri),
                         timeout=timeout)
Example #5
0
 def _put(self, path, body=None, headers=None):
     if headers is None:
         headers = {}
     headers['Authorization'] = auth_token
     url = 'https://' + self.uri + path
     if body is None:
         body = '{}'
     return requests.put(url,
                         headers=headers,
                         data=body,
                         verify=is_domain(self.uri),
                         timeout=2)
Example #6
0
def login(token, cc='cc.proteneer.com'):
    """ Login to a particular command center using your token. """
    url = 'https://' + cc + '/users/verify'
    headers = {'Authorization': token}
    reply = requests.get(url, verify=is_domain(cc), headers=headers)
    if reply.status_code != 200:
        print(reply.content)
    global auth_token
    auth_token = token
    global login_cc
    login_cc = cc
    refresh_scvs()
Example #7
0
def list_targets():
    """ Return a list of targets. """
    global login_cc
    global auth_token
    url = 'https://' + login_cc + '/targets'
    headers = {'Authorization': auth_token}
    reply = requests.get(url, verify=is_domain(login_cc), headers=headers)
    if reply.status_code != 200:
        raise Exception('Cannot list targets')
    target_ids = reply.json()['targets']
    targets = []
    for target_id in target_ids:
        targets.append(Target(target_id))
    return targets
Example #8
0
def refresh_scvs():
    """ Update and return the status of the SCVs. This method is rate limited
        to once every 2 seconds. """
    global scvs
    global last_scvs_refresh
    global login_cc
    if time.time() - last_scvs_refresh > 1:
        url = 'https://' + login_cc + '/scvs/status'
        reply = requests.get(url, verify=is_domain(login_cc))

        print('REFRESH SCVS called:', reply, reply.status_code, reply.content)

        if reply.status_code == 200:
            content = reply.json()
            for scv_name, scv_prop in content.items():
                # sets host and status fields
                scvs[scv_name] = scv_prop
            last_scvs_refresh = time.time()