crowbar-client 2.3.0 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +9 -0
  3. data/lib/crowbar/client/app/backup.rb +87 -21
  4. data/lib/crowbar/client/app/base.rb +20 -0
  5. data/lib/crowbar/client/app/batch.rb +44 -31
  6. data/lib/crowbar/client/app/host_ip.rb +2 -0
  7. data/lib/crowbar/client/app/interface.rb +2 -0
  8. data/lib/crowbar/client/app/virtual_ip.rb +2 -0
  9. data/lib/crowbar/client/command/backup.rb +3 -0
  10. data/lib/crowbar/client/command/backup/delete.rb +2 -0
  11. data/lib/crowbar/client/command/backup/download.rb +21 -14
  12. data/lib/crowbar/client/command/backup/list.rb +6 -3
  13. data/lib/crowbar/client/command/backup/restore.rb +42 -0
  14. data/lib/crowbar/client/command/backup/upload.rb +13 -0
  15. data/lib/crowbar/client/command/base.rb +3 -0
  16. data/lib/crowbar/client/command/batch/build.rb +26 -0
  17. data/lib/crowbar/client/command/batch/export.rb +43 -0
  18. data/lib/crowbar/client/command/installer/start.rb +2 -0
  19. data/lib/crowbar/client/filter/hash.rb +1 -1
  20. data/lib/crowbar/client/request/backup.rb +3 -0
  21. data/lib/crowbar/client/request/backup/create.rb +1 -3
  22. data/lib/crowbar/client/request/backup/delete.rb +1 -1
  23. data/lib/crowbar/client/request/backup/download.rb +1 -1
  24. data/lib/crowbar/client/request/backup/restore.rb +38 -0
  25. data/lib/crowbar/client/request/backup/upload.rb +0 -2
  26. data/lib/crowbar/client/request/batch/build.rb +17 -2
  27. data/lib/crowbar/client/request/batch/export.rb +22 -2
  28. data/lib/crowbar/client/version.rb +1 -1
  29. data/spec/crowbar/client/command/backup/create_spec.rb +1 -3
  30. data/spec/crowbar/client/command/backup/delete_spec.rb +1 -2
  31. data/spec/crowbar/client/command/backup/download_spec.rb +1 -1
  32. data/spec/crowbar/client/command/backup/restore_spec.rb +40 -0
  33. data/spec/crowbar/client/command/backup/upload_spec.rb +4 -1
  34. data/spec/crowbar/client/command/batch/build_spec.rb +5 -1
  35. data/spec/crowbar/client/request/backup/create_spec.rb +2 -4
  36. data/spec/crowbar/client/request/backup/delete_spec.rb +2 -2
  37. data/spec/crowbar/client/request/backup/download_spec.rb +2 -2
  38. data/spec/crowbar/client/request/backup/list_spec.rb +2 -4
  39. data/spec/crowbar/client/request/backup/restore_spec.rb +52 -0
  40. data/spec/crowbar/client/request/batch/build_spec.rb +35 -44
  41. data/spec/crowbar/client/request/batch/export_spec.rb +33 -44
  42. data/spec/crowbar/client/request/proposal/create_spec.rb +2 -1
  43. data/spec/crowbar/client/request/proposal/edit_spec.rb +2 -1
  44. data/spec/fixtures/batch.yml +0 -0
  45. metadata +11 -3
@@ -0,0 +1,42 @@
1
+ #
2
+ # Copyright 2015, SUSE Linux GmbH
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module Crowbar
18
+ module Client
19
+ module Command
20
+ module Backup
21
+ class Restore < Base
22
+ def request
23
+ @request ||= Request::Backup::Restore.new(
24
+ args
25
+ )
26
+ end
27
+
28
+ def execute
29
+ request.process do |request|
30
+ case request.code
31
+ when 200
32
+ say "Successfully triggered a restore"
33
+ else
34
+ err request.parsed_response["error"]
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -19,6 +19,19 @@ module Crowbar
19
19
  module Backup
20
20
  class Upload < Base
21
21
  def request
22
+ args.file =
23
+ case args.file
24
+ when "-"
25
+ stdin.to_io
26
+ when File
27
+ args.file
28
+ else
29
+ File.new(
30
+ args.file,
31
+ File::RDONLY
32
+ )
33
+ end
34
+
22
35
  @request ||= Request::Backup::Upload.new(
23
36
  args
24
37
  )
@@ -15,11 +15,14 @@
15
15
  #
16
16
 
17
17
  require "hashie"
18
+ require "active_support/number_helper"
18
19
 
19
20
  module Crowbar
20
21
  module Client
21
22
  module Command
22
23
  class Base
24
+ include ActiveSupport::NumberHelper
25
+
23
26
  attr_accessor :stdin
24
27
  attr_accessor :stdout
25
28
  attr_accessor :stderr
@@ -14,12 +14,32 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ require "easy_diff"
18
+
17
19
  module Crowbar
18
20
  module Client
19
21
  module Command
20
22
  module Batch
21
23
  class Build < Base
22
24
  def request
25
+ args.easy_merge!(
26
+ includes: options.includes,
27
+ excludes: options.excludes
28
+ )
29
+
30
+ args.file =
31
+ case args.file
32
+ when "-"
33
+ stdin.to_io
34
+ when File
35
+ args.file
36
+ else
37
+ File.new(
38
+ args.file,
39
+ File::RDONLY
40
+ )
41
+ end
42
+
23
43
  @request ||= Request::Batch::Build.new(
24
44
  args
25
45
  )
@@ -27,6 +47,12 @@ module Crowbar
27
47
 
28
48
  def execute
29
49
  request.process do |request|
50
+ case request.code
51
+ when 200
52
+ say "Successfully built batch"
53
+ else
54
+ err request.body
55
+ end
30
56
  end
31
57
  end
32
58
  end
@@ -14,12 +14,19 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ require "easy_diff"
18
+
17
19
  module Crowbar
18
20
  module Client
19
21
  module Command
20
22
  module Batch
21
23
  class Export < Base
22
24
  def request
25
+ args.easy_merge!(
26
+ includes: options.includes,
27
+ excludes: options.excludes
28
+ )
29
+
23
30
  @request ||= Request::Batch::Export.new(
24
31
  args
25
32
  )
@@ -27,8 +34,44 @@ module Crowbar
27
34
 
28
35
  def execute
29
36
  request.process do |request|
37
+ case request.code
38
+ when 200
39
+ if write(request.body)
40
+ say "Successfully exported batch"
41
+ else
42
+ err "Failed to export batch"
43
+ end
44
+ else
45
+ err request.parsed_response["error"]
46
+ end
30
47
  end
31
48
  end
49
+
50
+ protected
51
+
52
+ def write(body)
53
+ path.binmode
54
+ path.write body
55
+
56
+ true
57
+ rescue
58
+ false
59
+ end
60
+
61
+ def path
62
+ @path ||=
63
+ case args.file
64
+ when "-"
65
+ stdout.to_io
66
+ when File
67
+ args.file
68
+ else
69
+ File.new(
70
+ args.file,
71
+ File::CREAT | File::TRUNC | File::RDWR
72
+ )
73
+ end
74
+ end
32
75
  end
33
76
  end
34
77
  end
@@ -14,6 +14,8 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ require "easy_diff"
18
+
17
19
  module Crowbar
18
20
  module Client
19
21
  module Command
@@ -21,7 +21,7 @@ module Crowbar
21
21
  def process
22
22
  options[:values].select do |row|
23
23
  result = row.values.map do |value|
24
- value.include? options[:filter]
24
+ value.to_s.include? options[:filter]
25
25
  end
26
26
 
27
27
  result.include? true
@@ -30,6 +30,9 @@ module Crowbar
30
30
  autoload :List,
31
31
  File.expand_path("../backup/list", __FILE__)
32
32
 
33
+ autoload :Restore,
34
+ File.expand_path("../backup/restore", __FILE__)
35
+
33
36
  autoload :Upload,
34
37
  File.expand_path("../backup/upload", __FILE__)
35
38
  end
@@ -23,9 +23,7 @@ module Crowbar
23
23
  class Create < Base
24
24
  def content
25
25
  super.easy_merge!(
26
- backup: {
27
- name: attrs.backup
28
- }
26
+ name: attrs.name
29
27
  )
30
28
  end
31
29
 
@@ -27,7 +27,7 @@ module Crowbar
27
27
  [
28
28
  "utils",
29
29
  "backups",
30
- attrs.id
30
+ attrs.name
31
31
  ].join("/")
32
32
  end
33
33
  end
@@ -36,7 +36,7 @@ module Crowbar
36
36
  [
37
37
  "utils",
38
38
  "backups",
39
- attrs.id,
39
+ attrs.name,
40
40
  "download"
41
41
  ].join("/")
42
42
  end
@@ -0,0 +1,38 @@
1
+ #
2
+ # Copyright 2015, SUSE Linux GmbH
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ module Crowbar
18
+ module Client
19
+ module Request
20
+ module Backup
21
+ class Restore < Base
22
+ def method
23
+ :post
24
+ end
25
+
26
+ def url
27
+ [
28
+ "utils",
29
+ "backups",
30
+ attrs.name,
31
+ "restore"
32
+ ].join("/")
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -14,8 +14,6 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
- require "easy_diff"
18
-
19
17
  module Crowbar
20
18
  module Client
21
19
  module Request
@@ -19,12 +19,27 @@ module Crowbar
19
19
  module Request
20
20
  module Batch
21
21
  class Build < Base
22
+ def params
23
+ {
24
+ headers: headers,
25
+ query: {
26
+ includes: attrs.includes,
27
+ excludes: attrs.excludes,
28
+ file: attrs.file
29
+ }
30
+ }
31
+ end
32
+
22
33
  def method
23
- :get
34
+ :post
24
35
  end
25
36
 
26
37
  def url
27
- [].join("/")
38
+ [
39
+ "utils",
40
+ "batch",
41
+ "build"
42
+ ].join("/")
28
43
  end
29
44
  end
30
45
  end
@@ -14,17 +14,37 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ require "easy_diff"
18
+
17
19
  module Crowbar
18
20
  module Client
19
21
  module Request
20
22
  module Batch
21
23
  class Export < Base
24
+ def content
25
+ super.easy_merge!(
26
+ includes: attrs.includes,
27
+ excludes: attrs.excludes
28
+ )
29
+ end
30
+
31
+ def headers
32
+ super.easy_merge!(
33
+ "Content-Type" => "application/octet-stream",
34
+ "Accept" => "application/octet-stream"
35
+ )
36
+ end
37
+
22
38
  def method
23
- :get
39
+ :post
24
40
  end
25
41
 
26
42
  def url
27
- [].join("/")
43
+ [
44
+ "utils",
45
+ "batch",
46
+ "export"
47
+ ].join("/")
28
48
  end
29
49
  end
30
50
  end
@@ -18,7 +18,7 @@ module Crowbar
18
18
  module Client
19
19
  class Version
20
20
  MAJOR = 2
21
- MINOR = 3
21
+ MINOR = 4
22
22
  PATCH = 0
23
23
 
24
24
  PRE = nil
@@ -24,9 +24,7 @@ describe "Crowbar::Client::Command::Backup::Create" do
24
24
  stdin,
25
25
  stdout,
26
26
  stderr,
27
- backup: {
28
- name: "test-backup"
29
- }
27
+ name: "test-backup"
30
28
  )
31
29
  end
32
30
 
@@ -24,8 +24,7 @@ describe "Crowbar::Client::Command::Backup::Delete" do
24
24
  stdin,
25
25
  stdout,
26
26
  stderr,
27
- name: "test-backup",
28
- created_at: "20150303-170203"
27
+ name: "test-backup"
29
28
  )
30
29
  end
31
30
 
@@ -24,7 +24,7 @@ describe "Crowbar::Client::Command::Backup::Download" do
24
24
  stdin,
25
25
  stdout,
26
26
  stderr,
27
- id: 1
27
+ name: "foo"
28
28
  )
29
29
  end
30
30
 
@@ -0,0 +1,40 @@
1
+ #
2
+ # Copyright 2015, SUSE Linux GmbH
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require_relative "../../../../spec_helper"
18
+
19
+ describe "Crowbar::Client::Command::Backup::Restore" do
20
+ include_context "command_context"
21
+
22
+ subject do
23
+ ::Crowbar::Client::Command::Backup::Restore.new(
24
+ stdin,
25
+ stdout,
26
+ stderr,
27
+ name: "test-backup"
28
+ )
29
+ end
30
+
31
+ it "should always return a request class" do
32
+ expect(subject.request).to(
33
+ be_a(
34
+ ::Crowbar::Client::Request::Backup::Restore
35
+ )
36
+ )
37
+ end
38
+
39
+ pending
40
+ end