Cloud#
The cloud module provides storage and share management for cloud services. Currently supported: Nextcloud.
Installation#
pip install 'gselib[cloud]'
Nextcloud CLI#
All commands are available under gselib cloud nextcloud. Storage commands (create, list, delete) run occ on the server; share commands use the Nextcloud REST API.
Configuration#
Storage management runs occ locally or over SSH. Configure via flags or environment variables:
Flag |
Environment variable |
Description |
|---|---|---|
|
|
Full |
|
|
SSH host (omit to run locally) |
|
|
SSH username |
|
|
Path to private key (prompts for password if omitted) |
Share management uses the OCS REST API. Configure via flags or environment variables:
Flag |
Environment variable |
Description |
|---|---|---|
|
|
Nextcloud base URL |
|
|
Admin username |
|
|
Admin password (prompted if omitted) |
External storage#
Local (no SSH):
gselib cloud nextcloud --occ-cmd "php occ" create-storage --mount MyData --path /srv/data
Via SSH with key:
gselib cloud nextcloud \
--occ-cmd "php occ" \
--ssh-host myserver --ssh-user admin --ssh-key ~/.ssh/id_ed25519 \
create-storage --mount MyData --path /srv/data
Nextcloud AIO (Docker over SSH):
gselib cloud nextcloud \
--occ-cmd "docker exec --user www-data nextcloud-aio-nextcloud php occ" \
--ssh-host myserver --ssh-user admin --ssh-key ~/.ssh/id_ed25519 \
create-storage --mount MyData --path /srv/data --users alice bob
With groups:
gselib cloud nextcloud --occ-cmd "php occ" \
create-storage --mount Shared --path /srv/shared --groups scientists
List storages:
gselib cloud nextcloud --occ-cmd "php occ" list-storages
Delete a storage:
gselib cloud nextcloud --occ-cmd "php occ" delete-storage --id 3
Nextcloud library#
from gselib.cloud import NextcloudClient, NextcloudOCC
# External storage via occ (local)
with NextcloudOCC(occ_cmd="php occ") as occ:
mount = occ.create_local_storage("MyData", "/srv/data", applicable_users=["alice"])
print(mount["id"])
mounts = occ.list_storages()
occ.delete_storage(mount["id"])
# External storage via SSH
with NextcloudOCC(host="myserver", user="admin", key_path="~/.ssh/id_ed25519", occ_cmd="php occ") as occ:
occ.create_local_storage("MyData", "/srv/data")
# Nextcloud AIO (Docker over SSH)
with NextcloudOCC(
host="myserver",
user="admin",
key_path="~/.ssh/id_ed25519",
occ_cmd="docker exec --user www-data nextcloud-aio-nextcloud php occ",
) as occ:
occ.create_local_storage("MyData", "/srv/data")
# Shares via REST API
client = NextcloudClient("https://nextcloud.example.org", "admin", "password")
client.share_with_many("/MyData", ["alice", "bob@external.org"], permissions=NextcloudClient.perm_read)
shares = client.list_shares(path="/MyData")
client.delete_share(shares[0]["id"])