def list_tags(): if request.method == "POST": tag_name = request.form["tag-name"] tag = Tag.find(tag_name) if not tag: tag = Tag(tag_name) tag.save() tags = Tag.find_all() return render_template('tags.html', tags=tags)
def test_ansible_inventory_default_tags(self): fireflash = Item('fireflash') mole = Item('mole') fab1 = Item('fab1') linux = Tag('linux') ansible = Tag('ansible-managed') windows = Tag('windows') multiple = Tag('multiple') fireflash.add_to(linux) mole.add_to(ansible) fab1.add_to(windows) fireflash.add_to(multiple) fab1.add_to(multiple) linux.save() ansible.save() windows.save() multiple.save() with app.test_client() as c: rv = self.get_json(c, '/api/ansible_inventory/') data = json.loads(rv.data) assert rv.status_code == 200 print data assert data == { 'linux': {'hosts': ['fireflash']}, 'ansible-managed': {'hosts': ['mole']}, 'windows': {'hosts': []}, 'multiple': {'hosts': ['fireflash']}, '_meta': {'hostvars': {'fireflash': {}, 'mole': {}}} }
def test_ansible_inventory(self): fireflash = Item('fireflash') linux = Tag('linux') linux.set_variable('test', 'one') fireflash.add_to(linux) linux.save() with app.test_client() as c: rv = self.get_json(c, '/api/ansible_inventory/') data = json.loads(rv.data) assert rv.status_code == 200 print data assert data == { 'linux': {'hosts': ['fireflash']}, '_meta': {'hostvars': {'fireflash': {'test': 'one'}}} }
def test_api_set_tag_variable(self): fireflash = Item('fireflash') laptop = Tag('laptop') laptop.set_variable('test', 'one') fireflash.add_to(laptop) laptop.save() with app.test_client() as c: rv = self.get_json(c, '/api/tag/laptop/') data = json.loads(rv.data) data['vars']['test']= 'two' rv = self.put_json(c, '/api/tag/laptop/', data) print rv assert rv.status_code == 200 fireflash = Item.find('fireflash') laptop = Tag.find('laptop') assert laptop.variables['test'] == 'two' assert fireflash.get_all_variables()['test'] == 'two'
def list_tags(): if request.method == 'POST': if not request.json: abort(415) data = request.json if not 'name' in data: abort(400) if Tag.find(data['name']): abort(409) tag = Tag(data['name']) try: tag.update_from(data) except MelangeException: abort(400) tag.save() response = make_response('', 201) response.headers['Content-Location'] = url_for('melange_api.show_tag',name=tag.name) return response tags = [ {'name':tag.name, 'href':url_for('melange_api.show_tag', name=tag.name)} for tag in Tag.find_all() ] response = make_response( json.dumps(tags), 200 ) response.headers['Content-Type'] = 'application/json' return response