FUSE lets you mount almost anything as a filesystem. With HaveAPI-fs, you can mount your API and work with it as files and directories.
haveapi-fs is a virtual filesystem built on FUSE. Any API using HaveAPI is supported. Of course, it also works with our api.vpsfree.cz (documentation).
Working with haveapi-fs should be even easier than using the console client, because everything is immediately visible as directories and files. There is no need to look up the names of objects, actions, parameters, options and so on.
haveapi-fs is written in Ruby and installed with RubyGems:
$ gem install haveapi-fs
Mount the API with this command:
$ haveapi-fs <api_url> <mountpoint>
For our API, that means:
$ haveapi-fs https://api.vpsfree.cz /mnt/api.vpsfree.cz
Unmount it either with umount as root or with fusermount -u /mnt/api.vpsfree.cz as an unprivileged user.
The mountpoint contains a list of API objects and help files:
$ cd /mnt/api.vpsfree.cz $ tree -L 1 . ├── ... ├── dataset/ ├── environment/ ├── location/ ├── node/ ├── vps/ ├── help.html ├── help.man ├── help.md ├── help.txt └── ...
The help.{html,man,md,txt} files appear in every directory. They describe the current directory, its properties, subdirectories and files.
An object's directory lists all its records, for example all VPSes belonging to the account:
$ tree -L 1 vps/ vps ├── 1112/ ├── 1171/ ├── 1234/ ├── 1245/ ├── actions/ ├── create.yml ├── help.html ├── help.man ├── help.md └── help.txt
We can also filter records directly:
$ tree -L 1 vps/by-node/103/by-os_template/26 vps/by-node/103/by-os_template/26 ├── 1112/ └── ... $ cat vps/by-node/103/by-os_template/26/1112/node_id 103 $ cat vps/by-node/103/by-os_template/26/1112/os_template_id 26
Inside a particular VPS's directory, its attributes appear as files and associated objects as directories. Actions we can call are in actions/:
$ tree -L 1 vps/1112 vps/1112 ├── actions/ ├── id ├── hostname ├── node/ ├── os_template/ ├── edit.yml ├── save └── ... $ cat vps/1112/hostname moje-vps $ cat vps/1112/node/domain_name node3.prg $ cat vps/1112/node/location/label Praha $ cat vps/1112/os_template/label Scientific Linux 6.6
Depending on permissions, some attributes can also be changed. For example, to change the hostname:
$ echo novy-hostname > vps/1112/hostname $ echo 1 > vps/1112/save
Any other action can be called too:
$ tree -L 1 vps/1112/actions vps/1112/actions ├── ... ├── passwd/ ├── reinstall/ ├── restart/ ├── start/ ├── stop/ ├── swap_with/ └── update/ $ echo 1 > vps/1112/actions/passwd/exec
The status file always tells us whether the action succeeded or failed:
$ cat vps/1112/actions/passwd/status 1
Output parameters are in the output/ directory:
$ cat vps/1112/actions/passwd/output/password cmrdBcm72KkAM85Ux2MK
Other files provide any error message (message), a list of errors (errors/) and a way to supply input parameters (input/).
Actions can also be run through an exec.yml file. Fill in its input parameters in YAML, then save and close the file to execute the action. This also makes it easy to create new objects (create.yml) and edit existing ones (edit.yml).
$ vim vps/1112/edit.yml hostname: dalsi-zmena :wq
The full description of what haveapi-fs can do is in README.md.