Exemple #1
0
def list_locks(keyed_by_name=False, **kwargs):
    uri = os.path.join(config.lock_server, 'nodes', '')
    for key, value in kwargs.items():
        if kwargs[key] is False:
            kwargs[key] = '0'
        if kwargs[key] is True:
            kwargs[key] = '1'
    if kwargs:
        if 'machine_type' in kwargs:
            kwargs['machine_type'] = kwargs['machine_type'].replace(',', '|')
        uri += '?' + urlencode(kwargs)
    with safe_while(sleep=1, increment=0.5, action='list_locks') as proceed:
        while proceed():
            try:
                response = requests.get(uri)
                if response.ok:
                    break
            except requests.ConnectionError:
                log.exception("Could not contact lock server: %s, retrying...",
                              config.lock_server)
    if response.ok:
        if not keyed_by_name:
            return response.json()
        else:
            return {node['name']: node for node in response.json()}
    return dict()
Exemple #2
0
def list_locks(keyed_by_name=False, **kwargs):
    uri = os.path.join(config.lock_server, 'nodes', '')
    for key, value in kwargs.items():
        if kwargs[key] is False:
            kwargs[key] = '0'
        if kwargs[key] is True:
            kwargs[key] = '1'
    if kwargs:
        if 'machine_type' in kwargs:
            kwargs['machine_type'] = kwargs['machine_type'].replace(',','|')
        uri += '?' + urlencode(kwargs)
    try:
        response = requests.get(uri)
    except requests.ConnectionError:
        success = False
        log.exception("Could not contact lock server: %s", config.lock_server)
    else:
        success = response.ok
    if success:
        if not keyed_by_name:
            return response.json()
        else:
            return {node['name']: node
                    for node in response.json()}
    return dict()
Exemple #3
0
 def build_graph_url(self):
     config = dict(
         hosts=','.join(self.hosts),
         time_from=self._format_time(self.time_from),
     )
     if self.time_until:
         config['time_to'] = self._format_time(self.time_until)
     args = urlencode(config)
     template = "{base_url}?{args}"
     return template.format(base_url=self.base_url, args=args)
Exemple #4
0
 def _update_dns(self):
     query = urlencode(dict(
         name=self.name,
         ip=self.ips[0],
     ))
     nsupdate_url = "%s?%s" % (
         config.nsupdate_url,
         query,
     )
     resp = requests.get(nsupdate_url)
     resp.raise_for_status()
Exemple #5
0
 def get_graph_url(self, metric):
     config = dict(self.graph_defaults)
     config.update({
         'from': self.time_from,
         'until': self.time_until,
         # urlencode with doseq=True encodes each item as a separate
         # 'target=' arg
         'target': self.get_target_globs(metric),
     })
     args = urlencode(config, doseq=True)
     template = "{base_url}?{args}"
     return template.format(base_url=self.base_url, args=args)
Exemple #6
0
 def _search_uri(self):
     flavor = self.flavor
     req_obj = OrderedDict()
     req_obj['status'] = 'ready'
     req_obj['project'] = self.project
     req_obj['flavor'] = flavor
     arch = "noarch" if self.force_noarch else self.arch
     req_obj['distros'] = '%s/%s' % (self.distro, arch)
     ref_name, ref_val = list(self._choose_reference().items())[0]
     if ref_name == 'tag':
         req_obj['sha1'] = self._sha1 = self._tag_to_sha1()
     elif ref_name == 'sha1':
         req_obj['sha1'] = ref_val
     else:
         req_obj['ref'] = ref_val
     req_str = urlencode(req_obj)
     uri = urljoin(
         self.query_url,
         'search',
     ) + '?%s' % req_str
     return uri