mms-api 0.0.4 → 0.0.5

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: 30140add1019a1eeefbbad55e5cacd2589c76157
4
- data.tar.gz: b79a0a425bd350be7a362a456f10c61a1f01e489
3
+ metadata.gz: 0dbc10b527566cf58f1694c0525eb267dc9ffeab
4
+ data.tar.gz: cf1f710e7a902c82971a3af85c414009f1ccc1a1
5
5
  SHA512:
6
- metadata.gz: 69506c6a389147b341450ca1f86a276b6bc81ea8bf1282eec1dbf301c6c9e25e1a348fa52f703e12fb66d8b3a3f629e348311a7c08fe934e08127deaa3c711e9
7
- data.tar.gz: ad0578f5dd4bb9e6b0902197b9e258906c6b4b64912a854dd5d7b88bdd2de41cf71804870371f49fd82281aebd0861b26071a7a15f52a7637456983f3af68628
6
+ metadata.gz: ca588615fc6636d100578f39c567ddf1952caf4f7f3abd2eeae54a306304483ac72395e65c232cdafb729f0ffcd4bcbf0791e7eccd1c9c9e5d793566d0f53ee4
7
+ data.tar.gz: d4c01011132846e6fa2f62bfdbf5b4943ce21b9ca01fa743087b808f5b449860eec72083259850dec289ea85e27e2acbeca28c07927fd599c07679f5a71df66e
data/README.md CHANGED
@@ -1,3 +1,65 @@
1
1
  mms-api
2
2
  =======
3
3
  Minimalistic [MMS API](http://mms.mongodb.com/) agent for ruby
4
+
5
+ Installation
6
+ ------------
7
+ ```
8
+ gem install mms-api
9
+ ```
10
+
11
+ Cli
12
+ ---
13
+ ```bash
14
+ $ mms-api --help
15
+ mms-api is a tool for accessing MMS API
16
+
17
+ Usage:
18
+
19
+ mms-api command [options]
20
+
21
+ Commands:
22
+
23
+ groups | clusters | snapshots | restorejobs | restorejobs-create
24
+
25
+ Options:
26
+
27
+ -u, --username <string> MMS user
28
+ -k, --apikey <string> MMS api-key
29
+ -n, --name <string> Filter by resource name using regexp
30
+ -l, --limit <int> Limit for result items
31
+ -v, --version Version
32
+ -h, --help Show this help
33
+ ```
34
+
35
+ Development
36
+ -----------
37
+ ```ruby
38
+ require 'mms'
39
+
40
+ agent = MMS::Agent.new('username', 'apikey')
41
+
42
+ # all available resources
43
+ group_list = agent.groups
44
+ cluster_list = agent.clusters
45
+ snapshot_list = agent.snapshots
46
+
47
+ # get first cluster from list
48
+ cluster = cluster_list.first
49
+
50
+ # get list of all restore-jobs for specific cluster
51
+ job_list = agent.findGroup(cluster.group.id).cluster(cluster.id).restorejobs
52
+ # or simply using cluster instance
53
+ job_list = cluster.restorejobs
54
+
55
+ # get first snapshot from list
56
+ snapshot = snapshot_list.first
57
+
58
+ # create restore job for snapshot
59
+ group_id = snapshot.cluster.group.id
60
+ cluster_id = snapshot.cluster.id
61
+ snapshot_id = snapshot.id
62
+ job_list = agent.findGroup(group_id).cluster(cluster_id).snapshot(snapshot_id).create_restorejob
63
+ # or simply using snapshot instance
64
+ job_list = snapshot.create_restorejob
65
+ ```
data/bin/mms-api CHANGED
@@ -7,14 +7,17 @@ require 'optparse'
7
7
  require 'terminal-table'
8
8
  require 'pp'
9
9
 
10
- name = 'mms-api'
11
- version = MMS::VERSION
12
-
13
10
  actions_available = ["groups", "clusters", "snapshots", "restorejobs", "restorejobs-create"]
14
11
 
12
+ app_name = 'mms-api'
13
+ app_dscr = "#{app_name} is a tool for accessing MMS API"
14
+ app_usage = "#{app_name} command [options]"
15
+ app_version = MMS::VERSION
16
+ app_commands = "#{actions_available.join(' | ')}"
17
+
15
18
  options = {}
16
19
  optparse = OptionParser.new do |opts|
17
- opts.banner = "Usage: #{name} [options] action"
20
+ opts.banner = "#{app_dscr}\n\nUsage:\n\n\t#{app_usage}\n\nCommands:\n\n\t#{app_commands}\n\nOptions:\n\n"
18
21
 
19
22
  opts.on("-u", "--username <string>", "MMS user") do |u|
20
23
  options[:username] = u
@@ -25,17 +28,17 @@ optparse = OptionParser.new do |opts|
25
28
  end
26
29
 
27
30
  options[:name] = '.*'
28
- opts.on("-n", "--name <string>", "Resource name using regexp") do |n|
31
+ opts.on("-n", "--name <string>", "Filter for resource name using regexp") do |n|
29
32
  options[:name] = n
30
33
  end
31
34
 
32
35
  options[:limit] = 5
33
- opts.on("-l", "--limit <string>", "Limit for result items") do |l|
36
+ opts.on("-l", "--limit <int>", "Limit for result items") do |l|
34
37
  options[:limit] = l.to_i
35
38
  end
36
39
 
37
40
  opts.on("-v", "--version", "Version") do |v|
38
- puts "#{name} v#{version}"
41
+ puts "#{app_name} v#{app_version}"
39
42
  exit
40
43
  end
41
44
 
@@ -91,10 +94,10 @@ begin
91
94
  rows << [cluster.group.name, cluster.name, cluster.shard_name, cluster.replicaset_name, cluster.type_name, cluster.last_heartbeat]
92
95
  end
93
96
  when 'snapshots'
94
- heading = ['Group', 'Cluster', 'SnapshotId', 'Complete', 'Created increment', 'Created date (Name)', 'Expires']
97
+ heading = ['Group', 'Cluster', 'SnapshotId', 'Complete', 'Created increment', 'Name (created date)', 'Expires']
95
98
  results_sorted = results.sort_by { |snapshot| snapshot.created_date }.reverse
96
99
  results_sorted.first(options[:limit]).each do |snapshot|
97
- rows << [snapshot.cluster.group.name, snapshot.cluster.name, snapshot.id, snapshot.complete, snapshot.created_increment, snapshot.created_date, snapshot.expires]
100
+ rows << [snapshot.cluster.group.name, snapshot.cluster.name, snapshot.id, snapshot.complete, snapshot.created_increment, snapshot.name, snapshot.expires]
98
101
  rows << :separator
99
102
  part_count = 0
100
103
  snapshot.parts.each do |part|
@@ -105,10 +108,10 @@ begin
105
108
  rows << :separator
106
109
  end
107
110
  when 'restorejobs', 'restorejobs-create'
108
- heading = ['RestoreId', 'SnapshotId / Cluster / Group', 'Created (Name)', 'Status', 'Point in time', 'Delivery', 'Restore status']
111
+ heading = ['RestoreId', 'SnapshotId / Cluster / Group', 'Name (created)', 'Status', 'Point in time', 'Delivery', 'Restore status']
109
112
  results_sorted = results.sort_by { |job| job.created }.reverse
110
113
  results_sorted.first(options[:limit]).each do |job|
111
- rows << [job.id, job.snapshot_id, job.created, job.status_name, job.point_in_time, job.delivery_method_name, job.delivery_status_name]
114
+ rows << [job.id, job.snapshot_id, job.name, job.status_name, job.point_in_time, job.delivery_method_name, job.delivery_status_name]
112
115
  rows << ['', "#{job.cluster.name} (#{job.cluster.id})", {:value => '', :colspan => 5}]
113
116
  rows << ['', job.cluster.group.name, {:value => '', :colspan => 5}]
114
117
  rows << [{:value => 'download url:', :colspan => 7}]
@@ -117,9 +120,7 @@ begin
117
120
  end
118
121
  end
119
122
 
120
- table = Terminal::Table.new :title => action.upcase, :headings => (heading.nil? ? [] : heading), :rows => rows
121
-
122
- puts table
123
+ puts Terminal::Table.new :title => action.upcase, :headings => (heading.nil? ? [] : heading), :rows => rows
123
124
 
124
125
  rescue => e
125
126
  puts "Error: `#{e.message}`"
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module MMS
2
4
 
3
5
  class Resource::RestoreJob < Resource
@@ -31,7 +33,7 @@ module MMS
31
33
  @delivery_method_name = data['delivery']['methodName']
32
34
  @delivery_status_name = data['delivery']['statusName']
33
35
  @delivery_url = data['delivery']['url']
34
- @name = @created
36
+ @name = DateTime.parse(@created).strftime("%Y-%m-%d %H:%M:%S")
35
37
  end
36
38
  end
37
39
  end
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module MMS
2
4
 
3
5
  class Resource::Snapshot < Resource
@@ -52,7 +54,7 @@ module MMS
52
54
  @created_increment = data['created']['increment']
53
55
  @expires = data['expires']
54
56
  @parts = data['parts']
55
- @name = @created_date
57
+ @name = DateTime.parse(@created_date).strftime("%Y-%m-%d %H:%M:%S")
56
58
  end
57
59
  end
58
60
  end
data/lib/mms/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module MMS
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
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.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cargo Media