mms-api 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/mms-api +19 -16
- data/lib/mms.rb +8 -1
- data/lib/mms/agent.rb +16 -70
- data/lib/mms/cache.rb +31 -0
- data/lib/mms/client.rb +110 -0
- data/lib/mms/resource.rb +41 -0
- data/lib/mms/resource/cluster.rb +74 -0
- data/lib/mms/resource/group.rb +49 -0
- data/lib/mms/resource/restore_job.rb +36 -0
- data/lib/mms/resource/snapshot.rb +32 -0
- data/lib/mms/version.rb +1 -1
- metadata +10 -4
- data/lib/mms/helper.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39a0d0fc86adfb6147e58bfac07066c584a94ae2
|
4
|
+
data.tar.gz: 12291221088f7da5d90156e2b020e02b100c2f51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b0e56c1eaa825b8675c9864d111cd7bef8b2ff7f5dad9d0e999c07bbe0534e575ca76a5d2634b5695c8a15b2de7b3cb724e34742f3c1146cc85b18e2b22d997
|
7
|
+
data.tar.gz: adfaf6a8ace795944c64f4aa48f15b7e0c4d84f028ef4f13f36f4e34a8607dd21fa150cff32ce282a364be7c595bcc80ef8a21900996ed00ff4672445b3fc134
|
data/bin/mms-api
CHANGED
@@ -10,7 +10,7 @@ require 'pp'
|
|
10
10
|
name = 'mms-api'
|
11
11
|
version = MMS::VERSION
|
12
12
|
|
13
|
-
actions_available = ["groups", "clusters", "snapshots", "restorejobs"]
|
13
|
+
actions_available = ["groups", "clusters", "snapshots", "restorejobs", "restorejobs-create"]
|
14
14
|
|
15
15
|
options = {}
|
16
16
|
optparse = OptionParser.new do |opts|
|
@@ -68,41 +68,44 @@ end
|
|
68
68
|
|
69
69
|
begin
|
70
70
|
agent = MMS::Agent.new(options[:username], options[:apikey])
|
71
|
-
|
71
|
+
ARGV.shift
|
72
|
+
results = agent.send action.sub('-', '_'), *ARGV
|
72
73
|
|
73
74
|
rows = []
|
74
75
|
case action
|
75
76
|
when 'groups'
|
76
77
|
heading = ['Name', 'Active Agents', 'Replicas count', 'Shards count', 'Last Active Agent']
|
77
78
|
results.each do |group|
|
78
|
-
rows << [group
|
79
|
+
rows << [group.name, group.active_agent_count, group.replicaset_count, group.shard_count, group.last_active_agent]
|
79
80
|
end
|
80
81
|
when 'clusters'
|
81
|
-
heading = ['
|
82
|
+
heading = ['Group', 'Cluster', 'Shard name', 'Replica name', 'Type', 'Last heartbeat']
|
82
83
|
results.each do |cluster|
|
83
|
-
rows << [cluster
|
84
|
+
rows << [cluster.group.name, cluster.name, cluster.shard_name, cluster.replicaset_name, cluster.type_name, cluster.last_heartbeat]
|
84
85
|
end
|
85
86
|
when 'snapshots'
|
86
|
-
heading = ['SnapshotId', 'Complete', 'Created increment', 'Created date', 'Expires']
|
87
|
-
results_sorted = results.sort_by { |
|
87
|
+
heading = ['Group', 'Cluster', 'SnapshotId', 'Complete', 'Created increment', 'Created date', 'Expires']
|
88
|
+
results_sorted = results.sort_by { |snapshot| snapshot.created_date }.reverse
|
88
89
|
results_sorted.first(options[:limit]).each do |snapshot|
|
89
|
-
rows << [snapshot
|
90
|
+
rows << [snapshot.cluster.group.name, snapshot.cluster.name, snapshot.id, snapshot.complete, snapshot.created_increment, snapshot.created_date, snapshot.expires]
|
90
91
|
rows << :separator
|
91
92
|
part_count = 0
|
92
|
-
snapshot
|
93
|
+
snapshot.parts.each do |part|
|
93
94
|
file_size_mb = part['fileSizeBytes'].to_i / (1024*1024)
|
94
|
-
rows << [
|
95
|
+
rows << [{:value => "part #{part_count}", :colspan => 4, :alignment => :right}, part['typeName'], part['replicaSetName'], "#{file_size_mb} MB"]
|
95
96
|
part_count += 1
|
96
97
|
end
|
97
98
|
rows << :separator
|
98
99
|
end
|
99
|
-
when 'restorejobs'
|
100
|
-
heading = ['RestoreId', 'SnapshotId', 'Created', 'Status', 'Point in time', 'Delivery', 'Restore status']
|
101
|
-
results_sorted = results.sort_by { |
|
102
|
-
results_sorted.first(options[:limit]).each do |
|
103
|
-
rows << [
|
100
|
+
when 'restorejobs', 'restorejobs-create'
|
101
|
+
heading = ['RestoreId', 'SnapshotId / Cluster / Group', 'Created', 'Status', 'Point in time', 'Delivery', 'Restore status']
|
102
|
+
results_sorted = results.sort_by { |job| job.created }.reverse
|
103
|
+
results_sorted.first(options[:limit]).each do |job|
|
104
|
+
rows << [job.id, job.snapshot_id, job.created, job.status_name, job.point_in_time, job.delivery_method_name, job.delivery_status_name]
|
105
|
+
rows << ['', "#{job.cluster.name} (#{job.cluster.id})", {:value => '', :colspan => 5}]
|
106
|
+
rows << ['', job.cluster.group.name, {:value => '', :colspan => 5}]
|
104
107
|
rows << [{:value => 'download url:', :colspan => 7}]
|
105
|
-
rows << [{:value =>
|
108
|
+
rows << [{:value => job.delivery_url, :colspan => 7}]
|
106
109
|
rows << :separator
|
107
110
|
end
|
108
111
|
end
|
data/lib/mms.rb
CHANGED
@@ -2,6 +2,13 @@ module MMS
|
|
2
2
|
require 'rubygems' # For ruby < 1.9
|
3
3
|
|
4
4
|
require 'mms/agent'
|
5
|
-
require 'mms/
|
5
|
+
require 'mms/client'
|
6
|
+
require 'mms/cache'
|
6
7
|
require 'mms/version'
|
8
|
+
require 'mms/resource'
|
9
|
+
|
10
|
+
require 'mms/resource/group'
|
11
|
+
require 'mms/resource/cluster'
|
12
|
+
require 'mms/resource/snapshot'
|
13
|
+
require 'mms/resource/restore_job'
|
7
14
|
end
|
data/lib/mms/agent.rb
CHANGED
@@ -2,87 +2,33 @@ module MMS
|
|
2
2
|
|
3
3
|
class Agent
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
attr_accessor :api_port
|
8
|
-
attr_accessor :api_path
|
9
|
-
attr_accessor :api_version
|
10
|
-
|
11
|
-
attr_accessor :username
|
12
|
-
attr_accessor :apikey
|
13
|
-
|
14
|
-
def initialize(username = nil, apikey = nil)
|
15
|
-
@api_protocol = 'https'
|
16
|
-
@api_host = 'mms.mongodb.com'
|
17
|
-
@api_port = '443'
|
18
|
-
@api_path = '/api/public'
|
19
|
-
@api_version = 'v1.0'
|
20
|
-
|
21
|
-
@username = username
|
22
|
-
@apikey = apikey
|
23
|
-
end
|
24
|
-
|
25
|
-
def get_url
|
26
|
-
[@api_protocol, '://', @api_host, ':', @api_port, @api_path, '/', @api_version].join.to_s
|
5
|
+
def initialize(username, apikey)
|
6
|
+
MMS::Client.instance.auth_setup(username, apikey)
|
27
7
|
end
|
28
8
|
|
29
9
|
def groups
|
30
|
-
MMS::
|
10
|
+
MMS::Resource::Group.load_list
|
31
11
|
end
|
32
12
|
|
33
|
-
def clusters
|
34
|
-
|
35
|
-
groups.each do |group|
|
36
|
-
group_list.push group['id']
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
results = []
|
41
|
-
group_list.each do |group|
|
42
|
-
output = MMS::Helper.get get_url + '/groups/' + group + '/clusters', @username, @apikey
|
43
|
-
results = results + output
|
44
|
-
end
|
45
|
-
|
46
|
-
results
|
13
|
+
def clusters
|
14
|
+
MMS::Resource::Group.get_clusters
|
47
15
|
end
|
48
16
|
|
49
|
-
def snapshots
|
50
|
-
|
51
|
-
clusters.each do |cluster|
|
52
|
-
cluster_list.push({
|
53
|
-
:id => cluster['id'],
|
54
|
-
:group_id => cluster['groupId']
|
55
|
-
})
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
results = []
|
60
|
-
cluster_list.each do |cluster|
|
61
|
-
output = MMS::Helper.get get_url + '/groups/' + cluster[:group_id] + '/clusters/' + cluster[:id] + '/snapshots' , @username, @apikey
|
62
|
-
results = results + output
|
63
|
-
end
|
64
|
-
|
65
|
-
results
|
17
|
+
def snapshots
|
18
|
+
MMS::Resource::Cluster.get_snapshots
|
66
19
|
end
|
67
20
|
|
68
|
-
def restorejobs
|
69
|
-
|
70
|
-
|
71
|
-
cluster_list.push({
|
72
|
-
:id => cluster['id'],
|
73
|
-
:group_id => cluster['groupId']
|
74
|
-
})
|
75
|
-
end
|
76
|
-
end
|
21
|
+
def restorejobs
|
22
|
+
MMS::Resource::Cluster.get_restore_jobs
|
23
|
+
end
|
77
24
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
25
|
+
def restorejobs_create(group_id, cluster_id, snapshot_id)
|
26
|
+
begin
|
27
|
+
cluster = MMS::Resource::Cluster.new cluster_id, group_id
|
28
|
+
cluster.create_restorejob_from_snapshot snapshot_id
|
29
|
+
rescue => e
|
30
|
+
raise "Cannot create restore job `#{e.message}`"
|
82
31
|
end
|
83
|
-
|
84
|
-
results
|
85
32
|
end
|
86
|
-
|
87
33
|
end
|
88
34
|
end
|
data/lib/mms/cache.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module MMS
|
4
|
+
|
5
|
+
class Cache
|
6
|
+
|
7
|
+
include Singleton
|
8
|
+
|
9
|
+
attr_accessor :storage
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@storage = Hash.new {|hash, key| hash[key] = nil }
|
13
|
+
end
|
14
|
+
|
15
|
+
def set(key, value)
|
16
|
+
@storage[key] = value
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(key)
|
20
|
+
@storage[key].nil? ? nil : @storage[key]
|
21
|
+
end
|
22
|
+
|
23
|
+
def delete(key)
|
24
|
+
@storage.delete key unless @storage[key].nil?
|
25
|
+
end
|
26
|
+
|
27
|
+
def storage
|
28
|
+
@storage
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/mms/client.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require "net/http"
|
3
|
+
require "uri"
|
4
|
+
require 'net/http/digest_auth'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module MMS
|
8
|
+
|
9
|
+
class Client
|
10
|
+
|
11
|
+
include Singleton
|
12
|
+
|
13
|
+
attr_accessor :username
|
14
|
+
attr_accessor :apikey
|
15
|
+
|
16
|
+
attr_accessor :api_protocol
|
17
|
+
attr_accessor :api_host
|
18
|
+
attr_accessor :api_port
|
19
|
+
attr_accessor :api_path
|
20
|
+
attr_accessor :api_version
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@username, @apikey = nil
|
24
|
+
|
25
|
+
@api_protocol = 'https'
|
26
|
+
@api_host = 'mms.mongodb.com'
|
27
|
+
@api_port = '443'
|
28
|
+
@api_path = '/api/public'
|
29
|
+
@api_version = 'v1.0'
|
30
|
+
end
|
31
|
+
|
32
|
+
def auth_setup(username, apikey)
|
33
|
+
@username = username
|
34
|
+
@apikey = apikey
|
35
|
+
end
|
36
|
+
|
37
|
+
def site
|
38
|
+
[@api_protocol, '://', @api_host, ':', @api_port, @api_path, '/', @api_version].join.to_s
|
39
|
+
end
|
40
|
+
|
41
|
+
def get(path)
|
42
|
+
_get site + path, @username, @apikey
|
43
|
+
end
|
44
|
+
|
45
|
+
def post(path, data)
|
46
|
+
_post site + path, data, @username, @apikey
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def _get(path, username, password)
|
52
|
+
|
53
|
+
digest_auth = Net::HTTP::DigestAuth.new
|
54
|
+
digest_auth.next_nonce
|
55
|
+
|
56
|
+
uri = URI.parse path
|
57
|
+
uri.user= CGI.escape(username)
|
58
|
+
uri.password= CGI.escape(password)
|
59
|
+
|
60
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
61
|
+
http.use_ssl = true
|
62
|
+
|
63
|
+
req = Net::HTTP::Get.new uri.request_uri
|
64
|
+
res = http.request req
|
65
|
+
|
66
|
+
auth = digest_auth.auth_header uri, res['WWW-Authenticate'], 'GET'
|
67
|
+
req = Net::HTTP::Get.new uri.request_uri
|
68
|
+
req.add_field 'Authorization', auth
|
69
|
+
|
70
|
+
response = http.request(req)
|
71
|
+
response_json = JSON.parse(response.body)
|
72
|
+
|
73
|
+
unless response_json['error'].nil?
|
74
|
+
response_json = nil
|
75
|
+
end
|
76
|
+
|
77
|
+
(response_json.nil? or response_json['results'].nil?) ? response_json : response_json['results']
|
78
|
+
end
|
79
|
+
|
80
|
+
def _post(path, data, username, password)
|
81
|
+
digest_auth = Net::HTTP::DigestAuth.new
|
82
|
+
digest_auth.next_nonce
|
83
|
+
|
84
|
+
uri = URI.parse path
|
85
|
+
uri.user= CGI.escape(username)
|
86
|
+
uri.password= CGI.escape(password)
|
87
|
+
|
88
|
+
http = Net::HTTP.new uri.host, uri.port
|
89
|
+
http.use_ssl = true
|
90
|
+
|
91
|
+
req = Net::HTTP::Post.new uri.request_uri, {'Content-Type' =>'application/json'}
|
92
|
+
res = http.request req
|
93
|
+
|
94
|
+
auth = digest_auth.auth_header uri, res['WWW-Authenticate'], 'POST'
|
95
|
+
req = Net::HTTP::Post.new uri.request_uri, {'Content-Type' =>'application/json'}
|
96
|
+
req.add_field 'Authorization', auth
|
97
|
+
req.body = data.to_json
|
98
|
+
|
99
|
+
response = http.request req
|
100
|
+
response_json = JSON.parse response.body
|
101
|
+
|
102
|
+
unless response_json['error'].nil?
|
103
|
+
response_json = nil
|
104
|
+
end
|
105
|
+
|
106
|
+
(response_json.nil? or response_json['results'].nil?) ? response_json : response_json['results']
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
end
|
data/lib/mms/resource.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module MMS
|
2
|
+
|
3
|
+
class Resource
|
4
|
+
|
5
|
+
attr_accessor :id
|
6
|
+
attr_accessor :data
|
7
|
+
|
8
|
+
def initialize(id, data = nil)
|
9
|
+
@id = id
|
10
|
+
@data = data
|
11
|
+
|
12
|
+
load
|
13
|
+
end
|
14
|
+
|
15
|
+
def from_hash(data)
|
16
|
+
unless data.nil?
|
17
|
+
@id = data['id']
|
18
|
+
_from_hash data
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def load
|
23
|
+
_data = MMS::Cache.instance.get "Class::#{self.class.name}:#{@id}"
|
24
|
+
|
25
|
+
if _data.nil? and @data.nil?
|
26
|
+
_data = _load(@id) unless @id.nil?
|
27
|
+
|
28
|
+
if _data.nil?
|
29
|
+
raise "Cannot load data for #{self.class.name}, id `#{@id}`"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
save _data || @data
|
34
|
+
end
|
35
|
+
|
36
|
+
def save(data)
|
37
|
+
from_hash data
|
38
|
+
MMS::Cache.instance.set "Class::#{self.class.name}:#{@id}", data
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module MMS
|
2
|
+
|
3
|
+
class Resource::Cluster < Resource
|
4
|
+
|
5
|
+
attr_accessor :name
|
6
|
+
attr_accessor :group
|
7
|
+
attr_accessor :shard_name
|
8
|
+
attr_accessor :replicaset_name
|
9
|
+
attr_accessor :type_name
|
10
|
+
attr_accessor :last_heartbeat
|
11
|
+
|
12
|
+
def initialize(id, group_id, data = nil)
|
13
|
+
@group = MMS::Resource::Group.new(group_id)
|
14
|
+
|
15
|
+
super id, data
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.get_snapshots
|
19
|
+
snapshot_list = []
|
20
|
+
MMS::Resource::Group.get_clusters.each do |cluster|
|
21
|
+
MMS::Client.instance.get('/groups/' + cluster.group.id + '/clusters/' + cluster.id + '/snapshots').each do |snapshot|
|
22
|
+
snapshot_list.push MMS::Resource::Snapshot.new(snapshot['id'], snapshot['clusterId'], snapshot['groupId'], snapshot)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
snapshot_list
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.get_restore_jobs
|
29
|
+
job_list = []
|
30
|
+
MMS::Resource::Group.get_clusters.each do |cluster|
|
31
|
+
MMS::Client.instance.get('/groups/' + cluster.group.id + '/clusters/' + cluster.id + '/restoreJobs').each do |job|
|
32
|
+
job_list.push MMS::Resource::RestoreJob.new(job['id'], job['clusterId'], job['groupId'], job)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
job_list
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_restorejob_from_snapshot(id)
|
39
|
+
data = {:snapshotId => id}
|
40
|
+
jobs = MMS::Client.instance.post '/groups/' + @group.id + '/clusters/' + @id + '/restoreJobs', data
|
41
|
+
|
42
|
+
if jobs.nil?
|
43
|
+
raise "Cannot create job from snapshot `#{id}`"
|
44
|
+
end
|
45
|
+
|
46
|
+
job_list = []
|
47
|
+
# work around due to bug in MMS API; cannot read restoreJob using provided info.
|
48
|
+
restore_jobs = MMS::Resource::Cluster.get_restore_jobs
|
49
|
+
jobs.each do |job|
|
50
|
+
_list = restore_jobs.select {|restorejob| restorejob.id == job['id'] }
|
51
|
+
_list.each do |restorejob|
|
52
|
+
begin
|
53
|
+
job_list.push MMS::Resource::RestoreJob.new(restorejob.id, restorejob.cluster.id, restorejob.cluster.group.id)
|
54
|
+
rescue => e
|
55
|
+
puts "load error #{e.message}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
job_list
|
60
|
+
end
|
61
|
+
|
62
|
+
def _load(id)
|
63
|
+
MMS::Client.instance.get('/groups/' + @group.id + '/clusters/' + id.to_s)
|
64
|
+
end
|
65
|
+
|
66
|
+
def _from_hash(data)
|
67
|
+
@name = data['clusterName']
|
68
|
+
@shard_name = data['shardName']
|
69
|
+
@replicaset_name = data['replicaSetName']
|
70
|
+
@type_name = data['typeName']
|
71
|
+
@last_heartbeat = data['lastHeartbeat']
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module MMS
|
2
|
+
|
3
|
+
class Resource::Group < Resource
|
4
|
+
|
5
|
+
attr_reader :name
|
6
|
+
attr_reader :active_agent_count
|
7
|
+
attr_reader :replicaset_count
|
8
|
+
attr_reader :shard_count
|
9
|
+
attr_reader :last_active_agent
|
10
|
+
|
11
|
+
def initialize(id, data = nil)
|
12
|
+
super id, data
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.get_clusters
|
16
|
+
cluster_list = []
|
17
|
+
load_list.each do |group|
|
18
|
+
MMS::Client.instance.get('/groups/' + group.id + '/clusters').each do |cluster|
|
19
|
+
cluster_list.push MMS::Resource::Cluster.new(cluster['id'], cluster['groupId'], cluster)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
cluster_list
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_cluster(id)
|
26
|
+
MMS::Resource::Cluster.new(id, self.id)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.load_list
|
30
|
+
group_list = []
|
31
|
+
MMS::Client.instance.get('/groups').each do |group|
|
32
|
+
group_list.push MMS::Resource::Group.new(group['id'], group)
|
33
|
+
end
|
34
|
+
group_list
|
35
|
+
end
|
36
|
+
|
37
|
+
def _load(id)
|
38
|
+
MMS::Client.instance.get('/groups/' + id.to_s)
|
39
|
+
end
|
40
|
+
|
41
|
+
def _from_hash(data)
|
42
|
+
@name = data['name']
|
43
|
+
@active_agent_count = data['activeAgentCount']
|
44
|
+
@replicaset_count = data['replicaSetCount']
|
45
|
+
@shard_count = data['shardCount']
|
46
|
+
@last_active_agent = data['lastActiveAgent']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module MMS
|
2
|
+
|
3
|
+
class Resource::RestoreJob < Resource
|
4
|
+
|
5
|
+
attr_accessor :name
|
6
|
+
attr_accessor :cluster
|
7
|
+
|
8
|
+
attr_accessor :snapshot_id
|
9
|
+
attr_accessor :created
|
10
|
+
attr_accessor :status_name
|
11
|
+
attr_accessor :point_in_time
|
12
|
+
attr_accessor :delivery_method_name
|
13
|
+
attr_accessor :delivery_status_name
|
14
|
+
attr_accessor :delivery_url
|
15
|
+
|
16
|
+
def initialize(id, cluster_id, group_id, data = nil)
|
17
|
+
@cluster = MMS::Resource::Cluster.new cluster_id, group_id
|
18
|
+
|
19
|
+
super id, data
|
20
|
+
end
|
21
|
+
|
22
|
+
def _load(id)
|
23
|
+
MMS::Client.instance.get('/groups/' + @cluster.group.id + '/clusters/' + @cluster.id + '/restoreJobs/' + id.to_s)
|
24
|
+
end
|
25
|
+
|
26
|
+
def _from_hash(data)
|
27
|
+
@snapshot_id = data['snapshotId']
|
28
|
+
@created = data['created']
|
29
|
+
@status_name = data['statusName']
|
30
|
+
@point_in_time = data['pointInTime']
|
31
|
+
@delivery_method_name = data['delivery']['methodName']
|
32
|
+
@delivery_status_name = data['delivery']['statusName']
|
33
|
+
@delivery_url = data['delivery']['url']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module MMS
|
2
|
+
|
3
|
+
class Resource::Snapshot < Resource
|
4
|
+
|
5
|
+
attr_accessor :name
|
6
|
+
attr_accessor :cluster
|
7
|
+
|
8
|
+
attr_accessor :complete
|
9
|
+
attr_accessor :created_date
|
10
|
+
attr_accessor :created_increment
|
11
|
+
attr_accessor :expires
|
12
|
+
attr_accessor :parts
|
13
|
+
|
14
|
+
def initialize(id, cluster_id, group_id, data = nil)
|
15
|
+
@cluster = MMS::Resource::Cluster.new cluster_id, group_id
|
16
|
+
|
17
|
+
super id, data
|
18
|
+
end
|
19
|
+
|
20
|
+
def _load(id)
|
21
|
+
MMS::Client.instance.get('/groups/' + @cluster.group.id + '/clusters/' + @cluster.id + '/snapshots/' + id.to_s)
|
22
|
+
end
|
23
|
+
|
24
|
+
def _from_hash(data)
|
25
|
+
@complete = data['complete']
|
26
|
+
@created_date = data['created']['date']
|
27
|
+
@created_increment = data['created']['increment']
|
28
|
+
@expires = data['expires']
|
29
|
+
@parts = data['parts']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/mms/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mms-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cargo Media
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-08-
|
13
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: net-http-digest_auth
|
@@ -68,7 +68,7 @@ dependencies:
|
|
68
68
|
- - "~>"
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '2.0'
|
71
|
-
description: Agent
|
71
|
+
description: Agent for MMS API
|
72
72
|
email: hello@cargomedia.ch
|
73
73
|
executables:
|
74
74
|
- mms-api
|
@@ -80,7 +80,13 @@ files:
|
|
80
80
|
- bin/mms-api
|
81
81
|
- lib/mms.rb
|
82
82
|
- lib/mms/agent.rb
|
83
|
-
- lib/mms/
|
83
|
+
- lib/mms/cache.rb
|
84
|
+
- lib/mms/client.rb
|
85
|
+
- lib/mms/resource.rb
|
86
|
+
- lib/mms/resource/cluster.rb
|
87
|
+
- lib/mms/resource/group.rb
|
88
|
+
- lib/mms/resource/restore_job.rb
|
89
|
+
- lib/mms/resource/snapshot.rb
|
84
90
|
- lib/mms/version.rb
|
85
91
|
homepage: https://github.com/cargomedia/mms
|
86
92
|
licenses:
|
data/lib/mms/helper.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require "net/http"
|
2
|
-
require "uri"
|
3
|
-
require 'net/http/digest_auth'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
module MMS
|
7
|
-
|
8
|
-
class Helper
|
9
|
-
|
10
|
-
def self.get(path, username, password)
|
11
|
-
|
12
|
-
digest_auth = Net::HTTP::DigestAuth.new
|
13
|
-
digest_auth.next_nonce
|
14
|
-
|
15
|
-
uri = URI.parse path
|
16
|
-
uri.user= CGI.escape(username)
|
17
|
-
uri.password= CGI.escape(password)
|
18
|
-
|
19
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
20
|
-
http.use_ssl = true
|
21
|
-
|
22
|
-
req = Net::HTTP::Get.new uri.request_uri
|
23
|
-
res = http.request req
|
24
|
-
|
25
|
-
auth = digest_auth.auth_header uri, res['WWW-Authenticate'], 'GET'
|
26
|
-
req = Net::HTTP::Get.new uri.request_uri
|
27
|
-
req.add_field 'Authorization', auth
|
28
|
-
|
29
|
-
response = http.request(req)
|
30
|
-
response_json = JSON.parse(response.body)
|
31
|
-
|
32
|
-
if response_json['results'].nil?
|
33
|
-
fail("Error during API request!")
|
34
|
-
end
|
35
|
-
|
36
|
-
response_json['results']
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|