mms-api 0.0.3 → 0.0.4

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: 10eb7918ba86096f3366a7e0a9b8ca3781dd38f8
4
- data.tar.gz: daf1d6f4626bfa00ce6667d4359aa9d7c1c74140
3
+ metadata.gz: 30140add1019a1eeefbbad55e5cacd2589c76157
4
+ data.tar.gz: b79a0a425bd350be7a362a456f10c61a1f01e489
5
5
  SHA512:
6
- metadata.gz: 1dd9fa0687862b3acc79f35e73af8134a1fed99ab34ff912890c557317eba6795e87756d73109d96ea754ed7434ccfe577e9076f4429ca25a5c1151f80d88adb
7
- data.tar.gz: 25f0494ed23cefde64390d21f68e75be344c7aec859880db34c8ab1d4db16e60e7e153434388debc41e461e633798a8e4413422c6bfba13643dd50e3ef569cbc
6
+ metadata.gz: 69506c6a389147b341450ca1f86a276b6bc81ea8bf1282eec1dbf301c6c9e25e1a348fa52f703e12fb66d8b3a3f629e348311a7c08fe934e08127deaa3c711e9
7
+ data.tar.gz: ad0578f5dd4bb9e6b0902197b9e258906c6b4b64912a854dd5d7b88bdd2de41cf71804870371f49fd82281aebd0861b26071a7a15f52a7637456983f3af68628
@@ -24,16 +24,16 @@ optparse = OptionParser.new do |opts|
24
24
  options[:apikey] = k
25
25
  end
26
26
 
27
+ options[:name] = '.*'
28
+ opts.on("-n", "--name <string>", "Resource name using regexp") do |n|
29
+ options[:name] = n
30
+ end
31
+
27
32
  options[:limit] = 5
28
33
  opts.on("-l", "--limit <string>", "Limit for result items") do |l|
29
34
  options[:limit] = l.to_i
30
35
  end
31
36
 
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
-
37
37
  opts.on("-v", "--version", "Version") do |v|
38
38
  puts "#{name} v#{version}"
39
39
  exit
@@ -73,11 +73,10 @@ end
73
73
 
74
74
  begin
75
75
  ARGV.shift
76
- ARGV.push options[:page]
77
- ARGV.push options[:limit]
78
-
79
76
  agent = MMS::Agent.new(options[:username], options[:apikey])
77
+
80
78
  results = agent.send action.sub('-', '_'), *ARGV
79
+ results.select! { |resource| !resource.name.match(Regexp.new(options[:name])).nil? }
81
80
 
82
81
  rows = []
83
82
  case action
@@ -92,9 +91,9 @@ begin
92
91
  rows << [cluster.group.name, cluster.name, cluster.shard_name, cluster.replicaset_name, cluster.type_name, cluster.last_heartbeat]
93
92
  end
94
93
  when 'snapshots'
95
- heading = ['Group', 'Cluster', 'SnapshotId', 'Complete', 'Created increment', 'Created date', 'Expires']
94
+ heading = ['Group', 'Cluster', 'SnapshotId', 'Complete', 'Created increment', 'Created date (Name)', 'Expires']
96
95
  results_sorted = results.sort_by { |snapshot| snapshot.created_date }.reverse
97
- results_sorted.each do |snapshot|
96
+ results_sorted.first(options[:limit]).each do |snapshot|
98
97
  rows << [snapshot.cluster.group.name, snapshot.cluster.name, snapshot.id, snapshot.complete, snapshot.created_increment, snapshot.created_date, snapshot.expires]
99
98
  rows << :separator
100
99
  part_count = 0
@@ -106,9 +105,9 @@ begin
106
105
  rows << :separator
107
106
  end
108
107
  when 'restorejobs', 'restorejobs-create'
109
- heading = ['RestoreId', 'SnapshotId / Cluster / Group', 'Created', 'Status', 'Point in time', 'Delivery', 'Restore status']
108
+ heading = ['RestoreId', 'SnapshotId / Cluster / Group', 'Created (Name)', 'Status', 'Point in time', 'Delivery', 'Restore status']
110
109
  results_sorted = results.sort_by { |job| job.created }.reverse
111
- results_sorted.each do |job|
110
+ results_sorted.first(options[:limit]).each do |job|
112
111
  rows << [job.id, job.snapshot_id, job.created, job.status_name, job.point_in_time, job.delivery_method_name, job.delivery_status_name]
113
112
  rows << ['', "#{job.cluster.name} (#{job.cluster.id})", {:value => '', :colspan => 5}]
114
113
  rows << ['', job.cluster.group.name, {:value => '', :colspan => 5}]
@@ -123,6 +122,6 @@ begin
123
122
  puts table
124
123
 
125
124
  rescue => e
126
- puts "Cannot create restore job `#{e.message}`"
125
+ puts "Error: `#{e.message}`"
127
126
  exit 1
128
127
  end
@@ -7,24 +7,43 @@ module MMS
7
7
  end
8
8
 
9
9
  def groups
10
- MMS::Resource::Group.load_list
10
+ group_list = []
11
+ MMS::Client.instance.get('/groups').each do |group|
12
+ group_list.push MMS::Resource::Group.new group['id'], group
13
+ end
14
+ group_list
11
15
  end
12
16
 
13
17
  def clusters
14
- MMS::Resource::Group.get_clusters
18
+ cluster_list = []
19
+ groups.each do |group|
20
+ cluster_list.concat group.clusters
21
+ end
22
+ cluster_list
15
23
  end
16
24
 
17
- def snapshots(page = 1, limit = 10)
18
- MMS::Resource::Cluster.get_snapshots page, limit
25
+ def snapshots
26
+ snapshot_list = []
27
+ clusters.each do |cluster|
28
+ snapshot_list.concat cluster.snapshots
29
+ end
30
+ snapshot_list
19
31
  end
20
32
 
21
- def restorejobs(page = 1, limit = 10)
22
- MMS::Resource::Cluster.get_restore_jobs page, limit
33
+ def restorejobs
34
+ restorejob_list = []
35
+ clusters.each do |cluster|
36
+ restorejob_list.concat cluster.restorejobs
37
+ end
38
+ restorejob_list
23
39
  end
24
40
 
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
41
+ def restorejobs_create(group_id, cluster_id, snapshot_id)
42
+ findGroup(group_id).cluster(cluster_id).snapshot(snapshot_id).create_restorejob
43
+ end
44
+
45
+ def findGroup(id)
46
+ MMS::Resource::Group.new id
28
47
  end
29
48
  end
30
49
  end
@@ -15,52 +15,28 @@ module MMS
15
15
  super id, data
16
16
  end
17
17
 
18
- def self.get_snapshots(page = 1, limit = 10)
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?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).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
18
+ def snapshot(id)
19
+ MMS::Resource::Snapshot.new id, self.id, self.group.id
26
20
  end
27
21
 
28
- def self.get_restore_jobs(page = 1, limit = 10)
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?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |job|
32
- job_list.push MMS::Resource::RestoreJob.new(job['id'], job['clusterId'], job['groupId'], job)
33
- end
22
+ def snapshots(page = 1, limit = 1000)
23
+ snapshot_list = []
24
+ MMS::Client.instance.get('/groups/' + @group.id + '/clusters/' + @id + '/snapshots?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |snapshot|
25
+ snapshot_list.push MMS::Resource::Snapshot.new(snapshot['id'], snapshot['clusterId'], snapshot['groupId'], snapshot)
34
26
  end
35
- job_list
27
+ snapshot_list
36
28
  end
37
29
 
38
- def create_restorejob_from_snapshot(id, page = 1, limit = 10)
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
-
30
+ def restorejobs(page = 1, limit = 1000)
46
31
  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 page, limit
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
32
+ MMS::Client.instance.get('/groups/' + @group.id + '/clusters/' + @id + '/restoreJobs?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |job|
33
+ job_list.push MMS::Resource::RestoreJob.new(job['id'], job['clusterId'], job['groupId'], job)
58
34
  end
59
35
  job_list
60
36
  end
61
37
 
62
38
  def _load(id)
63
- MMS::Client.instance.get('/groups/' + @group.id + '/clusters/' + id.to_s)
39
+ MMS::Client.instance.get '/groups/' + @group.id + '/clusters/' + id.to_s
64
40
  end
65
41
 
66
42
  def _from_hash(data)
@@ -12,30 +12,20 @@ module MMS
12
12
  super id, data
13
13
  end
14
14
 
15
- def self.get_clusters
15
+ def clusters(page = 1, limit = 1000)
16
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
17
+ MMS::Client.instance.get('/groups/' + @id + '/clusters?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |cluster|
18
+ cluster_list.push MMS::Resource::Cluster.new(cluster['id'], cluster['groupId'], cluster)
21
19
  end
22
20
  cluster_list
23
21
  end
24
22
 
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
23
+ def cluster(id)
24
+ MMS::Resource::Cluster.new id, self.id
35
25
  end
36
26
 
37
27
  def _load(id)
38
- MMS::Client.instance.get('/groups/' + id.to_s)
28
+ MMS::Client.instance.get '/groups/' + id.to_s
39
29
  end
40
30
 
41
31
  def _from_hash(data)
@@ -20,7 +20,7 @@ module MMS
20
20
  end
21
21
 
22
22
  def _load(id)
23
- MMS::Client.instance.get('/groups/' + @cluster.group.id + '/clusters/' + @cluster.id + '/restoreJobs/' + id.to_s)
23
+ MMS::Client.instance.get '/groups/' + @cluster.group.id + '/clusters/' + @cluster.id + '/restoreJobs/' + id.to_s
24
24
  end
25
25
 
26
26
  def _from_hash(data)
@@ -31,6 +31,7 @@ module MMS
31
31
  @delivery_method_name = data['delivery']['methodName']
32
32
  @delivery_status_name = data['delivery']['statusName']
33
33
  @delivery_url = data['delivery']['url']
34
+ @name = @created
34
35
  end
35
36
  end
36
37
  end
@@ -18,7 +18,32 @@ module MMS
18
18
  end
19
19
 
20
20
  def _load(id)
21
- MMS::Client.instance.get('/groups/' + @cluster.group.id + '/clusters/' + @cluster.id + '/snapshots/' + id.to_s)
21
+ MMS::Client.instance.get '/groups/' + @cluster.group.id + '/clusters/' + @cluster.id + '/snapshots/' + id.to_s
22
+ end
23
+
24
+ def create_restorejob
25
+ data = {:snapshotId => @id}
26
+ jobs = MMS::Client.instance.post '/groups/' + @cluster.group.id + '/clusters/' + @cluster.id + '/restoreJobs', data
27
+
28
+ if jobs.nil?
29
+ raise "Cannot create job from snapshot `#{self.id}`"
30
+ end
31
+
32
+ job_list = []
33
+ # work around due to bug in MMS API; cannot read restoreJob using provided info.
34
+ restore_jobs = @cluster.restorejobs
35
+
36
+ jobs.each do |job|
37
+ _list = restore_jobs.select {|restorejob| restorejob.id == job['id'] }
38
+ _list.each do |restorejob|
39
+ begin
40
+ job_list.push MMS::Resource::RestoreJob.new(restorejob.id, restorejob.cluster.id, restorejob.cluster.group.id)
41
+ rescue => e
42
+ puts "load error #{e.message}"
43
+ end
44
+ end
45
+ end
46
+ job_list
22
47
  end
23
48
 
24
49
  def _from_hash(data)
@@ -27,6 +52,7 @@ module MMS
27
52
  @created_increment = data['created']['increment']
28
53
  @expires = data['expires']
29
54
  @parts = data['parts']
55
+ @name = @created_date
30
56
  end
31
57
  end
32
58
  end
@@ -1,3 +1,3 @@
1
1
  module MMS
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cargo Media
@@ -19,7 +19,7 @@ dependencies:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
21
  version: '1.4'
22
- type: :development
22
+ type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
@@ -33,7 +33,7 @@ dependencies:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
35
  version: 1.4.5
36
- type: :development
36
+ type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements: