def delete_user(self, login_name):
        api = NaElement("useradmin-user-delete")
        api.child_add_string("user-name", login_name)

        xo = self.naserver.invoke_elem(api)
        if xo.results_status() == "failed":
            if xo.results_errno() == "13114":
                raise deleteUserNotFoundException(xo.results_errno(), xo.results_reason())
            else:
                raise deleteUserException(xo.results_errno(), xo.results_reason())

        return True
    def delete_dir(self, path):
        api = NaElement("file-delete-directory")
        api.child_add_string("path", path)

        xo = self.naserver.invoke_elem(api)
        if xo.results_status() == "failed":
            if xo.results_errno() == "2":
                raise deleteDirNotFoundException(xo.results_errno(), xo.results_reason())
            else:
                raise DirException(xo.results_errno(), xo.results_reason())

        return True
    def delete_file(self, path):
        api = NaElement("file-delete-file")
        api.child_add_string("path", path)

        xo = self.naserver.invoke_elem(api)
        if xo.results_status() == "failed":
            if xo.results_errno() == "2":
                raise deleteFileNotFoundException(xo.results_errno(), xo.results_reason())
            elif xo.results_errno() == 13001:
                raise ApiNotEnabledException(xo.results_errno(), xo.results_reason())
            else:
                raise FileException(xo.results_errno(), xo.results_reason())

        return True
    def create_dir(self, path, perm="755"):
        """
        Create directory specified by path. Assumes that only last dir in path needs to be created and preceeding
         dirs in path already exists.
        If directory exists or was created, it will return path
        In case of any error it will raise createDirException
        """
        api = NaElement("file-create-directory")
        api.child_add_string("path", path)
        api.child_add_string("perm", perm)

        xo = self.naserver.invoke_elem(api)
        if xo.results_status() == "failed":
            if xo.results_errno() == "17":
                # if directory exists it means, that dir is created and returns True
                return path
            else:
                raise createDirException(xo.results_errno(), xo.results_reason())

        return path
    def create_user(self, login_name, password, full_name=""):
        """
        Create user by API (same as useradmin user add in CLI)
        """

        api = NaElement("useradmin-user-add")
        api.child_add_string("password", password)

        xi = NaElement("useradmin-user")
        api.child_add(xi)

        xi1 = NaElement("useradmin-user-info")
        xi.child_add(xi1)

        xi1.child_add_string("comment", "UserManagement")
        xi1.child_add_string("full-name", full_name)
        xi1.child_add_string("name", login_name)

        xi2 = NaElement("useradmin-groups")
        xi1.child_add(xi2)

        xi3 = NaElement("useradmin-group-info")
        xi2.child_add(xi3)

        xi3.child_add_string("name", "Administrators")

        xo = self.naserver.invoke_elem(api)
        if xo.results_status() == "failed":
            if xo.results_errno() == "13114":
                raise createUserAlreadyExistsException(xo.results_errno(), xo.results_reason())
            elif xo.results_errno() == 13001:
                raise ApiNotEnabledException(xo.results_errno(), xo.results_reason())
            elif xo.results_errno() == 13002:
                raise AuthorizationFailed(xo.results_errno(), xo.results_reason())
            else:
                raise createUserException(xo.results_errno(), xo.results_reason())

        return True
    def create_file(self, path, data):
        datahex = data.encode("hex")

        api = NaElement("file-write-file")
        api.child_add_string("data", datahex)
        api.child_add_string("offset", "0")
        api.child_add_string("path", path)

        xo = self.naserver.invoke_elem(api)
        if xo.results_status() == "failed":
            raise FileException(xo.results_errno(), xo.results_reason())