User Tools

Site Tools


manuals:vps:api

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
manuals:vps:api [2016/12/11 14:44] – created tomsmanuals:vps:api [2017/03/27 07:37] – API v4.1 Aither
Line 10: Line 10:
 ===== API Documentation ===== ===== API Documentation =====
 The API documentation, i.e. a list of objects, possible actions as well as input and output The API documentation, i.e. a list of objects, possible actions as well as input and output
-parameters can be found at https://api.vpsfree.cz/v3.0/.+parameters can be found at https://api.vpsfree.cz/v4.1/.
  
 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 536: Line 536:
 <note> <note>
 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.
 </note> </note>
Line 546: Line 546:
 require 'vpsfree/client' require 'vpsfree/client'
  
-api = VpsFree::Client::Client.new+api = VpsFree::Client.new
 api.authenticate(:token, token: 'PUT YOUR TOKEN HERE') api.authenticate(:token, token: 'PUT YOUR TOKEN HERE')
- 
-downloads = [] 
  
 api.dataset.list(role: :hypervisor).each do |ds| api.dataset.list(role: :hypervisor).each do |ds|
   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: last_snapshot.id)   dl = api.snapshot_download.create(snapshot: last_snapshot.id)
-  +
   unless dl.api_response.ok?   unless dl.api_response.ok?
     warn "#{ds.name}@#{last_snapshot.created_at}: #{dl.api_response.message}"     warn "#{ds.name}@#{last_snapshot.created_at}: #{dl.api_response.message}"
     next     next
   end   end
 +  
 +  # The file is ready for download
 +  puts "Downloading #{id} to #{dl.file_name} (#{dl.size / 1024} GB)"
 +  `wget #{dl.url}`
  
-  downloads << dl.id +  # Finally, delete the file from the server 
-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 "Waiting for the downloads to be ready..." +
-loop do +
-  sleep(5*60) +
- +
-  downloads.delete_if do |id| +
-    dl = api.snapshot_download.find(id) +
-   +
-    unless dl.api_response.ok? +
-      warn "Download #{id} has failed" +
-      next(true)  # remove from the list +
-    end +
-   +
-    if dl.ready +
-      puts "Downloading #{id} to #{dl.file_name} (#{dl.size / 1024} GB)" +
-      `wget "#{dl.url}"+
-      dl.delete +
-      true +
-   +
-    else +
-      false +
-    end +
-  end +
-   +
-  break if downloads.empty?+
 end end
  
Line 601: Line 577:
 require 'vpsfree/client' require 'vpsfree/client'
  
-api = VpsFree::Client::Client.new+api = VpsFree::Client.new
 api.authenticate(:token, token: 'PUT YOUR TOKEN HERE') api.authenticate(:token, token: 'PUT YOUR TOKEN HERE')
  
Line 607: Line 583:
   # 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 598:
       snap.delete       snap.delete
       deleted += 1       deleted += 1
- 
-      # Once again, naive waiting until the action finishes. 
-      sleep(30) 
     end     end
   end   end
manuals/vps/api.txt · Last modified: 2024/01/02 21:05 by aither