vpsadmin-client 3.0.0.master.20240728.pre.0.dc5474cc → 3.0.0.master.202211181.pre.0.ac358990
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -4
- data/Rakefile +1 -0
- data/lib/{terminal_size.rb → terminal-size.rb} +17 -23
- data/lib/vpsadmin/cli/commands/backup_dataset.rb +98 -96
- data/lib/vpsadmin/cli/commands/backup_vps.rb +1 -1
- data/lib/vpsadmin/cli/commands/base_download.rb +6 -6
- data/lib/vpsadmin/cli/commands/network_top.rb +59 -65
- data/lib/vpsadmin/cli/commands/snapshot_download.rb +21 -20
- data/lib/vpsadmin/cli/commands/snapshot_send.rb +7 -6
- data/lib/vpsadmin/cli/commands/vps_migrate_many.rb +12 -10
- data/lib/vpsadmin/cli/commands/vps_remote_console.rb +30 -29
- data/lib/vpsadmin/cli/stream_downloader.rb +45 -38
- data/lib/vpsadmin/cli.rb +2 -2
- data/lib/vpsadmin/client/version.rb +1 -1
- data/lib/vpsadmin/client.rb +3 -2
- data/shell.nix +6 -6
- data/vpsadmin-client.gemspec +10 -7
- metadata +38 -10
@@ -1,8 +1,8 @@
|
|
1
|
+
require 'thread'
|
1
2
|
require 'time'
|
2
3
|
require 'json'
|
3
4
|
require 'base64'
|
4
|
-
require '
|
5
|
-
require 'terminal_size'
|
5
|
+
require 'terminal-size'
|
6
6
|
|
7
7
|
module VpsAdmin::CLI::Commands
|
8
8
|
class VpsRemoteControl < HaveAPI::CLI::Command
|
@@ -14,7 +14,7 @@ module VpsAdmin::CLI::Commands
|
|
14
14
|
def initialize(http_client)
|
15
15
|
@http_client = http_client
|
16
16
|
@private_buffer = ''
|
17
|
-
@end_seq = ["\r", "\e",
|
17
|
+
@end_seq = ["\r", "\e", "."]
|
18
18
|
@end_i = 0
|
19
19
|
@stop = false
|
20
20
|
end
|
@@ -37,7 +37,6 @@ module VpsAdmin::CLI::Commands
|
|
37
37
|
end
|
38
38
|
|
39
39
|
protected
|
40
|
-
|
41
40
|
attr_reader :http_client
|
42
41
|
|
43
42
|
# Data is checked on the presence of the end sequence. The first character
|
@@ -53,10 +52,10 @@ module VpsAdmin::CLI::Commands
|
|
53
52
|
buffer = ''
|
54
53
|
|
55
54
|
data.each_char do |char|
|
56
|
-
if char == @end_seq[@end_i]
|
55
|
+
if char == @end_seq[ @end_i ]
|
57
56
|
if @end_i == @end_seq.size - 1
|
58
57
|
@stop = true
|
59
|
-
return
|
58
|
+
return
|
60
59
|
end
|
61
60
|
|
62
61
|
@end_i += 1
|
@@ -112,7 +111,9 @@ module VpsAdmin::CLI::Commands
|
|
112
111
|
@error != false
|
113
112
|
end
|
114
113
|
|
115
|
-
|
114
|
+
def error
|
115
|
+
@error
|
116
|
+
end
|
116
117
|
|
117
118
|
def join
|
118
119
|
stop
|
@@ -131,14 +132,13 @@ module VpsAdmin::CLI::Commands
|
|
131
132
|
end
|
132
133
|
|
133
134
|
protected
|
134
|
-
|
135
135
|
attr_reader :vps, :token, :rate, :width, :height, :write_buffer,
|
136
|
-
|
136
|
+
:mutex, :thread
|
137
137
|
|
138
138
|
def run
|
139
139
|
uri = URI("#{vps.node.location.remote_console_server}/console/feed/#{vps.id}")
|
140
140
|
start_args = [uri.host, uri.port, nil, nil, nil, nil, {
|
141
|
-
use_ssl: uri.scheme == 'https'
|
141
|
+
use_ssl: uri.scheme == 'https',
|
142
142
|
}]
|
143
143
|
|
144
144
|
Net::HTTP.start(*start_args) do |http|
|
@@ -164,14 +164,14 @@ module VpsAdmin::CLI::Commands
|
|
164
164
|
'session' => token,
|
165
165
|
'keys' => keys,
|
166
166
|
'width' => width,
|
167
|
-
'height' => height
|
167
|
+
'height' => height,
|
168
168
|
)
|
169
169
|
|
170
170
|
res = http.request(req)
|
171
171
|
|
172
172
|
unless res.is_a?(Net::HTTPSuccess)
|
173
173
|
set_error(
|
174
|
-
|
174
|
+
"Console server returned error: "+
|
175
175
|
"HTTP #{res.code} - #{res.message}\n\n#{res.body}"
|
176
176
|
)
|
177
177
|
stop
|
@@ -182,7 +182,7 @@ module VpsAdmin::CLI::Commands
|
|
182
182
|
|
183
183
|
unless ret[:session]
|
184
184
|
$stdout.write(ret[:data])
|
185
|
-
set_error(
|
185
|
+
set_error("Session closed.")
|
186
186
|
stop
|
187
187
|
return
|
188
188
|
end
|
@@ -216,36 +216,38 @@ module VpsAdmin::CLI::Commands
|
|
216
216
|
|
217
217
|
def exec(args)
|
218
218
|
if args.empty?
|
219
|
-
puts
|
219
|
+
puts "provide VPS ID as an argument"
|
220
220
|
exit(false)
|
221
221
|
end
|
222
222
|
|
223
223
|
vps_id = args.first.to_i
|
224
224
|
|
225
|
-
write
|
225
|
+
write "Locating VPS.."
|
226
226
|
begin
|
227
227
|
vps = @api.vps.show(vps_id, meta: { includes: 'node__location' })
|
228
|
+
|
228
229
|
rescue HaveAPI::Client::ActionFailed => e
|
229
|
-
puts
|
230
|
+
puts " error"
|
230
231
|
puts e.message
|
231
232
|
exit(false)
|
232
233
|
end
|
233
234
|
|
234
235
|
puts " VPS is on #{vps.node.domain_name}, located in #{vps.node.location.label}."
|
235
236
|
puts "Console server URL is #{vps.node.location.remote_console_server}"
|
236
|
-
write
|
237
|
+
write "Obtaining authentication token..."
|
237
238
|
|
238
239
|
begin
|
239
240
|
t = vps.console_token.create
|
241
|
+
|
240
242
|
rescue HaveAPI::Client::ActionFailed => e
|
241
|
-
puts
|
243
|
+
puts " error"
|
242
244
|
puts e.message
|
243
245
|
exit(false)
|
244
246
|
end
|
245
247
|
|
246
248
|
puts
|
247
|
-
puts
|
248
|
-
puts
|
249
|
+
puts "Connecting to the remote console..."
|
250
|
+
puts "Press ENTER ESC . to exit"
|
249
251
|
puts
|
250
252
|
|
251
253
|
raw_mode do
|
@@ -254,7 +256,6 @@ module VpsAdmin::CLI::Commands
|
|
254
256
|
end
|
255
257
|
|
256
258
|
protected
|
257
|
-
|
258
259
|
attr_reader :client
|
259
260
|
|
260
261
|
def raw_mode
|
@@ -288,19 +289,19 @@ module VpsAdmin::CLI::Commands
|
|
288
289
|
client.start
|
289
290
|
|
290
291
|
loop do
|
291
|
-
res = $stdin
|
292
|
+
res = IO.select([$stdin], [], [], 1)
|
292
293
|
input.read_from($stdin) if res
|
293
294
|
|
294
|
-
|
295
|
+
if input.stop? || client.stop?
|
296
|
+
client.join
|
295
297
|
|
296
|
-
|
298
|
+
if client.error?
|
299
|
+
write("\n")
|
300
|
+
write(client.error)
|
301
|
+
end
|
297
302
|
|
298
|
-
|
299
|
-
write("\n")
|
300
|
-
write(client.error)
|
303
|
+
return
|
301
304
|
end
|
302
|
-
|
303
|
-
return
|
304
305
|
end
|
305
306
|
end
|
306
307
|
|
@@ -4,15 +4,15 @@ require 'ruby-progressbar'
|
|
4
4
|
require 'digest'
|
5
5
|
|
6
6
|
module VpsAdmin::CLI
|
7
|
-
class DownloadError < StandardError; end
|
7
|
+
class DownloadError < StandardError ; end
|
8
8
|
|
9
9
|
class StreamDownloader
|
10
|
-
def self.download(
|
11
|
-
new(
|
10
|
+
def self.download(*args, **kwargs)
|
11
|
+
new(*args, **kwargs)
|
12
12
|
end
|
13
13
|
|
14
|
-
def initialize(api, dl, io, progress:
|
15
|
-
|
14
|
+
def initialize(api, dl, io, progress: STDOUT, position: 0, max_rate: nil,
|
15
|
+
checksum: true)
|
16
16
|
downloaded = position
|
17
17
|
uri = URI(dl.url)
|
18
18
|
digest = Digest::SHA256.new
|
@@ -26,12 +26,12 @@ module VpsAdmin::CLI
|
|
26
26
|
format: '%E %t: [%B] %p%% %r MB/s',
|
27
27
|
rate_scale: ->(rate) { (rate / 1024.0 / 1024.0).round(2) },
|
28
28
|
throttle_rate: 0.2,
|
29
|
-
output: progress
|
29
|
+
output: progress,
|
30
30
|
)
|
31
31
|
end
|
32
32
|
|
33
33
|
read = 0
|
34
|
-
step = 1
|
34
|
+
step = 1*1024*1024
|
35
35
|
io.seek(0)
|
36
36
|
|
37
37
|
while read < position
|
@@ -56,20 +56,20 @@ module VpsAdmin::CLI
|
|
56
56
|
throttle_rate: 0.2,
|
57
57
|
starting_at: downloaded,
|
58
58
|
autofinish: false,
|
59
|
-
output: progress
|
59
|
+
output: progress,
|
60
60
|
)
|
61
61
|
end
|
62
62
|
|
63
|
-
args = [uri.host] + Array.new(5, nil) + [{
|
63
|
+
args = [uri.host] + Array.new(5, nil) + [{use_ssl: uri.scheme == 'https'}]
|
64
64
|
|
65
65
|
Net::HTTP.start(*args) do |http|
|
66
66
|
loop do
|
67
67
|
begin
|
68
68
|
dl_check = api.snapshot_download.show(dl.id)
|
69
69
|
|
70
|
-
if @pb && (dl_check.ready || (dl_check.size && dl_check.size > 0))
|
70
|
+
if @pb && (dl_check.ready || (dl_check.size && dl_check.size > 0))
|
71
71
|
total = dl_check.size * 1024 * 1024
|
72
|
-
@pb.total =
|
72
|
+
@pb.total = @pb.progress > total ? @pb.progress : total
|
73
73
|
|
74
74
|
@download_size = (dl_check.size / 1024.0).round(2)
|
75
75
|
|
@@ -81,6 +81,7 @@ module VpsAdmin::CLI
|
|
81
81
|
self.format = "%E %t ~#{@download_size} GB: [%B] %p%% %r kB/s"
|
82
82
|
end
|
83
83
|
end
|
84
|
+
|
84
85
|
rescue HaveAPI::Client::ActionFailed => e
|
85
86
|
# The SnapshotDownload object no longer exists, the transaction
|
86
87
|
# responsible for its creation must have failed.
|
@@ -93,32 +94,36 @@ module VpsAdmin::CLI
|
|
93
94
|
|
94
95
|
http.request_get(uri.path, headers) do |res|
|
95
96
|
case res.code
|
96
|
-
when '404'
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
# The file is not available yet, this is normal, the transaction
|
103
|
-
# may be queued and it can take some time before it is processed.
|
104
|
-
pause(10)
|
105
|
-
next
|
97
|
+
when '404' # Not Found
|
98
|
+
if downloaded > 0
|
99
|
+
# This means that the transaction used for preparing the download
|
100
|
+
# has failed, the file to download does not exist anymore, so fail.
|
101
|
+
raise DownloadError, 'The download has failed, most likely transaction failure'
|
106
102
|
|
107
|
-
|
108
|
-
|
103
|
+
else
|
104
|
+
# The file is not available yet, this is normal, the transaction
|
105
|
+
# may be queued and it can take some time before it is processed.
|
106
|
+
pause(10)
|
107
|
+
next
|
108
|
+
end
|
109
109
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
110
|
+
when '416' # Range Not Satisfiable
|
111
|
+
if downloaded > position
|
112
|
+
# We have already managed to download something (at this run, if the trasfer
|
113
|
+
# was resumed) and the server cannot provide more data yet. This can be
|
114
|
+
# because the server is busy. Wait and retry.
|
115
|
+
pause(20)
|
116
|
+
next
|
115
117
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
118
|
+
else
|
119
|
+
# The file is not ready yet - we ask for range that cannot be provided
|
120
|
+
# This happens when we're resuming a download and the file on the
|
121
|
+
# server was deleted meanwhile. The file might not be exactly the same
|
122
|
+
# as the one before, sha256sum would most likely fail.
|
123
|
+
raise DownloadError, 'Range not satisfiable'
|
124
|
+
end
|
120
125
|
|
121
|
-
when '200', '206'
|
126
|
+
when '200', '206' # OK and Partial Content
|
122
127
|
resume
|
123
128
|
|
124
129
|
else
|
@@ -135,7 +140,10 @@ module VpsAdmin::CLI
|
|
135
140
|
downloaded += size
|
136
141
|
|
137
142
|
begin
|
138
|
-
|
143
|
+
if @pb && (@pb.total.nil? || @pb.progress < @pb.total)
|
144
|
+
@pb.progress += size
|
145
|
+
end
|
146
|
+
|
139
147
|
rescue ProgressBar::InvalidProgressError
|
140
148
|
# The total value is in MB, it is not precise, so the actual
|
141
149
|
# size may be a little bit bigger.
|
@@ -178,13 +186,12 @@ module VpsAdmin::CLI
|
|
178
186
|
@pb.finish if @pb
|
179
187
|
|
180
188
|
# Verify the checksum
|
181
|
-
|
182
|
-
|
183
|
-
|
189
|
+
if checksum && digest.hexdigest != dl_check.sha256sum
|
190
|
+
raise DownloadError, 'The sha256sum does not match, retry the download'
|
191
|
+
end
|
184
192
|
end
|
185
193
|
|
186
194
|
protected
|
187
|
-
|
188
195
|
def pause(secs)
|
189
196
|
@paused = true
|
190
197
|
|
data/lib/vpsadmin/cli.rb
CHANGED
@@ -3,11 +3,11 @@ require 'vpsadmin/client/version'
|
|
3
3
|
|
4
4
|
module VpsAdmin
|
5
5
|
module CLI
|
6
|
-
module Commands; end
|
6
|
+
module Commands ; end
|
7
7
|
|
8
8
|
class Cli < HaveAPI::CLI::Cli
|
9
9
|
def show_version
|
10
|
-
puts "#{VpsAdmin::Client::VERSION} based on haveapi-client "
|
10
|
+
puts "#{VpsAdmin::Client::VERSION} based on haveapi-client "+
|
11
11
|
HaveAPI::Client::VERSION
|
12
12
|
end
|
13
13
|
end
|
data/lib/vpsadmin/client.rb
CHANGED
@@ -3,11 +3,12 @@ require 'haveapi/client'
|
|
3
3
|
module VpsAdmin
|
4
4
|
module Client
|
5
5
|
class Client < HaveAPI::Client::Client
|
6
|
+
|
6
7
|
end
|
7
8
|
|
8
9
|
# Shortcut to {VpsAdmin::Client::Client.new}
|
9
|
-
def self.new(*)
|
10
|
-
Client.new(*)
|
10
|
+
def self.new(*args)
|
11
|
+
Client.new(*args)
|
11
12
|
end
|
12
13
|
end
|
13
14
|
end
|
data/shell.nix
CHANGED
@@ -5,12 +5,12 @@ let
|
|
5
5
|
in stdenv.mkDerivation rec {
|
6
6
|
name = "vpsadmin-client";
|
7
7
|
|
8
|
-
buildInputs =
|
9
|
-
|
10
|
-
git
|
11
|
-
zlib
|
12
|
-
openssl
|
13
|
-
ncurses
|
8
|
+
buildInputs = [
|
9
|
+
pkgs.ruby
|
10
|
+
pkgs.git
|
11
|
+
pkgs.zlib
|
12
|
+
pkgs.openssl
|
13
|
+
pkgs.ncurses
|
14
14
|
];
|
15
15
|
|
16
16
|
shellHook = ''
|
data/vpsadmin-client.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
4
|
require 'vpsadmin/client/version'
|
4
5
|
|
5
6
|
Gem::Specification.new do |spec|
|
@@ -8,17 +9,19 @@ Gem::Specification.new do |spec|
|
|
8
9
|
spec.authors = ['Jakub Skokan']
|
9
10
|
spec.email = ['jakub.skokan@vpsfree.cz']
|
10
11
|
spec.summary =
|
11
|
-
|
12
|
+
spec.description = 'Ruby API and CLI for vpsAdmin API'
|
12
13
|
spec.homepage = ''
|
13
14
|
spec.license = 'GPL'
|
14
15
|
|
15
|
-
spec.required_ruby_version = ">= #{File.read('../.ruby-version').strip}"
|
16
|
-
|
17
16
|
spec.files = `git ls-files -z`.split("\x0")
|
18
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
22
|
-
spec.
|
21
|
+
spec.add_development_dependency 'bundler'
|
22
|
+
spec.add_development_dependency 'rake'
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'haveapi-client', '~> 0.16.1'
|
23
25
|
spec.add_runtime_dependency 'json'
|
26
|
+
spec.add_runtime_dependency 'curses'
|
24
27
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vpsadmin-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.master.
|
4
|
+
version: 3.0.0.master.202211181.pre.0.ac358990
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jakub Skokan
|
@@ -11,13 +11,27 @@ cert_chain: []
|
|
11
11
|
date: 1980-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
type: :
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
@@ -30,14 +44,14 @@ dependencies:
|
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
47
|
+
version: 0.16.1
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
54
|
+
version: 0.16.1
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: json
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - ">="
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: curses
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description: Ruby API and CLI for vpsAdmin API
|
56
84
|
email:
|
57
85
|
- jakub.skokan@vpsfree.cz
|
@@ -67,7 +95,7 @@ files:
|
|
67
95
|
- README.md
|
68
96
|
- Rakefile
|
69
97
|
- bin/vpsadminctl
|
70
|
-
- lib/
|
98
|
+
- lib/terminal-size.rb
|
71
99
|
- lib/vpsadmin/cli.rb
|
72
100
|
- lib/vpsadmin/cli/commands/backup_dataset.rb
|
73
101
|
- lib/vpsadmin/cli/commands/backup_vps.rb
|
@@ -94,14 +122,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
122
|
requirements:
|
95
123
|
- - ">="
|
96
124
|
- !ruby/object:Gem::Version
|
97
|
-
version:
|
125
|
+
version: '0'
|
98
126
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
127
|
requirements:
|
100
|
-
- - "
|
128
|
+
- - ">"
|
101
129
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
130
|
+
version: 1.3.1
|
103
131
|
requirements: []
|
104
|
-
rubygems_version: 3.
|
132
|
+
rubygems_version: 3.2.26
|
105
133
|
signing_key:
|
106
134
|
specification_version: 4
|
107
135
|
summary: Ruby API and CLI for vpsAdmin API
|