ultravault 1.0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -0
- data/Gemfile +2 -0
- data/README.md +88 -0
- data/Rakefile +17 -0
- data/lib/ultravault.rb +17 -0
- data/lib/ultravault/api_request.rb +26 -0
- data/lib/ultravault/client.rb +19 -0
- data/lib/ultravault/config.rb +55 -0
- data/lib/ultravault/data_objects/agent.rb +104 -0
- data/lib/ultravault/data_objects/disk_safe.rb +64 -0
- data/lib/ultravault/data_objects/recovery_point.rb +24 -0
- data/lib/ultravault/soap_service.rb +29 -0
- data/lib/ultravault/soap_service/agent_service.rb +62 -0
- data/lib/ultravault/soap_service/disk_safe_service.rb +18 -0
- data/lib/ultravault/soap_service/recovery_point_service.rb +21 -0
- data/test/all.rb +6 -0
- data/test/integration/client_code.rb +88 -0
- data/test/support/fixtures.rb +4 -0
- data/test/support/fixtures/agent_service.rb +56 -0
- data/test/support/fixtures/disk_safe.rb +35 -0
- data/test/support/fixtures/disk_safe_service.rb +60 -0
- data/test/support/fixtures/recovery_point_service.rb +26 -0
- data/test/test_helper.rb +35 -0
- data/test/unit/lib/ultravault/data_objects/test_agent.rb +133 -0
- data/test/unit/lib/ultravault/data_objects/test_disk_safe.rb +150 -0
- data/test/unit/lib/ultravault/data_objects/test_recovery_point.rb +59 -0
- data/test/unit/lib/ultravault/soap_service/test_agent_service.rb +139 -0
- data/test/unit/lib/ultravault/soap_service/test_disk_safe_service.rb +40 -0
- data/test/unit/lib/ultravault/soap_service/test_recovery_point_service.rb +39 -0
- data/test/unit/lib/ultravault/test_api_request.rb +36 -0
- data/test/unit/lib/ultravault/test_client.rb +47 -0
- data/test/unit/lib/ultravault/test_config.rb +37 -0
- data/test/unit/lib/ultravault/test_soap_service.rb +41 -0
- data/test/vcr_cassettes/agent_by_id.yml +41 -0
- data/test/vcr_cassettes/all_agents.yml +118 -0
- data/test/vcr_cassettes/create_mod_rm_agents.yml +158 -0
- data/ultravault.gemspec +25 -0
- metadata +212 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
module UltraVault
|
2
|
+
|
3
|
+
# @private
|
4
|
+
class SoapService
|
5
|
+
attr_reader :client
|
6
|
+
|
7
|
+
def initialize(service)
|
8
|
+
api_request = UltraVault::ApiRequest.new( host: UltraVault.config.host,
|
9
|
+
port: UltraVault.config.port,
|
10
|
+
service: service,
|
11
|
+
api_verison: UltraVault.config.api_version,
|
12
|
+
ssl: UltraVault.config.ssl)
|
13
|
+
@client = UltraVault::Client.new( endpoint: api_request.endpoint,
|
14
|
+
namespace: api_request.namespace,
|
15
|
+
username: UltraVault.config.username,
|
16
|
+
password: UltraVault.config.password)
|
17
|
+
end
|
18
|
+
|
19
|
+
def extract_params(response_hash, type)
|
20
|
+
return response_hash[type][:return] if response_hash[type]
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def extract_params_array(response_hash, type)
|
25
|
+
[extract_params(response_hash,type)].flatten.compact
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module UltraVault
|
2
|
+
# @private
|
3
|
+
class AgentService < UltraVault::SoapService
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
super(:Agent)
|
7
|
+
end
|
8
|
+
|
9
|
+
def find_agent_by_id(agent_id)
|
10
|
+
response_hash = client.request(:getAgentByID, :id => agent_id).to_hash
|
11
|
+
params = extract_params(response_hash, :get_agent_by_id_response)
|
12
|
+
UltraVault::Agent.new(params)
|
13
|
+
end
|
14
|
+
|
15
|
+
def all_agents
|
16
|
+
response_hash = client.request(:getAgents).to_hash
|
17
|
+
params = extract_params_array(response_hash, :get_agents_response)
|
18
|
+
params.collect do |agent|
|
19
|
+
UltraVault::Agent.new(agent)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_agent(params)
|
24
|
+
response_hash = client.request(:createAgentWithObject,
|
25
|
+
:agent => map_agent_params(params)).to_hash
|
26
|
+
params = extract_params(response_hash,
|
27
|
+
:create_agent_with_object_response)
|
28
|
+
UltraVault::Agent.new(params)
|
29
|
+
end
|
30
|
+
|
31
|
+
def update_agent(params)
|
32
|
+
client.request(:updateAgent,
|
33
|
+
:agent => map_agent_params(params)).to_hash
|
34
|
+
UltraVault::Agent.new(params)
|
35
|
+
end
|
36
|
+
|
37
|
+
def destroy_agent(id)
|
38
|
+
client.request(:deleteAgentById, id: id)
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def map_agent_params(params)
|
45
|
+
mapped_params = {}
|
46
|
+
params.keys.each do |key|
|
47
|
+
case key
|
48
|
+
when :port_number
|
49
|
+
mapped_params[:portNumber] = params[key]
|
50
|
+
when :os_type
|
51
|
+
mapped_params[:osType] = params[key]
|
52
|
+
else
|
53
|
+
mapped_params[key] = params[key]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
mapped_params
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module UltraVault
|
2
|
+
# @private
|
3
|
+
class DiskSafeService < UltraVault::SoapService
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
super(:DiskSafe)
|
7
|
+
end
|
8
|
+
|
9
|
+
def find_disksafes_by_agent_id(agent_id)
|
10
|
+
response_hash = client.request(:getDiskSafesForAgent, :agent => {:id => agent_id }).to_hash
|
11
|
+
params = extract_params_array(response_hash,
|
12
|
+
:get_disk_safes_for_agent_response)
|
13
|
+
params.collect do |disk_safe|
|
14
|
+
UltraVault::DiskSafe.new(disk_safe)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module UltraVault
|
2
|
+
# @private
|
3
|
+
class RecoveryPointService < UltraVault::SoapService
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
super(:RecoveryPoints)
|
7
|
+
end
|
8
|
+
|
9
|
+
def find_recovery_points_by_disk_safe_id(disk_safe_id)
|
10
|
+
response_hash = client.request(:getRecoveryPoints,
|
11
|
+
:diskSafe => {:id => disk_safe_id },
|
12
|
+
:includeMerged => false).to_hash
|
13
|
+
params = extract_params_array(response_hash,
|
14
|
+
:get_recovery_points_response)
|
15
|
+
params.collect do |recovery_point|
|
16
|
+
UltraVault::RecoveryPoint.new(recovery_point)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/test/all.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
require_relative '../../lib/ultravault'
|
3
|
+
require 'vcr'
|
4
|
+
|
5
|
+
VCR.configure do |c|
|
6
|
+
c.cassette_library_dir = "#{File.dirname(__FILE__)}/../vcr_cassettes"
|
7
|
+
c.hook_into :webmock # or :fakeweb
|
8
|
+
end
|
9
|
+
|
10
|
+
class ClientCodeTest < Test::Unit::TestCase
|
11
|
+
|
12
|
+
context "typical usage" do
|
13
|
+
|
14
|
+
should "retrieve agents, disksafes and recovery points" do
|
15
|
+
VCR.use_cassette('all_agents') do
|
16
|
+
|
17
|
+
# Set up the service
|
18
|
+
UltraVault.configure do |config|
|
19
|
+
config.host = 'foo.bar.baz'
|
20
|
+
config.port = 9080
|
21
|
+
config.api_version = 1
|
22
|
+
config.ssl = false
|
23
|
+
config.username = 'foo'
|
24
|
+
config.password = 'bar'
|
25
|
+
config.debug = false
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get all agents
|
29
|
+
agents = UltraVault::Agent.all
|
30
|
+
assert agents.count > 0
|
31
|
+
|
32
|
+
# Check disksafes
|
33
|
+
agent = agents.first
|
34
|
+
assert agent.disk_safes.count > 0
|
35
|
+
|
36
|
+
# Check recovery points
|
37
|
+
disk_safe = agent.disk_safes.first
|
38
|
+
assert disk_safe.recovery_points.count > 0
|
39
|
+
end
|
40
|
+
|
41
|
+
VCR.use_cassette('agent_by_id') do
|
42
|
+
# Get an agent
|
43
|
+
agent = UltraVault::Agent.find_by_id("157b9915-0ec8-45cd-a04f-aeea13f48c8e")
|
44
|
+
assert_not_nil agent
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
should "create, modify and delete agents" do
|
49
|
+
VCR.use_cassette('create_mod_rm_agents') do
|
50
|
+
|
51
|
+
# Set up the service
|
52
|
+
UltraVault.configure do |config|
|
53
|
+
config.host = 'foo.bar.baz'
|
54
|
+
config.port = 9080
|
55
|
+
config.api_version = 1
|
56
|
+
config.ssl = false
|
57
|
+
config.username = 'foo'
|
58
|
+
config.password = 'bar'
|
59
|
+
config.debug = false
|
60
|
+
end
|
61
|
+
|
62
|
+
# Create new agent
|
63
|
+
agent = UltraVault::Agent.create(
|
64
|
+
:hostname => 'foobar.com', :port_number => 9080,
|
65
|
+
:description => 'foobarbazbar',
|
66
|
+
:os_type => 'linux'
|
67
|
+
)
|
68
|
+
|
69
|
+
assert_not_nil agent
|
70
|
+
|
71
|
+
agent_id = agent.id
|
72
|
+
agent_old_host = agent.hostname
|
73
|
+
|
74
|
+
# Update an agent's properties
|
75
|
+
agent.update(:hostname => 'bazbar')
|
76
|
+
assert_not_equal agent_old_host, agent.host
|
77
|
+
|
78
|
+
# Delete an agent
|
79
|
+
agent.destroy
|
80
|
+
|
81
|
+
# Prove it's gone
|
82
|
+
assert_raise Savon::SOAP::Fault do
|
83
|
+
agent = UltraVault::Agent.find_by_id(agent_id)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module UltraVault
|
2
|
+
module Fixtures
|
3
|
+
def load_agent_service_fixtures
|
4
|
+
@agent_by_id = { :database_add_on_enabled=>false,
|
5
|
+
:description=>"test-MSSQL",
|
6
|
+
:hostname=>"1.2.3.4",
|
7
|
+
:id=>"e9bd701b-dac1-4921-ab1c-467f35209e21",
|
8
|
+
:os_type=>"WINDOWS", :port_number=>"1167"
|
9
|
+
}
|
10
|
+
|
11
|
+
@agent_by_id_wrapper = {
|
12
|
+
:get_agent_by_id_response=>
|
13
|
+
{
|
14
|
+
:return=> @agent_by_id,
|
15
|
+
:"@xmlns:ns1"=>"http://agent.api.server.backup.r1soft.com/"
|
16
|
+
}
|
17
|
+
}
|
18
|
+
@update_agent_wrapper = {
|
19
|
+
:update_agent_response=>
|
20
|
+
{
|
21
|
+
:return=> @agent_by_id,
|
22
|
+
:"@xmlns:ns1"=>"http://agent.api.server.backup.r1soft.com/"
|
23
|
+
}
|
24
|
+
}
|
25
|
+
@agent_with_object_wrapper = {
|
26
|
+
:create_agent_with_object_response=>
|
27
|
+
{
|
28
|
+
:return=> @agent_by_id,
|
29
|
+
:"@xmlns:ns1"=>"http://agent.api.server.backup.r1soft.com/"
|
30
|
+
}
|
31
|
+
}
|
32
|
+
@all_agents = [
|
33
|
+
{ :database_add_on_enabled=>false,
|
34
|
+
:description=>"test-MSSQL",
|
35
|
+
:hostname=>"1.2.3.4",
|
36
|
+
:id=>"e9bd701b-dac1-4921-ab1c-467f35209e21",
|
37
|
+
:os_type=>"WINDOWS", :port_number=>"1167"
|
38
|
+
},
|
39
|
+
{ :database_add_on_enabled=>false,
|
40
|
+
:description=>"test-MSSQL2",
|
41
|
+
:hostname=>"2.3.4.5",
|
42
|
+
:id=>"b107db9e-dac1-4921-ab1d-12e90253f764support",
|
43
|
+
:os_type=>"LINUX", :port_number=>"1168"
|
44
|
+
}
|
45
|
+
]
|
46
|
+
|
47
|
+
@all_agents_wrapper = {
|
48
|
+
:get_agents_response=>
|
49
|
+
{
|
50
|
+
:return=> @all_agents,
|
51
|
+
:"@xmlns:ns1"=>"http://agent.api.server.backup.r1soft.com/"
|
52
|
+
}
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module UltraVault
|
2
|
+
module Fixtures
|
3
|
+
def load_disk_safe_fixtures
|
4
|
+
@disk_safe_params = {:agent_id=>"e9bd701b-dac1-4921-ab1c-467f35209e21",
|
5
|
+
:compression_level=>"LOW",
|
6
|
+
:compression_type=>"QUICKLZ",
|
7
|
+
:description=>"test-MSSQL",
|
8
|
+
:device_count=>"2",
|
9
|
+
:device_list=>{
|
10
|
+
:capacity=>"64421359616",
|
11
|
+
:device_content_type=>"NTFS",
|
12
|
+
:device_path=>"\\\\?\\Volume{1b1cac04-b25f-11e0-bc49-806e6f6e6963}",
|
13
|
+
:enabled=>true,
|
14
|
+
:mount_point=>"C:\\",
|
15
|
+
:mounted=>true},
|
16
|
+
:disk_safe_attribute_map=>{:entry=>
|
17
|
+
[{:key=>"ARCHIVING_ENABLED", :value=>true},
|
18
|
+
{:key=>"FILE_EXCLUDES_ENABLED", :value=>true},
|
19
|
+
{:key=>"QUOTA_TYPE", :value=>"NONE"},
|
20
|
+
{:key=>"CONTROLPANELS_ENABLED", :value=>true},
|
21
|
+
{:key=>"ARCHIVE_POINT_LIMIT", :value=>"-1"},
|
22
|
+
{:key=>"RECOVERY_POINT_LIMIT", :value=>"-1"},
|
23
|
+
{:key=>"SOFT_QUOTA_VALUE", :value=>"-1.0"},
|
24
|
+
{:key=>"REPLICATION_FREQUENCY_LIMIT", :value=>"NO_LIMIT"},
|
25
|
+
{:key=>"HARD_QUOTA_VALUE", :value=>"-1.0"}]
|
26
|
+
},
|
27
|
+
:id=>"3067f030-9814-4314-ae03-75933ac29e37",
|
28
|
+
:open=>true,
|
29
|
+
:recovery_point_count=>"2",
|
30
|
+
:size=>"20931331073",
|
31
|
+
:size_of_deltas_in_disk_safe=>"18665326744",
|
32
|
+
:volume_id=>"9b77052e-e1d3-4c51-a49a-51544fcb12e1"}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module UltraVault
|
2
|
+
module Fixtures
|
3
|
+
def load_disk_safe_service_fixtures
|
4
|
+
@disk_safes_by_agent_id = {
|
5
|
+
:agent_id=>"e9bd701b-dac1-4921-ab1c-467f35209e21",
|
6
|
+
:backup_partition_table=>true,
|
7
|
+
:backup_unmounted_devices=>true,
|
8
|
+
:bytes_on_disk=>"20931331073",
|
9
|
+
:compression_level=>"LOW",
|
10
|
+
:compression_type=>"QUICKLZ",
|
11
|
+
:deltas_in_disk_safe=>"6920703",
|
12
|
+
:description=>"test-MSSQL",
|
13
|
+
:device_backup_type=>"AUTO_ADD_DEVICES",
|
14
|
+
:device_count=>"2",
|
15
|
+
:device_list=>{
|
16
|
+
:allocated_blocks=>"7843190",
|
17
|
+
:block_size=>"4096",
|
18
|
+
:capacity=>"64421359616",
|
19
|
+
:content_id=>"0004AFF104AFE7BC",
|
20
|
+
:device_content_type=>"NTFS",
|
21
|
+
:device_path=>"\\\\?\\Volume{1b1cac04-b25f-11e0-bc49-806e6f6e6963}",
|
22
|
+
:enabled=>true,
|
23
|
+
:mount_point=>"C:\\",
|
24
|
+
:mounted=>true,
|
25
|
+
:total_blocks=>"15727871"
|
26
|
+
},
|
27
|
+
:disk_safe_attribute_map=>{
|
28
|
+
:entry=>[
|
29
|
+
{:key=>"ARCHIVING_ENABLED", :value=>true},
|
30
|
+
{:key=>"FILE_EXCLUDES_ENABLED", :value=>true},
|
31
|
+
{:key=>"QUOTA_TYPE", :value=>"NONE"},
|
32
|
+
{:key=>"CONTROLPANELS_ENABLED", :value=>true},
|
33
|
+
{:key=>"ARCHIVE_POINT_LIMIT", :value=>"-1"},
|
34
|
+
{:key=>"RECOVERY_POINT_LIMIT", :value=>"-1"},
|
35
|
+
{:key=>"SOFT_QUOTA_VALUE", :value=>"-1.0"},
|
36
|
+
{:key=>"REPLICATION_FREQUENCY_LIMIT", :value=>"NO_LIMIT"},
|
37
|
+
{:key=>"HARD_QUOTA_VALUE", :value=>"-1.0"}
|
38
|
+
]},
|
39
|
+
:id=>"3067f030-9814-4314-ae03-75933ac29e37",
|
40
|
+
:open=>true,
|
41
|
+
:path=>"/data/test-volume/3067f030-9814-4314-ae03-75933ac29e37",
|
42
|
+
:recovery_point_count=>"2",
|
43
|
+
:size=>"20931331073",
|
44
|
+
:size_of_deltas_in_disk_safe=>"18665326744",
|
45
|
+
:total_free_pages=>"0",
|
46
|
+
:total_free_pages_bytes=>"0",
|
47
|
+
:total_page_bytes=>"20924334080",
|
48
|
+
:total_page_count=>"638560",
|
49
|
+
:volume_id=>"9b77052e-e1d3-4c51-a49a-51544fcb12e1"
|
50
|
+
}
|
51
|
+
|
52
|
+
@disk_safes_by_agent_id_wrapper = {
|
53
|
+
:get_disk_safes_for_agent_response=>{
|
54
|
+
:return=> @disk_safes_by_agent_id,
|
55
|
+
:"@xmlns:ns1"=>"http://disksafe.api.server.backup.r1soft.com/"
|
56
|
+
}
|
57
|
+
}
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module UltraVault
|
2
|
+
module Fixtures
|
3
|
+
def load_recovery_point_service_fixtures
|
4
|
+
@recovery_points_by_disk_safe_id = [
|
5
|
+
{:agent_id=>"e9bd701b-dac1-4921-ab1c-467f35209e21",
|
6
|
+
:created_on_timestamp_in_millis=>"1330361712361",
|
7
|
+
:disk_safe_id=>"3067f030-9814-4314-ae03-75933ac29e37",
|
8
|
+
:recovery_point_id=>"1",
|
9
|
+
:recovery_point_state=>"AVAILABLE"},
|
10
|
+
{:agent_id=>"e9bd701b-dac1-4921-ab1c-467f35209e21",
|
11
|
+
:created_on_timestamp_in_millis=>"1330427016495",
|
12
|
+
:disk_safe_id=>"3067f030-9814-4314-ae03-75933ac29e37",
|
13
|
+
:recovery_point_id=>"2",
|
14
|
+
:recovery_point_state=>"AVAILABLE"}
|
15
|
+
]
|
16
|
+
|
17
|
+
@recovery_points_by_disk_safe_id_wrapper = {
|
18
|
+
:get_recovery_points_response=>
|
19
|
+
{
|
20
|
+
:return=> @recovery_points_by_disk_safe_id,
|
21
|
+
:"@xmlns:ns1"=>"http://recoverypoints.api.server.backup.r1soft.com/"
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'test/unit'
|
5
|
+
require 'shoulda'
|
6
|
+
require 'mocha'
|
7
|
+
require 'webmock/test_unit'
|
8
|
+
require 'savon'
|
9
|
+
require 'ostruct'
|
10
|
+
|
11
|
+
include WebMock::API
|
12
|
+
|
13
|
+
require_relative '../lib/ultravault/api_request'
|
14
|
+
require_relative '../lib/ultravault/client'
|
15
|
+
require_relative '../lib/ultravault/config'
|
16
|
+
require_relative '../lib/ultravault/data_objects/agent'
|
17
|
+
require_relative '../lib/ultravault/data_objects/disk_safe'
|
18
|
+
require_relative '../lib/ultravault/data_objects/recovery_point'
|
19
|
+
require_relative '../lib/ultravault/soap_service'
|
20
|
+
require_relative '../lib/ultravault/soap_service/agent_service'
|
21
|
+
require_relative '../lib/ultravault/soap_service/disk_safe_service'
|
22
|
+
require_relative '../lib/ultravault/soap_service/recovery_point_service'
|
23
|
+
|
24
|
+
require_relative 'support/fixtures'
|
25
|
+
|
26
|
+
include UltraVault::Fixtures
|
27
|
+
|
28
|
+
UltraVault.configure do |config|
|
29
|
+
config.host = 'foo.bar.baz'
|
30
|
+
config.port = 9080
|
31
|
+
config.api_version = 1
|
32
|
+
config.ssl = false
|
33
|
+
config.username = 'foo'
|
34
|
+
config.password = 'bar'
|
35
|
+
end
|