ultravault 1.0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/.gitignore +15 -0
  2. data/Gemfile +2 -0
  3. data/README.md +88 -0
  4. data/Rakefile +17 -0
  5. data/lib/ultravault.rb +17 -0
  6. data/lib/ultravault/api_request.rb +26 -0
  7. data/lib/ultravault/client.rb +19 -0
  8. data/lib/ultravault/config.rb +55 -0
  9. data/lib/ultravault/data_objects/agent.rb +104 -0
  10. data/lib/ultravault/data_objects/disk_safe.rb +64 -0
  11. data/lib/ultravault/data_objects/recovery_point.rb +24 -0
  12. data/lib/ultravault/soap_service.rb +29 -0
  13. data/lib/ultravault/soap_service/agent_service.rb +62 -0
  14. data/lib/ultravault/soap_service/disk_safe_service.rb +18 -0
  15. data/lib/ultravault/soap_service/recovery_point_service.rb +21 -0
  16. data/test/all.rb +6 -0
  17. data/test/integration/client_code.rb +88 -0
  18. data/test/support/fixtures.rb +4 -0
  19. data/test/support/fixtures/agent_service.rb +56 -0
  20. data/test/support/fixtures/disk_safe.rb +35 -0
  21. data/test/support/fixtures/disk_safe_service.rb +60 -0
  22. data/test/support/fixtures/recovery_point_service.rb +26 -0
  23. data/test/test_helper.rb +35 -0
  24. data/test/unit/lib/ultravault/data_objects/test_agent.rb +133 -0
  25. data/test/unit/lib/ultravault/data_objects/test_disk_safe.rb +150 -0
  26. data/test/unit/lib/ultravault/data_objects/test_recovery_point.rb +59 -0
  27. data/test/unit/lib/ultravault/soap_service/test_agent_service.rb +139 -0
  28. data/test/unit/lib/ultravault/soap_service/test_disk_safe_service.rb +40 -0
  29. data/test/unit/lib/ultravault/soap_service/test_recovery_point_service.rb +39 -0
  30. data/test/unit/lib/ultravault/test_api_request.rb +36 -0
  31. data/test/unit/lib/ultravault/test_client.rb +47 -0
  32. data/test/unit/lib/ultravault/test_config.rb +37 -0
  33. data/test/unit/lib/ultravault/test_soap_service.rb +41 -0
  34. data/test/vcr_cassettes/agent_by_id.yml +41 -0
  35. data/test/vcr_cassettes/all_agents.yml +118 -0
  36. data/test/vcr_cassettes/create_mod_rm_agents.yml +158 -0
  37. data/ultravault.gemspec +25 -0
  38. metadata +212 -0
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ coverage/
2
+ doc/
3
+ Gemfile.lock
4
+ old/
5
+ pkg/
6
+ *.gem
7
+ *.rbc
8
+ .DS_Store
9
+ .bundle
10
+ .rvmrc
11
+ Gemfile.lock
12
+ .yardoc/checksums
13
+ .yardoc/objects/root.dat
14
+ .yardoc/proxy_types
15
+ .yardopts
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # UltraVault
2
+
3
+ A simple wrapper gem for the UltraVault API allowing users to retrieve information about their agents, disk safes and recovery points.
4
+
5
+ ## Installing with Bundler
6
+
7
+ Add this to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'ultravault', :git => "git@github.com:melbourne/ultravault.git", :branch => :master
11
+ ```
12
+
13
+ Run
14
+
15
+ $ bundle install
16
+
17
+ ## Intended usage
18
+
19
+ See test/integration/client_code.rb for an executable example.
20
+
21
+ ### Inclusion
22
+
23
+ ```ruby
24
+ require 'ultravault'
25
+ ```
26
+
27
+ ### Configure
28
+
29
+ ```ruby
30
+ UltraVault.configure do |config|
31
+ config.host = 'foo.bar.baz'
32
+ config.port = 9080
33
+ config.api_version = 1
34
+ config.ssl = false
35
+ config.username = 'foo'
36
+ config.password = 'bar'
37
+ config.debug = false
38
+ end
39
+ ```
40
+
41
+ or
42
+
43
+ ```ruby
44
+ UltraVault.config = { host: 'baz.bar.foo' }
45
+ ```
46
+
47
+ ### Retrieving data
48
+
49
+ ```ruby
50
+ # Retrieving an agent
51
+ agent = UltraVault::Agent.find_by_id("e9bd701b-dac1-4921-ab1c-467f35209e21")
52
+
53
+ # Retrieve all agents
54
+ agents = UltraVault::Agent.all
55
+
56
+ # Retrieving a disk safe
57
+ disk_safe = agent.disk_safes.first
58
+
59
+ # Retrieving recovery points
60
+ recovery_point = disk_safe.recovery_points.first
61
+ ```
62
+
63
+ ### Creating, editing, removing objects
64
+
65
+ ```ruby
66
+ # Creating an agent
67
+ agent = UltraVault::Agent.create(
68
+ :hostname => 'foo', :port_number => 1234,
69
+ :description => 'A new agent',
70
+ :os_type => 'linux'
71
+ )
72
+
73
+ # Updating an agent
74
+ updated_agent = agent.update(:hostname => 'bazbar')
75
+
76
+ # Deleting an agent
77
+ destroyed_agent = agent.destroy
78
+ ```
79
+
80
+ ## Authoring changes
81
+
82
+ ### Testing
83
+
84
+ Make sure you run the test suite in full before pushing changes. Write new tests as you add new features.
85
+
86
+ $ rake unit # run unit tests
87
+ $ rake integration # run integration tests
88
+
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new("unit") do |t|
7
+ t.libs << 'test'
8
+ t.pattern = "#{File.dirname(__FILE__)}/test/all.rb"
9
+ end
10
+
11
+ Rake::TestTask.new("integration") do |t|
12
+ t.libs << 'test'
13
+ t.pattern = "#{File.dirname(__FILE__)}/test/integration/client_code.rb"
14
+ end
15
+
16
+ desc "Run tests"
17
+ task :default => :unit
data/lib/ultravault.rb ADDED
@@ -0,0 +1,17 @@
1
+ module UltraVault
2
+
3
+ require 'savon'
4
+ require 'ostruct'
5
+ require_relative "ultravault/config"
6
+
7
+ autoload :Agent, "ultravault/data_objects/agent"
8
+ autoload :AgentService, "ultravault/soap_service/agent_service"
9
+ autoload :ApiRequest, "ultravault/api_request"
10
+ autoload :Client, "ultravault/client"
11
+ autoload :DiskSafe, "ultravault/data_objects/disk_safe"
12
+ autoload :DiskSafeService, "ultravault/soap_service/disk_safe_service"
13
+ autoload :RecoveryPoint, "ultravault/data_objects/recovery_point"
14
+ autoload :RecoveryPointService, "ultravault/soap_service/recovery_point_service"
15
+ autoload :SoapService, "ultravault/soap_service"
16
+
17
+ end
@@ -0,0 +1,26 @@
1
+ module UltraVault
2
+ # @private
3
+ class ApiRequest
4
+ def initialize(params)
5
+ @host = params[:host]
6
+ @port = params[:port]
7
+ @service = params[:service]
8
+ @ssl = params.fetch(:ssl) { true }
9
+ end
10
+
11
+ def endpoint
12
+ "#{protocol}://#{@host}:#{@port}/#{@service}"
13
+ end
14
+
15
+ def namespace
16
+ "http://#{@service.downcase}.api.server.backup.r1soft.com/"
17
+ end
18
+
19
+ private
20
+
21
+ def protocol
22
+ @ssl ? "https" : "http"
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,19 @@
1
+ module UltraVault
2
+ # @private
3
+ class Client
4
+ def initialize(params)
5
+
6
+ @client = Savon::Client.new do
7
+ wsdl.endpoint = params[:endpoint]
8
+ wsdl.namespace = params[:namespace]
9
+ http.auth.basic params[:username], params[:password]
10
+ end
11
+ end
12
+
13
+ def request(action, args={})
14
+ @client.request action, :body => args
15
+ end
16
+ end
17
+
18
+ end
19
+
@@ -0,0 +1,55 @@
1
+ module UltraVault
2
+ def self.configure
3
+ yield(config)
4
+ end
5
+
6
+ def self.config
7
+ @config ||= Config.new
8
+ end
9
+
10
+ def self.config=(hash)
11
+ self.config.update(hash)
12
+ end
13
+
14
+ private
15
+
16
+ class Config
17
+ attr_accessor :host, :port, :api_version,
18
+ :ssl, :username, :password,
19
+ :debug
20
+
21
+ def initialize(params={})
22
+ params = defaults.merge(params)
23
+ update(params)
24
+ end
25
+
26
+ def update(params)
27
+ params.each do |k,v|
28
+ instance_variable_set("@#{k}", v)
29
+ end
30
+ set_debug(@debug)
31
+ end
32
+
33
+ def debug=(state)
34
+ set_debug(state)
35
+ end
36
+
37
+ def set_debug(state)
38
+ Savon.configure do |config|
39
+ config.log = state
40
+ HTTPI.log = state
41
+ end
42
+ @debug = state
43
+ end
44
+
45
+ private
46
+
47
+ def defaults
48
+ {
49
+ host: '', port: 0, api_version: 1,
50
+ ssl: false, username: '', password:'',
51
+ debug: false
52
+ }
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,104 @@
1
+ module UltraVault
2
+ class Agent < OpenStruct
3
+ attr_reader :description, :hostname, :id, :os_type, :port_number
4
+
5
+ def initialize(params)
6
+ @description = params[:description]
7
+ @hostname = params[:hostname]
8
+ @id = params[:id]
9
+ @os_type = params[:os_type]
10
+ @port_number = params[:port_number]
11
+ super(params)
12
+ end
13
+
14
+ # Disksafes belonging to this agent.
15
+ #
16
+ # @return [[UltraVault::DiskSafe]] disk safes for this agent
17
+ # @raise [Savon::SOAP::Fault] errors from the soap transaction
18
+ def disk_safes
19
+ @disk_safes ||= UltraVault::DiskSafe.find_all_by_agent_id(id)
20
+ end
21
+
22
+ # Returns an agent, if found.
23
+ #
24
+ # @param [String] agent_id the UUID of the agent
25
+ # @return [UltraVault::Agent] the agent matching the agent_id
26
+ # @raise [Savon::SOAP::Fault] errors from the soap transaction
27
+ def self.find_by_id(agent_id)
28
+ UltraVault::AgentService.new.find_agent_by_id(agent_id)
29
+ end
30
+
31
+ # Returns all agents for the current user.
32
+ #
33
+ # @return [[UltraVault::Agent]] current user's agents
34
+ # @raise [Savon::SOAP::Fault] errors from the soap transaction
35
+ def self.all
36
+ UltraVault::AgentService.new.all_agents
37
+ end
38
+
39
+ # Returns a newly created agent with the given params.
40
+ #
41
+ # @return [UltraVault::Agent] new agent
42
+ # @raise [Savon::SOAP::Fault] errors from the soap transaction
43
+ def self.create(params)
44
+ Agent.check_params_strict(params)
45
+ UltraVault::AgentService.new.create_agent(params)
46
+ end
47
+
48
+ # Update the current agent
49
+ #
50
+ # @return [UltraVault::Agent] updated agent
51
+ # @raise [Savon::SOAP::Fault] errors from the soap transaction
52
+ def update(params)
53
+ Agent.check_params(params)
54
+ self.marshal_load(self.marshal_dump.merge(params))
55
+ UltraVault::AgentService.new.update_agent(self.marshal_dump)
56
+ end
57
+
58
+ # Destroy the current agent
59
+ # @ return [UltraVault::Agent] deleted agent
60
+ # @raise [Savon::SOAP::Fault] errors from the soap transaction
61
+ def destroy
62
+ UltraVault::AgentService.new.destroy_agent(self.id)
63
+ self
64
+ end
65
+
66
+ class << self
67
+
68
+ USAGE = "Valid arguments - :hostname, :port_number, :description, :os_type"
69
+ USE_ALL = "All arguments required."
70
+ REQUIRED_PARAMS = [:hostname, :port_number, :description, :os_type]
71
+
72
+ def check_params(params)
73
+ do_check_params(false, params)
74
+ end
75
+
76
+ def check_params_strict(params)
77
+ do_check_params(true, params)
78
+ end
79
+
80
+ def do_check_params(strict, params)
81
+ check_params_are_legal(params)
82
+ check_all_params_are_present(params) if strict
83
+ true
84
+ end
85
+
86
+ def check_params_are_legal(params)
87
+ params.keys.each do |key|
88
+ unless REQUIRED_PARAMS.include?(key)
89
+ raise ArgumentError.new(USAGE)
90
+ end
91
+ end
92
+ end
93
+
94
+ def check_all_params_are_present(params)
95
+ REQUIRED_PARAMS.each do |key|
96
+ unless params.keys.include?(key)
97
+ raise ArgumentError.new("#{USAGE}. #{USE_ALL}")
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+ end
104
+ end
@@ -0,0 +1,64 @@
1
+ module UltraVault
2
+ class DiskSafe < OpenStruct
3
+ attr_reader :agent_id, :compression_level, :compression_type,
4
+ :description, :device_count, :device_list,
5
+ :id, :open, :recovery_point_count,
6
+ :volume_id, :size, :size_of_deltas
7
+
8
+ def initialize(params)
9
+ @agent_id = params[:agent_id]
10
+ @compression_level = params[:compression_level]
11
+ @compression_type = params[:compression_type]
12
+ @description = params[:description]
13
+ @device_count = params[:device_count].to_i
14
+ @device_list = [params[:device_list]].flatten.collect do |device|
15
+ DeviceList.new(device)
16
+ end
17
+ @id = params[:id]
18
+ @open = params[:open]
19
+ @recovery_point_count = params[:recovery_point_count].to_i
20
+ @size = params[:size].to_i
21
+ @size_of_deltas = params[:size_of_deltas_in_disk_safe].to_i
22
+ @volume_id = params[:volume_id]
23
+ extract_attributes params[:disk_safe_attribute_map]
24
+ end
25
+
26
+ def recovery_points
27
+ @recovery_points ||= UltraVault::RecoveryPointService.new.find_recovery_points_by_disk_safe_id(id)
28
+ end
29
+
30
+ # Returns an array of disk safes, if found.
31
+ #
32
+ # @param [String] agent_id the UUID of the agent
33
+ # @return [[UltraVault::DiskSafe]] the matching disk safes for the agent
34
+ # @raise [Savon::SOAP::Fault] errors from the soap transaction
35
+ def self.find_all_by_agent_id(agent_id)
36
+ UltraVault::DiskSafeService.new.find_disksafes_by_agent_id agent_id
37
+ end
38
+
39
+ private
40
+
41
+ def extract_attributes(params)
42
+ params[:entry].each do |entry|
43
+ self.instance_variable_set "@#{entry[:key]}".downcase.to_sym, entry[:value]
44
+ self.class.send(:attr_reader, entry[:key].downcase.to_sym)
45
+ end
46
+ end
47
+
48
+ class DeviceList
49
+ attr_reader :content_type, :path, :enabled,
50
+ :mount_point, :mounted, :capacity
51
+
52
+ def initialize(params)
53
+ @capacity = params[:capacity].to_i
54
+ @content_type = params[:device_content_type]
55
+ @path = params[:device_path]
56
+ @enabled = params[:enabled]
57
+ @mount_point = params[:mount_point]
58
+ @mounted = params[:mounted]
59
+ end
60
+
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,24 @@
1
+ module UltraVault
2
+ class RecoveryPoint < OpenStruct
3
+ attr_reader :agent_id, :created_at, :disk_safe_id,
4
+ :id, :state
5
+
6
+ def initialize(params)
7
+ @agent_id = params[:agent_id]
8
+ @created_at = Time.at(params[:created_on_timestamp_in_millis].to_i / 1000.0)
9
+ @disk_safe_id = params[:disk_safe_id]
10
+ @id = params[:recovery_point_id]
11
+ @state = params[:recovery_point_state].downcase
12
+ end
13
+
14
+ # Returns an array of recovery points, if found.
15
+ #
16
+ # @param [String] disk_safe_id the UUID of the disk safe
17
+ # @return [[UltraVault::RecoveryPoint]] the matching recovery points for the agent
18
+ # @raise [Savon::SOAP::Fault] errors from the soap transaction
19
+ def self.find_all_by_disk_safe_id(disk_safe_id)
20
+ UltraVault::RecoveryPointService.new.find_recovery_points_by_disk_safe_id(disk_safe_id)
21
+ end
22
+
23
+ end
24
+ end