vpsadmin-client 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a714093237b2d1b08d20ad5b4d351b2315140b09
4
- data.tar.gz: 5b4f90ecb139558384731bd05738109cf96bb951
3
+ metadata.gz: 90de46caa07d6a1e3b79cc71f322d6b5deea4cc2
4
+ data.tar.gz: 95cd27f3867fe42945542f0965be82ff47e5d6d0
5
5
  SHA512:
6
- metadata.gz: 5ffe1e3fc9242a7715df2d138a9b5bc421c46bce5a9e6614961fd361bb8a120ac6d28666d484e99b3c225c5748e0d110f20555e2a72e459663d13ed5a906caea
7
- data.tar.gz: f86d5e0259515a3ce72eacf2f291c5c356010afb1d62e6fdb64d0bed17ee781c355d93558a4b6e289bbe619758ccb03623042a86244c0f06b93b5bed8b2faa1e
6
+ metadata.gz: daff91e634cf9b40cbd113423874a08feec9fd8b46dc0a64fa6c843ee4f0735b1ebab09607d3ffb3382a8c6053cdc169ee167503f7bcd5477721c75f53e68a42
7
+ data.tar.gz: d67762ed6357b3c3463c05253a500b8f50fcb7b76933a24844f9cd31ffdfad05805306b0545937b303df71e0fedf4a23f0ca00a93bdc1f92e4605f171cd61714
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ - New command vps migrate_many
2
+
1
3
  * Sat Jan 23 2016 - version 2.1.0
2
4
  - Renamed to vpsadmin-client
3
5
  - Rebased on HaveAPI v0.4
data/lib/vpsadmin/cli.rb CHANGED
@@ -11,3 +11,4 @@ module VpsAdmin
11
11
  end
12
12
 
13
13
  require 'vpsadmin/cli/commands/vps_remote_console'
14
+ require 'vpsadmin/cli/commands/vps_migrate_many'
@@ -0,0 +1,123 @@
1
+ module VpsAdmin::CLI::Commands
2
+ class VpsMigrateMany < HaveAPI::CLI::Command
3
+ cmd :vps, :migrate_many
4
+ args 'VPS_ID...'
5
+ desc 'Migrate multiple VPSes using a migration plan'
6
+
7
+ def options(opts)
8
+ @opts = {}
9
+
10
+ opts.on('--migration-plan PLAN_ID', 'Reuse existing migration plan') do |id|
11
+ @opts[:plan] = id
12
+ end
13
+
14
+ opts.on('--dst-node NODE_ID', 'Destination node') do |id|
15
+ @opts[:dst_node] = id.to_i
16
+ end
17
+
18
+ opts.on('--[no-]outage-window', 'Migrate VPSes inside outage windows') do |w|
19
+ @opts[:outage_window] = w
20
+ end
21
+
22
+ opts.on('--[no-]stop-on-error', 'Cancel the plan if a migration fails') do |s|
23
+ @opts[:stop_on_error] = s
24
+ end
25
+
26
+ opts.on('--concurrency N', 'How many migrations run concurrently') do |n|
27
+ @opts[:concurrency] = n.to_i
28
+ end
29
+
30
+ opts.on('--[no-]send-mail', 'Send users mail informing about the migration') do |s|
31
+ @opts[:send_mail] = s
32
+ end
33
+
34
+ opts.on('--reason REASON', 'Why are the VPS being migrated') do |r|
35
+ @opts[:reason] = r
36
+ end
37
+ end
38
+
39
+ def exec(args)
40
+ if args.size < 2
41
+ puts "provide at least two VPS IDs"
42
+ exit(false)
43
+
44
+ elsif @opts[:dst_node].nil?
45
+ puts "provide --dst-node"
46
+ exit(false)
47
+ end
48
+
49
+ puts "Verifying VPS IDs..."
50
+ vpses = []
51
+
52
+ args.each do |vps_id|
53
+ if /^\d+$/ !~ vps_id
54
+ puts "'#{vps_id}' is not a valid VPS ID"
55
+ exit(false)
56
+ end
57
+
58
+ vpses << vps_id.to_i
59
+ end
60
+
61
+ plan = nil
62
+
63
+ begin
64
+ if @opts[:plan]
65
+ puts "Reusing an existing migration plan..."
66
+ plan = @api.migration_plan.find(@opts[:plan])
67
+
68
+ if plan.state != 'staged'
69
+ puts "Cannot reuse a plan that has already left the staging phase"
70
+ exit(false)
71
+ end
72
+
73
+ else
74
+ puts "Creating a migration plan..."
75
+ plan = @api.migration_plan.create(@opts)
76
+ end
77
+
78
+ rescue HaveAPI::Client::ActionFailed => e
79
+ report_error(e)
80
+ end
81
+
82
+ puts "Scheduling VPS migrations..."
83
+ begin
84
+ vpses.each do |vps_id|
85
+ params = {
86
+ vps: vps_id,
87
+ dst_node: @opts[:dst_node],
88
+ }
89
+ params[:outage_window] = @opts[:outage_window] unless @opts[:outage_window].nil?
90
+
91
+ plan.vps_migration.create(params)
92
+ end
93
+
94
+ rescue HaveAPI::Client::ActionFailed => e
95
+ report_error(e)
96
+ end
97
+
98
+ puts "Executing the migration plan"
99
+ begin
100
+ ret = plan.start
101
+
102
+ rescue HaveAPI::Client::ActionFailed => e
103
+ report_error(e)
104
+ end
105
+
106
+ HaveAPI::CLI::OutputFormatter.print(ret.attributes)
107
+ end
108
+
109
+ protected
110
+ def report_error(e)
111
+ puts e.message
112
+
113
+ # FIXME: uncomment this code when ActionFailed makes response accessible
114
+ # if e.response.errors
115
+ # e.response.errors.each do |param, errs|
116
+ # puts " #{param}: #{errs.join('; ')}"
117
+ # end
118
+ # end
119
+
120
+ exit(false)
121
+ end
122
+ end
123
+ end
@@ -1,5 +1,5 @@
1
1
  module VpsAdmin
2
2
  module Client
3
- VERSION = '2.1.0'
3
+ VERSION = '2.2.0'
4
4
  end
5
5
  end
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency 'bundler', '~> 1.6'
22
22
  spec.add_development_dependency 'rake'
23
23
 
24
- spec.add_runtime_dependency 'haveapi-client', '~> 0.4.0'
24
+ spec.add_runtime_dependency 'haveapi-client', '~> 0.5.0'
25
25
  spec.add_runtime_dependency 'eventmachine', '~> 1.0.3'
26
26
  spec.add_runtime_dependency 'em-http-request', '~> 1.1.3'
27
27
  spec.add_runtime_dependency 'json', '~> 1.8.3'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vpsadmin-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakub Skokan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-23 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: 0.4.0
47
+ version: 0.5.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: 0.4.0
54
+ version: 0.5.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: eventmachine
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -111,6 +111,7 @@ files:
111
111
  - bin/vpsadminctl
112
112
  - lib/terminal-size.rb
113
113
  - lib/vpsadmin/cli.rb
114
+ - lib/vpsadmin/cli/commands/vps_migrate_many.rb
114
115
  - lib/vpsadmin/cli/commands/vps_remote_console.rb
115
116
  - lib/vpsadmin/client.rb
116
117
  - lib/vpsadmin/client/version.rb