def delete_realm(realmname): """ delete the realm from the Database Table with the given name If, after deleting this realm, there is only one realm left, the remaining realm is set the default realm. :param realmname: the to be deleted realm :type realmname: string """ # Check if there is a default realm defRealm = get_default_realm() hadDefRealmBefore = (defRealm != "") ret = fetch_one_resource(Realm, name=realmname).delete() # If there was a default realm before # and if there is only one realm left, we set the # remaining realm the default realm if hadDefRealmBefore is True: defRealm = get_default_realm() if not defRealm: realms = get_realms() if len(realms) == 1: for key in realms: set_default_realm(key) return ret
def delete_smtpserver(identifier): """ Delete the given server from the database. Raise a ResourceNotFoundError if it couldn't be found. :param identifier: The identifier/name of the server :return: The ID of the database entry, that was deleted """ return fetch_one_resource(SMTPServerDB, identifier=identifier).delete()
def delete_smsgateway(identifier): """ Delete the SMS gateway configuration with this given ID. :param identifier: The name of the SMS gateway definition :type identifier: basestring :return: """ return fetch_one_resource(SMSGateway, identifier=identifier).delete()
def delete_radius(identifier): """ Delete the given server from the database. If no such entry could be found, a ResourceNotFoundError is raised. :param identifier: The identifier/name of the server :return: The ID of the database entry, that was deleted """ return fetch_one_resource(RADIUSServerDB, identifier=identifier).delete()
def _get_periodic_task_entry(ptask_id): """ Get a periodic task entry by ID. Raise ResourceNotFoundError if the task could not be found. This is only for internal use. :param id: task ID as integer :return: PeriodicTask object """ return fetch_one_resource(PeriodicTask, id=ptask_id)
def delete_event(event_id): """ Delete the event configuration with this given ID. :param event_id: The database ID of the event. :type event_id: int :return: """ event_id = int(event_id) return fetch_one_resource(EventHandler, id=event_id).delete()
def delete_smsgateway_option(id, option_key): """ Delete the SMS gateway option :param id: The id of the SMS Gateway definition :param option_key: The identifier/key of the option :return: True """ return fetch_one_resource(SMSGatewayOption, gateway_id=id, Key=option_key).delete()
def get_smtpserver(identifier): """ This returns the SMTP Server object of the SMTP Server definition "identifier". In case the identifier does not exist, a ResourceNotFoundError is raised. :param identifier: The name of the SMTP server definition :return: A SMTP Server Object """ return SMTPServer(fetch_one_resource(SMTPServerDB, identifier=identifier))
def delete_smsgateway_key_generic(id, key, Type="option"): """ Delete the SMS gateway header :param id: The id of the SMS Gateway definition :param key: The identifier/key :param type: The type of the key :return: True """ return fetch_one_resource(SMSGatewayOption, gateway_id=id, Key=key, Type=Type).delete()
def list_token_machines(serial): """ This method returns the machines for a given token :return: returns a list of machines and apps """ res = [] db_token = fetch_one_resource(Token, serial=serial) for machine in db_token.machine_list: hostname = "unknown" if machine.machine_id and machine.machineresolver_id: MR = fetch_one_resource(MachineResolver, id=machine.machineresolver_id) resolver_name = MR.name else: resolver_name = NO_RESOLVER hostname = "any host" option_list = machine.option_list options = {} for option in option_list: options[option.mt_key] = option.mt_value # Try to determine the hostname machines = get_machines(id=machine.machine_id, resolver=resolver_name) if len(machines) == 1: # There is only one machine in the list and we get its ID hostname = machines[0].hostname # return the first hostname if type(hostname) == list: hostname = hostname[0] res.append({ "machine_id": machine.machine_id or ANY_MACHINE, "hostname": hostname, "application": machine.application, "resolver": resolver_name, "options": options, "serial": serial }) return res
def list_token_machines(serial): """ This method returns the machines for a given token :return: returns a list of machines and apps """ res = [] db_token = fetch_one_resource(Token, serial=serial) for machine in db_token.machine_list: MR = fetch_one_resource(MachineResolver, id=machine.machineresolver_id) resolver_name = MR.name option_list = machine.option_list options = {} for option in option_list: options[option.mt_key] = option.mt_value machines = get_machines(id=machine.machine_id, resolver=resolver_name) hostname = "unknown" """ if len(machines) > 1: raise Exception("Can not get unique ID for IP=%r. " "More than one machine found." % ip) """ if len(machines) == 1: # There is only one machine in the list and we get its ID hostname = machines[0].hostname # return the first hostname if type(hostname) == list: hostname = hostname[0] res.append({ "machine_id": machine.machine_id, "hostname": hostname, "application": machine.application, "resolver": resolver_name, "options": options, "serial": serial }) return res
def enable_event(event_id, enable=True): """ Enable or disable the and event :param event_id: ID of the event :return: """ ev = fetch_one_resource(EventHandler, id=event_id) # Update the event ev.active = enable r = ev.save() return r
def delete_caconnector(connector_name): """ delete a CA connector and all related config entries. If there was no CA connector, that could be deleted, a ResourceNotFoundError is raised. :param connector_name: The name of the CA connector that is to be deleted :type connector_name: basestring :return: The Id of the resolver :rtype: int """ return fetch_one_resource(CAConnector, name=connector_name).delete()
def delete_resolver(resolvername): """ delete a machine resolver and all related MachineResolverConfig entries If there was no resolver, this raises a ResourceNotFoundError. :param resolvername: the name of the to be deleted resolver :type resolvername: string :return: The Id of the resolver :rtype: int """ return fetch_one_resource(MachineResolver, name=resolvername).delete()
def delete_db_admin(username): print("Deleting admin {0!s}".format(username)) fetch_one_resource(Admin, username=username).delete()