def get_host_params(uuid): host_params = mongo.db.hosts.find_one({'_id': uuid}) if host_params is None: host_params = mongo.db.hosts.find_one({'_id': 'register'}) if host_params is None: host_params = {} host_params.pop("_id", None) host_params[UUID] = uuid current_params, _groups = get_group_params(host_params.get('groups')) current_params.update(host_params) current_params["groups"] = _groups for i in range(10): new_params = {} for k, v in current_params.iteritems(): k = render_string(k, **current_params) v = render_string(v, **current_params) new_params[k] = v if new_params == current_params: break current_params = new_params logging.debug(current_params) return current_params
def test_get_group_params(self): expected_params = { u'kernel': u'{{image_base_url}}/linux', u'image_base_url': u'{{base_url}}/images', u'mirror_path': u'/ubuntu', u'mirror_scheme': u'http', u'base_url': u'http://127.0.0.1', u'module': u'{{image_base_url}}/initrd.gz', u'module1': u'{{image_base_url}}/initrd1.gz', u'kernel_opts': u'quiet', u'ipxe_script': u'ubuntu.temp', u'groups': [u'default'], u'mirror_host': u'jp.archive.ubuntu.com' } expected_groups = [u'ubuntu', u'default'] with self.app.test_request_context('/'): _params, _groups = groups.get_group_params(self.group_id) self.assertEqual(_params, expected_params) self.assertEqual(_groups, expected_groups)
def _get(name): if request.args.get('params') == 'all': params, _groups = get_group_params(name) return jsonify(params) return jsonify(get_group(name))