mms-api 0.0.2 → 0.0.3

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: 39a0d0fc86adfb6147e58bfac07066c584a94ae2
4
- data.tar.gz: 12291221088f7da5d90156e2b020e02b100c2f51
3
+ metadata.gz: 10eb7918ba86096f3366a7e0a9b8ca3781dd38f8
4
+ data.tar.gz: daf1d6f4626bfa00ce6667d4359aa9d7c1c74140
5
5
  SHA512:
6
- metadata.gz: 7b0e56c1eaa825b8675c9864d111cd7bef8b2ff7f5dad9d0e999c07bbe0534e575ca76a5d2634b5695c8a15b2de7b3cb724e34742f3c1146cc85b18e2b22d997
7
- data.tar.gz: adfaf6a8ace795944c64f4aa48f15b7e0c4d84f028ef4f13f36f4e34a8607dd21fa150cff32ce282a364be7c595bcc80ef8a21900996ed00ff4672445b3fc134
6
+ metadata.gz: 1dd9fa0687862b3acc79f35e73af8134a1fed99ab34ff912890c557317eba6795e87756d73109d96ea754ed7434ccfe577e9076f4429ca25a5c1151f80d88adb
7
+ data.tar.gz: 25f0494ed23cefde64390d21f68e75be344c7aec859880db34c8ab1d4db16e60e7e153434388debc41e461e633798a8e4413422c6bfba13643dd50e3ef569cbc
data/bin/mms-api CHANGED
@@ -25,10 +25,15 @@ optparse = OptionParser.new do |opts|
25
25
  end
26
26
 
27
27
  options[:limit] = 5
28
- opts.on("-l", "--limit <string>", "Limit for result lines") do |l|
28
+ opts.on("-l", "--limit <string>", "Limit for result items") do |l|
29
29
  options[:limit] = l.to_i
30
30
  end
31
31
 
32
+ options[:page] = 1
33
+ opts.on("-p", "--page <string>", "Page number for listing") do |p|
34
+ options[:page] = p.to_i
35
+ end
36
+
32
37
  opts.on("-v", "--version", "Version") do |v|
33
38
  puts "#{name} v#{version}"
34
39
  exit
@@ -67,8 +72,11 @@ rescue => e
67
72
  end
68
73
 
69
74
  begin
70
- agent = MMS::Agent.new(options[:username], options[:apikey])
71
75
  ARGV.shift
76
+ ARGV.push options[:page]
77
+ ARGV.push options[:limit]
78
+
79
+ agent = MMS::Agent.new(options[:username], options[:apikey])
72
80
  results = agent.send action.sub('-', '_'), *ARGV
73
81
 
74
82
  rows = []
@@ -86,7 +94,7 @@ begin
86
94
  when 'snapshots'
87
95
  heading = ['Group', 'Cluster', 'SnapshotId', 'Complete', 'Created increment', 'Created date', 'Expires']
88
96
  results_sorted = results.sort_by { |snapshot| snapshot.created_date }.reverse
89
- results_sorted.first(options[:limit]).each do |snapshot|
97
+ results_sorted.each do |snapshot|
90
98
  rows << [snapshot.cluster.group.name, snapshot.cluster.name, snapshot.id, snapshot.complete, snapshot.created_increment, snapshot.created_date, snapshot.expires]
91
99
  rows << :separator
92
100
  part_count = 0
@@ -100,7 +108,7 @@ begin
100
108
  when 'restorejobs', 'restorejobs-create'
101
109
  heading = ['RestoreId', 'SnapshotId / Cluster / Group', 'Created', 'Status', 'Point in time', 'Delivery', 'Restore status']
102
110
  results_sorted = results.sort_by { |job| job.created }.reverse
103
- results_sorted.first(options[:limit]).each do |job|
111
+ results_sorted.each do |job|
104
112
  rows << [job.id, job.snapshot_id, job.created, job.status_name, job.point_in_time, job.delivery_method_name, job.delivery_status_name]
105
113
  rows << ['', "#{job.cluster.name} (#{job.cluster.id})", {:value => '', :colspan => 5}]
106
114
  rows << ['', job.cluster.group.name, {:value => '', :colspan => 5}]
@@ -115,5 +123,6 @@ begin
115
123
  puts table
116
124
 
117
125
  rescue => e
126
+ puts "Cannot create restore job `#{e.message}`"
118
127
  exit 1
119
128
  end
data/lib/mms/agent.rb CHANGED
@@ -14,21 +14,17 @@ module MMS
14
14
  MMS::Resource::Group.get_clusters
15
15
  end
16
16
 
17
- def snapshots
18
- MMS::Resource::Cluster.get_snapshots
17
+ def snapshots(page = 1, limit = 10)
18
+ MMS::Resource::Cluster.get_snapshots page, limit
19
19
  end
20
20
 
21
- def restorejobs
22
- MMS::Resource::Cluster.get_restore_jobs
21
+ def restorejobs(page = 1, limit = 10)
22
+ MMS::Resource::Cluster.get_restore_jobs page, limit
23
23
  end
24
24
 
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}`"
31
- end
25
+ def restorejobs_create(group_id, cluster_id, snapshot_id, page = 1, limit = 10)
26
+ cluster = MMS::Resource::Cluster.new cluster_id, group_id
27
+ cluster.create_restorejob_from_snapshot snapshot_id, page, limit
32
28
  end
33
29
  end
34
30
  end
@@ -15,27 +15,27 @@ module MMS
15
15
  super id, data
16
16
  end
17
17
 
18
- def self.get_snapshots
18
+ def self.get_snapshots(page = 1, limit = 10)
19
19
  snapshot_list = []
20
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|
21
+ MMS::Client.instance.get('/groups/' + cluster.group.id + '/clusters/' + cluster.id + '/snapshots?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |snapshot|
22
22
  snapshot_list.push MMS::Resource::Snapshot.new(snapshot['id'], snapshot['clusterId'], snapshot['groupId'], snapshot)
23
23
  end
24
24
  end
25
25
  snapshot_list
26
26
  end
27
27
 
28
- def self.get_restore_jobs
28
+ def self.get_restore_jobs(page = 1, limit = 10)
29
29
  job_list = []
30
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|
31
+ MMS::Client.instance.get('/groups/' + cluster.group.id + '/clusters/' + cluster.id + '/restoreJobs?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |job|
32
32
  job_list.push MMS::Resource::RestoreJob.new(job['id'], job['clusterId'], job['groupId'], job)
33
33
  end
34
34
  end
35
35
  job_list
36
36
  end
37
37
 
38
- def create_restorejob_from_snapshot(id)
38
+ def create_restorejob_from_snapshot(id, page = 1, limit = 10)
39
39
  data = {:snapshotId => id}
40
40
  jobs = MMS::Client.instance.post '/groups/' + @group.id + '/clusters/' + @id + '/restoreJobs', data
41
41
 
@@ -45,7 +45,7 @@ module MMS
45
45
 
46
46
  job_list = []
47
47
  # work around due to bug in MMS API; cannot read restoreJob using provided info.
48
- restore_jobs = MMS::Resource::Cluster.get_restore_jobs
48
+ restore_jobs = MMS::Resource::Cluster.get_restore_jobs page, limit
49
49
  jobs.each do |job|
50
50
  _list = restore_jobs.select {|restorejob| restorejob.id == job['id'] }
51
51
  _list.each do |restorejob|
data/lib/mms/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MMS
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
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.2
4
+ version: 0.0.3
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-26 00:00:00.000000000 Z
13
+ date: 2014-08-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: net-http-digest_auth
@@ -88,7 +88,7 @@ files:
88
88
  - lib/mms/resource/restore_job.rb
89
89
  - lib/mms/resource/snapshot.rb
90
90
  - lib/mms/version.rb
91
- homepage: https://github.com/cargomedia/mms
91
+ homepage: https://github.com/cargomedia/mms-api
92
92
  licenses:
93
93
  - MIT
94
94
  metadata: {}