def update(params): """Update a folder Title and attributes can be updated, but there is no checking of the attributes done.""" ident = params['ident'] folder = load_folder(ident, status=404) constructors.require_etag(constructors.etag_of_obj(folder)) post_body = params['body'] title = post_body['title'] replace_attributes = post_body.get('attributes') update_attributes = post_body.get('update_attributes') attributes = folder.attributes().copy() if replace_attributes: attributes = replace_attributes if update_attributes: attributes.update(update_attributes) # FIXME # You can't update the attributes without updating the title, so the title is mandatory. # This shouldn't be the case though. folder.edit(title, attributes) return _serve_folder(folder)
def update_host(params): """Update a host""" host_name = params["host_name"] body = params["body"] new_attributes = body["attributes"] update_attributes = body["update_attributes"] remove_attributes = body["remove_attributes"] check_hostname(host_name, should_exist=True) host: watolib.CREHost = watolib.Host.host(host_name) constructors.require_etag(etag_of_host(host)) if new_attributes: host.edit(new_attributes, None) if update_attributes: host.update_attributes(update_attributes) faulty_attributes = [] for attribute in remove_attributes: if not host.has_explicit_attribute(attribute): faulty_attributes.append(attribute) if remove_attributes: host.clean_attributes( remove_attributes) # silently ignores missing attributes if faulty_attributes: return problem( status=400, title="Some attributes were not removed", detail= f"The following attributes were not removed since they didn't exist: {', '.join(faulty_attributes)}", ) return _serve_host(host, False)
def delete(params): """Delete a contact-group""" name = params['name'] group = _fetch_contact_group(name) constructors.require_etag(constructors.etag_of_dict(group)) watolib.delete_group(name, 'contact') return Response(status=204)
def delete(params): """Delete a host group""" name = params['name'] group = fetch_group(name, "host") constructors.require_etag(constructors.etag_of_dict(group)) watolib.delete_group(name, 'host') return Response(status=204)
def update(params): """Update a folder """ folder = params['folder'] constructors.require_etag(constructors.etag_of_obj(folder)) post_body = params['body'] title = post_body['title'] replace_attributes = post_body.get('attributes') update_attributes = post_body.get('update_attributes') attributes = folder.attributes().copy() if replace_attributes: attributes = replace_attributes if update_attributes: attributes.update(update_attributes) # FIXME # You can't update the attributes without updating the title, so the title is mandatory. # This shouldn't be the case though. folder.edit(title, attributes) return _serve_folder(folder)
def update(params): name = params['name'] group = _fetch_host_group(name) constructors.require_etag(constructors.etag_of_dict(group)) edit_group(name, 'host', params['body']) group = _fetch_host_group(name) return serve_group(group, serialize_group('host_group'))
def delete(params): """Delete a service group""" name = params['name'] group = fetch_group(name, "service") constructors.require_etag(constructors.etag_of_dict(group)) watolib.delete_group(name, group_type='service') return Response(status=204)
def update(params): """Update a folder """ folder = params['folder'] constructors.require_etag(constructors.etag_of_obj(folder)) post_body = params['body'] title = post_body['title'] replace_attributes = post_body['attributes'] update_attributes = post_body['update_attributes'] remove_attributes = post_body['remove_attributes'] attributes = folder.attributes().copy() if replace_attributes: attributes = replace_attributes if update_attributes: attributes.update(update_attributes) for attribute in remove_attributes: folder.remove_attribute(attribute) folder.edit(title, attributes) return _serve_folder(folder)
def delete(params): hostname = params['hostname'] check_hostname(hostname, should_exist=True) host = watolib.Host.host(hostname) constructors.require_etag(constructors.etag_of_obj(host)) host.folder().delete_hosts([host.name()]) return Response(status=204)
def update(params): """Update a host group""" name = params["name"] group = fetch_group(name, "host") constructors.require_etag(constructors.etag_of_dict(group)) edit_group(name, "host", updated_group_details(name, "host", params["body"])) group = fetch_group(name, "host") return serve_group(group, serialize_group("host_group_config"))
def update(params): """Update a contact group""" name = params['name'] group = fetch_group(name, "contact") constructors.require_etag(constructors.etag_of_dict(group)) edit_group(name, 'contact', params['body']) group = fetch_group(name, "contact") return serve_group(group, serialize_group('contact_group_config'))
def update(params): hostname = params['hostname'] body = params['body'] attributes = body['attributes'] host = watolib.Host.host(hostname) # type: watolib.CREHost constructors.require_etag(constructors.etag_of_obj(host)) host.update_attributes(attributes) return _serve_host(host)
def update(params): """Update a service-group""" name = params['name'] group = fetch_group(name, "service") constructors.require_etag(constructors.etag_of_dict(group)) edit_group(name, group_type='service', extra_info=params['body']) group = fetch_group(name, "service") return serve_group(group, serialize_group('service_group_config'))
def update(params): """Update a service-group""" name = params['name'] group = _fetch_service_group(name) constructors.require_etag(constructors.etag_of_dict(group)) edit_group(name, 'service', params['body']) group = _fetch_service_group(name) return serve_group(group, serialize_group('service_group'))
def delete(params): """Delete a host""" host_name = params['host_name'] # Parameters can't be validated through marshmallow yet. check_hostname(host_name, should_exist=True) host = watolib.Host.host(host_name) constructors.require_etag(constructors.etag_of_obj(host)) host.folder().delete_hosts([host.name()]) return Response(status=204)
def update(params): """Update a host group""" name = params['name'] group = fetch_group(name, "host") constructors.require_etag(constructors.etag_of_dict(group)) edit_group(name, 'host', updated_group_details(name, 'host', params['body'])) group = fetch_group(name, "host") return serve_group(group, serialize_group('host_group_config'))
def update_host(params): """Update a host""" hostname = params['hostname'] body = params['body'] attributes = body['attributes'] host: watolib.CREHost = watolib.Host.host(hostname) constructors.require_etag(constructors.etag_of_obj(host)) validate_host_attributes(attributes, new=False) host.update_attributes(attributes) return _serve_host(host)
def update(params): """Update a contact group""" user.need_permission("wato.edit") name = params["name"] group = fetch_group(name, "contact") constructors.require_etag(constructors.etag_of_dict(group)) edit_group(name, "contact", updated_group_details(name, "contact", params["body"])) group = fetch_group(name, "contact") return serve_group(group, serialize_group("contact_group_config"))
def update(params): """Update a folder Title and attributes can be updated, but there is no checking of the attributes done.""" ident = params['ident'] folder = load_folder(ident, status=404) constructors.require_etag(constructors.etag_of_obj(folder)) post_body = params['body'] title = post_body['title'] attributes = folder.attributes() folder.edit(title, attributes) return _serve_folder(folder)
def update_nodes(params): """Update the nodes of a cluster host""" host_name = params['host_name'] body = params['body'] nodes = body['nodes'] host: watolib.CREHost = watolib.Host.host(host_name) constructors.require_etag(constructors.etag_of_obj(host)) host.edit(host.attributes(), nodes) return constructors.serve_json( constructors.object_sub_property( domain_type='host_config', ident=host_name, name='nodes', value=host.cluster_nodes(), ))
def update_nodes(params): """Update the nodes of a cluster host""" host_name = params["host_name"] body = params["body"] nodes = body["nodes"] host: watolib.CREHost = watolib.Host.host(host_name) constructors.require_etag(etag_of_host(host)) host.edit(host.attributes(), nodes) return constructors.serve_json( constructors.object_sub_property( domain_type="host_config", ident=host_name, name="nodes", value=host.cluster_nodes(), ))
def move(params): ident = params['ident'] folder = load_folder(ident, status=404) constructors.require_etag(_get_etag(folder)) dest = params['body']['destination'] if dest == 'root': dest_folder = watolib.Folder.root_folder() else: dest_folder = load_folder(dest, status=400) folder.parent().move_subfolder_to(folder, dest_folder) folder = load_folder(ident, status=500) return _serve_folder(folder)
def update_host(params): """Update a host""" host_name = params['host_name'] body = params['body'] new_attributes = body['attributes'] update_attributes = body['attributes'] check_hostname(host_name, should_exist=True) host: watolib.CREHost = watolib.Host.host(host_name) constructors.require_etag(constructors.etag_of_obj(host)) if new_attributes: host.edit(new_attributes, None) if update_attributes: host.update_attributes(update_attributes) return _serve_host(host)
def move(params): """Move a folder""" folder: watolib.CREFolder = params["folder"] folder_id = folder.id() constructors.require_etag(etag_of_folder(folder)) dest_folder: watolib.CREFolder = params["body"]["destination"] try: folder.parent().move_subfolder_to(folder, dest_folder) except MKUserError as exc: raise ProblemException( title="Problem moving folder.", detail=exc.message, status=400, ) folder = fields.FolderField.load_folder(folder_id) return _serve_folder(folder)
def update(params): """Update a folder""" user.need_permission("wato.edit") user.need_permission("wato.edit_folders") folder = params["folder"] constructors.require_etag(etag_of_folder(folder)) post_body = params["body"] if "title" in post_body: title = post_body["title"] else: title = folder.title() replace_attributes = post_body["attributes"] update_attributes = post_body["update_attributes"] remove_attributes = post_body["remove_attributes"] attributes = folder.attributes().copy() if replace_attributes: attributes = replace_attributes if update_attributes: attributes.update(update_attributes) faulty_attributes = [] for attribute in remove_attributes: try: attributes.pop(attribute) except KeyError: faulty_attributes.append(attribute) if faulty_attributes: return problem( status=400, title="The folder was not updated", detail=f"The following attributes did not exist and could therefore" f"not be removed: {', '.join(faulty_attributes)}", ) folder.edit(title, attributes) return _serve_folder(folder)
def update(params): """Update a folder """ folder = params['folder'] constructors.require_etag(etag_of_folder(folder)) post_body = params['body'] if 'title' in post_body: title = post_body['title'] else: title = folder.title() replace_attributes = post_body['attributes'] update_attributes = post_body['update_attributes'] remove_attributes = post_body['remove_attributes'] attributes = folder.attributes().copy() if replace_attributes: attributes = replace_attributes if update_attributes: attributes.update(update_attributes) faulty_attributes = [] for attribute in remove_attributes: try: attributes.pop(attribute) except KeyError: faulty_attributes.append(attribute) if faulty_attributes: return problem( status=400, title="The folder was not updated", detail=f"The following attributes did not exist and could therefore" f"not be removed: {', '.join(faulty_attributes)}") folder.edit(title, attributes) return _serve_folder(folder)
def update_nodes(params): """Update the nodes of a cluster host""" host_name = params['host_name'] body = params['body'] nodes = body['nodes'] check_hostname(host_name, should_exist=True) for node in nodes: check_hostname(node, should_exist=True) host: watolib.CREHost = watolib.Host.host(host_name) if not host.is_cluster(): return problem(status=400, title="Trying to change nodes of a regular host.", detail="nodes can only be changed on cluster hosts.") constructors.require_etag(constructors.etag_of_obj(host)) host.edit(host.attributes(), nodes) return constructors.serve_json( constructors.object_sub_property( domain_type='host_config', ident=host_name, name='nodes', value=host.cluster_nodes(), ))
def _require_host_etag(host): etag_values = _host_etag_values(host) constructors.require_etag( constructors.etag_of_dict(etag_values), error_details=etag_values, )
def delete(params): name = params['name'] group = _fetch_service_group(name) constructors.require_etag(constructors.etag_of_dict(group)) watolib.delete_group(name, 'service') return Response(status=204)
def delete(params): name = params['name'] group = _fetch_host_group(name) constructors.require_etag(constructors.etag_of_dict(group)) watolib.delete_group(name, 'host') return constructors.sucess(status=204)