This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
manuals:vps:api [2016/12/11 14:44] – created toms | manuals:vps:api [2025/03/24 20:40] (current) – Fix API doc link aither | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== API ====== | ====== API ====== | ||
- | Our API is running at https:// | + | Our API is running at https:// |
- | actions, just like you can do from the web interface. | + | any action that you can do in the web interface. In fact, the web interface |
- | are the management of user profiles (address, email, etc.) and data transfers. | + | running at https:// |
- | + | action. | |
- | In reality, the web interface running at https:// | + | |
- | the API and calls it for every action. | + | |
===== API Documentation ===== | ===== API Documentation ===== | ||
The API documentation, | The API documentation, | ||
- | parameters can be found at https:// | + | parameters can be found at https:// |
Even without logging in, you can see a list of all objects, i.e. even those that only | Even without logging in, you can see a list of all objects, i.e. even those that only | ||
Line 25: | Line 23: | ||
* Ruby - https:// | * Ruby - https:// | ||
- | * PHP - https:// | + | * PHP - https:// |
- | * JavaScript - https:// | + | * JavaScript - https:// |
- | * The HaveAPI web interface - https:// | + | * Go - https:// |
- | * A file system based on FUSE - https:// | + | * The HaveAPI web interface - https:// |
+ | * A file system based on FUSE - https:// | ||
Usage examples can always be found in the '' | Usage examples can always be found in the '' | ||
Line 39: | Line 38: | ||
===== Authentication===== | ===== Authentication===== | ||
- | There are two authentication methods | + | There are two authentication methods: |
- | basic. The name and password must be sent along with every API request. This is a good | + | |
- | choice for one-off actions. However, if you need to call the API several times or | + | |
- | automatically, | + | |
- | Another method is authentication using tokens. The way this method works is that the client first | + | * [[# |
- | requests a token to be created, one for which the client needs the name and password. As soon as the client receives | + | * [[# |
- | the token, the name and password can be forgotten since it is the token that is then used for further authentication. | + | |
- | There can be several types of tokens with different lifetimes: | + | Example usage in different programming languages |
- | * fixed - token validity is fixed | + | ==== HTTP Basic ==== |
- | * renewable_manual - token validity can be manually extended | + | The name and password must be sent along with every API request |
- | * renewable_auto - token validity is extended after every request | + | This is a good choice for one-off actions. However, if you need to call the API repeatedly or |
- | * permament | + | automatically, storing the password on the disk or entering |
+ | HTTP Basic cannot be used if two-factor authentication | ||
- | The type of token and time period by which its validity is extended is chosen by the client. | + | ==== Tokens ==== |
+ | The client first requests a token using your credentials | ||
+ | As soon as the client | ||
+ | is used for authentication. | ||
- | ===== CLI ===== | + | There can be several types of tokens |
- | [[https:// | + | |
- | In order for it to work properly, you need Ruby >= 2.0 and Ruby header files, | + | |
- | OpenSSL and ncurses (mostly packages | + | |
- | < | + | * //fixed// - token validity is fixed |
- | If you’re using OS X, you first need to install OpenSSL using [[http://brew.sh/|Homebrew]] and only then | + | * // |
- | can you install EventMachine (a gem required by the client). | + | * // |
+ | * // | ||
- | < | + | The type of token and time period by which its validity is extended is chosen |
- | $ brew install openssl | + | by the client. |
- | $ sudo gem install eventmachine -- --with-opt-include="/ | + | |
- | </ | + | |
- | </ | + | |
- | It can be installed using ruby gems: | + | ===== Scopes ===== |
+ | Authentication tokens | ||
+ | you can find the available scopes in the documentation. You can configure scopes when you' | ||
+ | requesting a new authentication token. | ||
- | < | + | Example scopes: |
- | $ gem install vpsfree-client | + | |
- | </ | + | |
- | ==== Installing in Windows 10 Using a Ubuntu Linux Subsystem ==== | + | * '' |
+ | * an empty scope will allow access only to '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
- | === Installing Ubuntu (Windows 10 Subsystem | + | Scopes can contain globs for resource and action names. Action name is separated from resource name by a hash (''#'' |
- | | + | ===== Installing vpsfree-client ===== |
- | - in the Programs and Features menu, open Turn Windows Features On or Off, scroll | + | [[https:// |
- | | + | In order for it to work properly, you need Ruby >= 2.7, Ruby header files and ncurses (mostly packages with the '' |
- | | + | |
- | - press the Y key and let the Ubuntu base be installed | + | |
- | + | ||
- | === Installing Dependencies === | + | |
<code bash> | <code bash> | ||
- | sudo apt-get | + | gem install |
</ | </ | ||
- | === A Quick & Dirty Fix to Set Ruby2.0 as Default Instead of 1.9 === | + | Platform-specific instructions: |
- | + | ||
- | <code bash> | + | |
- | sudo rm / | + | |
- | sudo ln -s / | + | |
- | sudo ln -s / | + | |
- | sudo ln -s / | + | |
- | sudo ln -s / | + | |
- | sudo ln -s / | + | |
- | sudo gem update --system | + | |
- | sudo gem pristine --all | + | |
- | </ | + | |
- | + | ||
- | Source: http:// | + | |
- | + | ||
- | === Installing vpsfree-client === | + | |
- | + | ||
- | <code bash> | + | |
- | sudo gem install vpsfree-client | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ---- | + | |
+ | * [[manuals: | ||
+ | * [[manuals: | ||
- | After the installation, | + | After the installation, |
this can be fixed easily: | this can be fixed easily: | ||
Line 130: | Line 107: | ||
< | < | ||
- | $ PATH=" | + | $ PATH=" |
</ | </ | ||
- | ==== Usage ==== | + | ==== Using CLI ==== |
< | < | ||
Line 165: | Line 142: | ||
Commands: | Commands: | ||
- | vps remote_console VPS_ID | + | action_state wait <STATE ID> |
+ | vps remote_console VPS_ID | ||
+ | vps migrate_many VPS_ID... | ||
+ | snapshot download [SNAPSHOT_ID] | ||
+ | snapshot send SNAPSHOT_ID | ||
+ | backup dataset [DATASET_ID] FILESYSTEM Backup dataset locally | ||
+ | backup vps [VPS_ID] FILESYSTEM | ||
+ | ip_traffic top Live IP traffic monitor | ||
Available resources: | Available resources: | ||
- | auth_token | ||
cluster | cluster | ||
cluster_resource | cluster_resource | ||
+ | cluster_resource_package | ||
+ | cluster_resource_package.item | ||
dataset | dataset | ||
dataset.snapshot | dataset.snapshot | ||
dataset.plan | dataset.plan | ||
+ | dataset.property_history | ||
dataset_plan | dataset_plan | ||
dns_resolver | dns_resolver | ||
Line 179: | Line 165: | ||
environment.config_chain | environment.config_chain | ||
environment.dataset_plan | environment.dataset_plan | ||
+ | host_ip_address | ||
integrity_check | integrity_check | ||
integrity_fact | integrity_fact | ||
integrity_object | integrity_object | ||
ip_address | ip_address | ||
+ | ip_traffic | ||
+ | ip_traffic_monitor | ||
+ | language | ||
location | location | ||
mail_log | mail_log | ||
Line 188: | Line 178: | ||
mail_template | mail_template | ||
mail_template.recipient | mail_template.recipient | ||
+ | mail_template.translation | ||
+ | migration_plan | ||
+ | migration_plan.vps_migration | ||
+ | network | ||
+ | network_interface | ||
node | node | ||
+ | node.status | ||
+ | object_history | ||
os_template | os_template | ||
pool | pool | ||
+ | session_token | ||
snapshot_download | snapshot_download | ||
+ | system_config | ||
+ | transaction | ||
transaction_chain | transaction_chain | ||
- | transaction_chain.transaction | ||
user | user | ||
user.environment_config | user.environment_config | ||
user.cluster_resource | user.cluster_resource | ||
+ | user.public_key | ||
+ | user.mail_role_recipient | ||
+ | user.mail_template_recipient | ||
user.state_log | user.state_log | ||
+ | user_cluster_resource_package | ||
+ | user_cluster_resource_package.item | ||
+ | user_namespace | ||
+ | user_namespace_map | ||
+ | user_namespace_map.entry | ||
user_session | user_session | ||
vps | vps | ||
Line 203: | Line 210: | ||
vps.config | vps.config | ||
vps.feature | vps.feature | ||
- | vps.ip_address | ||
vps.mount | vps.mount | ||
+ | vps.outage_window | ||
vps.console_token | vps.console_token | ||
+ | vps.status | ||
vps_config | vps_config | ||
+ | monitored_event | ||
+ | monitored_event.log | ||
+ | outage | ||
+ | outage.entity | ||
+ | outage.handler | ||
+ | outage_update | ||
+ | user_outage | ||
+ | vps_outage | ||
+ | vps_outage_mount | ||
+ | help_box | ||
+ | news_log | ||
+ | incoming_payment | ||
+ | payment_stats | ||
+ | user_account | ||
+ | user_payment | ||
+ | user_request | ||
+ | user_request.registration | ||
+ | user_request.change | ||
+ | action_state | ||
</ | </ | ||
Line 234: | Line 261: | ||
-a, --auth METHOD | -a, --auth METHOD | ||
-s, --save | -s, --save | ||
- | --username | + | --user USER User name |
--password PASSWORD | --password PASSWORD | ||
+ | --scope [SCOPE] | ||
--token TOKEN Token | --token TOKEN Token | ||
--token-lifetime LIFETIME | --token-lifetime LIFETIME | ||
Line 280: | Line 308: | ||
access to '' | access to '' | ||
</ | </ | ||
+ | |||
+ | Specify a scope: | ||
+ | |||
+ | < | ||
+ | $ vpsfreectl --auth token --scope ' | ||
+ | </ | ||
+ | |||
+ | The command above will ask for an authentication token that will only be allowed to call actions on the vps resource and only on VPS with ID 123. | ||
==== Actions and Parameters ==== | ==== Actions and Parameters ==== | ||
Line 536: | Line 572: | ||
< | < | ||
Although these examples are still valid, the CLI client already contains | Although these examples are still valid, the CLI client already contains | ||
- | [[navody:vps:datasety#stahovani_zaloh|commands]] which make downloading backups | + | [[manuals:vps:datasets#downloading_backups|commands]] which make downloading backups |
even easier. | even easier. | ||
</ | </ | ||
Line 546: | Line 582: | ||
require ' | require ' | ||
- | api = VpsFree::Client:: | + | api = VpsFree:: |
api.authenticate(: | api.authenticate(: | ||
- | |||
- | downloads = [] | ||
api.dataset.list(role: | api.dataset.list(role: | ||
last_snapshot = ds.snapshot.list.last | last_snapshot = ds.snapshot.list.last | ||
+ | # This action may take up to several hours | ||
dl = api.snapshot_download.create(snapshot: | dl = api.snapshot_download.create(snapshot: | ||
- | | + | |
unless dl.api_response.ok? | unless dl.api_response.ok? | ||
warn "# | warn "# | ||
next | next | ||
end | end | ||
+ | | ||
+ | # The file is ready for download | ||
+ | puts " | ||
+ | `wget #{dl.url}` | ||
- | | + | # Finally, delete |
- | end | + | dl.delete |
- | + | ||
- | # vpsAdmin is now creating a tar.gz with the backup and it will take a while until it can be | + | |
- | # downloaded. There are regular checks for the “ready” parameter for all archives. | + | |
- | puts " | + | |
- | loop do | + | |
- | sleep(5*60) | + | |
- | + | ||
- | downloads.delete_if do |id| | + | |
- | dl = api.snapshot_download.find(id) | + | |
- | + | ||
- | unless dl.api_response.ok? | + | |
- | warn " | + | |
- | next(true) | + | |
- | end | + | |
- | | + | |
- | if dl.ready | + | |
- | puts " | + | |
- | `wget "# | + | |
- | | + | |
- | true | + | |
- | + | ||
- | else | + | |
- | false | + | |
- | end | + | |
- | end | + | |
- | + | ||
- | break if downloads.empty? | + | |
end | end | ||
Line 601: | Line 613: | ||
require ' | require ' | ||
- | api = VpsFree::Client:: | + | api = VpsFree:: |
api.authenticate(: | api.authenticate(: | ||
Line 607: | Line 619: | ||
# Creating a new snapshot | # Creating a new snapshot | ||
ds.snapshot.create | ds.snapshot.create | ||
- | |||
- | # Naive waiting until the snapshot is created. A different option would be checking | ||
- | # the state of the corresponding transaction chain. | ||
- | sleep(10) | ||
# Deleting older snapshots | # Deleting older snapshots | ||
Line 626: | Line 634: | ||
snap.delete | snap.delete | ||
deleted += 1 | deleted += 1 | ||
- | |||
- | # Once again, naive waiting until the action finishes. | ||
- | sleep(30) | ||
end | end | ||
end | end |