mms-api 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,5 @@
1
1
  module MMS
2
-
3
2
  class Resource::Host < Resource
4
-
5
3
  attr_accessor :name
6
4
  attr_accessor :hostname
7
5
  attr_accessor :port
@@ -30,12 +28,12 @@ module MMS
30
28
  MMS::Resource::Snapshot.find(@client, group.id, nil, @id, id)
31
29
  end
32
30
 
33
- def snapshots(page = 1, limit = 1000)
31
+ def snapshots(page = 1, limit = 100)
34
32
  if @snapshots.empty?
35
33
  @client.get('/groups/' + group.id + '/hosts/' + @id + '/snapshots?pageNum=' + page.to_s + '&itemsPerPage=' + limit.to_s).each do |snapshot|
36
34
  s = MMS::Resource::Snapshot.new
37
- s.set_client(@client)
38
- s.set_data(snapshot)
35
+ s.client(@client)
36
+ s.data(snapshot)
39
37
 
40
38
  @snapshots.push s
41
39
  end
@@ -58,18 +56,18 @@ module MMS
58
56
  # @param [MMS::Client] client
59
57
  # @param [String] group_id
60
58
  # @param [String] id
61
- # @returns [Hash]
59
+ # @return [Hash]
62
60
  def self._find(client, group_id, id)
63
61
  client.get('/groups/' + group_id + '/hosts/' + id)
64
62
  end
65
63
 
66
- # @returns [Array<MMS::Resource::Metric>]
64
+ # @return [Array<MMS::Resource::Metric>]
67
65
  def metrics
68
66
  if @metric_list.empty?
69
67
  @client.get('/groups/' + group.id + '/hosts/' + @id + '/metrics').each do |metric|
70
68
  m = MMS::Resource::Metric.new
71
- m.set_client(@client)
72
- m.set_data(metric)
69
+ m.client(@client)
70
+ m.data(metric)
73
71
 
74
72
  @metric_list.push m
75
73
  end
@@ -77,8 +75,6 @@ module MMS
77
75
  @metric_list
78
76
  end
79
77
 
80
- private
81
-
82
78
  def _from_hash(data)
83
79
  @hostname = data['hostname']
84
80
  @port = data['port']
@@ -99,6 +95,5 @@ module MMS
99
95
  def _to_hash
100
96
  @data
101
97
  end
102
-
103
98
  end
104
99
  end
@@ -1,7 +1,5 @@
1
1
  module MMS
2
-
3
2
  class Resource::Metric < Resource
4
-
5
3
  attr_accessor :name
6
4
  attr_accessor :units
7
5
  attr_accessor :granularity
@@ -12,7 +10,7 @@ module MMS
12
10
  end
13
11
 
14
12
  # @param [Hash] options
15
- # @returns [Array<Hash>]
13
+ # @return [Array<Hash>]
16
14
  def data_points(options = {})
17
15
  series = []
18
16
  metric_data = get_metric_data(options)
@@ -31,7 +29,7 @@ module MMS
31
29
  # @param [String] group_id
32
30
  # @param [String] host_id
33
31
  # @param [String] metric_name
34
- # @returns [Hash]
32
+ # @return [Hash]
35
33
  def self._find(client, group_id, host_id, metric_name)
36
34
  client.get('/groups/' + group_id + '/hosts/' + host_id + '/metrics/' + metric_name)
37
35
  end
@@ -39,12 +37,12 @@ module MMS
39
37
  private
40
38
 
41
39
  # @param [Hash] options
42
- # @param [String] name
43
- # @returns [Hash]
40
+ # @param [String] d_name
41
+ # @return [Hash]
44
42
  def get_metric_data(options = {}, d_name = '')
45
43
  params = options.map { |k, v| "#{k}=#{v}" }.join('&')
46
44
  ret = client.get("/groups/#{@data['groupId']}/hosts/#{@data['hostId']}/metrics/#{@data['metricName']}/#{d_name}?#{params}")
47
- ret.delete("links")
45
+ ret.delete('links')
48
46
  ret
49
47
  end
50
48
 
@@ -1,9 +1,7 @@
1
1
  require 'date'
2
2
 
3
3
  module MMS
4
-
5
4
  class Resource::RestoreJob < Resource
6
-
7
5
  attr_accessor :name
8
6
 
9
7
  # this is source point from where RestoreJob was created
@@ -44,17 +42,17 @@ module MMS
44
42
  end
45
43
 
46
44
  def table_row
47
- time_str = DateTime.parse(@timestamp).strftime("%m/%d/%Y %H:%M")
45
+ time_str = DateTime.parse(@timestamp).strftime('%m/%d/%Y %H:%M')
48
46
  [time_str, @snapshot_id, @name, @status_name, @point_in_time, @delivery_method_name, @delivery_status_name]
49
47
  end
50
48
 
51
49
  def table_section
52
50
  [
53
51
  table_row,
54
- [@id, "#{cluster.name} (#{cluster.id})", {:value => '', :colspan => 5}],
55
- ['', cluster.group.name, {:value => '', :colspan => 5}],
56
- [{:value => 'download url:', :colspan => 7}],
57
- [{:value => @delivery_url || '(waiting for link)', :colspan => 7}],
52
+ [@id, "#{cluster.name} (#{cluster.id})", { value: '', colspan: 5 }],
53
+ ['', cluster.group.name, { value: '', colspan: 5 }],
54
+ [{ value: 'download url:', colspan: 7 }],
55
+ [{ value: @delivery_url || '(waiting for link)', colspan: 7 }],
58
56
  :separator
59
57
  ]
60
58
  end
@@ -64,7 +62,7 @@ module MMS
64
62
  end
65
63
 
66
64
  def self._find(client, group_id, cluster_id, host_id, id)
67
- host_id.nil? ? self._find_by_cluster(client, group_id, cluster_id, id) : self._find_by_host(client, group_id, host_id, id)
65
+ host_id.nil? ? _find_by_cluster(client, group_id, cluster_id, id) : _find_by_host(client, group_id, host_id, id)
68
66
  end
69
67
 
70
68
  def self._find_by_host(client, group_id, host_id, id)
@@ -86,7 +84,7 @@ module MMS
86
84
  @delivery_method_name = data['delivery']['methodName'] unless data['delivery'].nil?
87
85
  @delivery_status_name = data['delivery']['statusName'] unless data['delivery'].nil?
88
86
  @delivery_url = data['delivery']['url'] unless data['delivery'].nil?
89
- @name = DateTime.parse(@created).strftime("%Y-%m-%d %H:%M:%S")
87
+ @name = DateTime.parse(@created).strftime('%Y-%m-%d %H:%M:%S')
90
88
  @cluster_id = data['clusterId']
91
89
  @group_id = data['groupId']
92
90
  @host_id = data['hostId']
@@ -1,9 +1,7 @@
1
1
  require 'date'
2
2
 
3
3
  module MMS
4
-
5
4
  class Resource::Snapshot < Resource
6
-
7
5
  attr_accessor :name
8
6
 
9
7
  attr_accessor :complete
@@ -20,12 +18,12 @@ module MMS
20
18
 
21
19
  # @return [TrueClass, FalseClass]
22
20
  def is_config
23
- @parts.length == 1 and @parts.first['typeName'] == 'REPLICA_SET' and !@parts.first['hostId'].nil?
21
+ @parts.length == 1 && @parts.first['typeName'] == 'REPLICA_SET' && !@parts.first['hostId'].nil?
24
22
  end
25
23
 
26
24
  # @return [TrueClass, FalseClass]
27
25
  def is_replica
28
- @parts.length == 1 and @parts.first['typeName'] == 'REPLICA_SET' and !@parts.first['clusterId'].nil?
26
+ @parts.length == 1 && @parts.first['typeName'] == 'REPLICA_SET' && !@parts.first['clusterId'].nil?
29
27
  end
30
28
 
31
29
  # @return [String, NilClass]
@@ -59,17 +57,17 @@ module MMS
59
57
 
60
58
  # @return [Array<MMS::Resource::RestoreJob>]
61
59
  def create_restorejob
62
- data = {:snapshotId => @id}
60
+ data = { snapshotId: @id }
63
61
  job_data_list = @client.post '/groups/' + cluster.group.id + '/clusters/' + cluster.id + '/restoreJobs', data
64
62
 
65
63
  if job_data_list.nil?
66
- raise MMS::ResourceError.new("Cannot create job from snapshot `#{self.id}`", self)
64
+ fail MMS::ResourceError.new("Cannot create job from snapshot `#{id}`", self)
67
65
  end
68
66
 
69
67
  job_data_list.map do |job_data|
70
68
  j = MMS::Resource::RestoreJob.new
71
- j.set_client(@client)
72
- j.set_data(job_data)
69
+ j.client(@client)
70
+ j.data(job_data)
73
71
  j
74
72
  end
75
73
  end
@@ -84,8 +82,8 @@ module MMS
84
82
  rows << :separator
85
83
  part_count = 0
86
84
  @parts.each do |part|
87
- file_size_mb = part['fileSizeBytes'].to_i / (1024*1024)
88
- rows << [{:value => "part #{part_count}", :colspan => 4, :alignment => :right}, part['typeName'], part['replicaSetName'], "#{file_size_mb} MB"]
85
+ file_size_mb = part['fileSizeBytes'].to_i / (1024 * 1024)
86
+ rows << [{ value: "part #{part_count}", colspan: 4, alignment: :right }, part['typeName'], part['replicaSetName'], "#{file_size_mb} MB"]
89
87
  part_count += 1
90
88
  end
91
89
  rows << :separator
@@ -102,7 +100,7 @@ module MMS
102
100
  # @param [String] id
103
101
  # @return [MMS::Resource::Snapshot]
104
102
  def self._find(client, group_id, cluster_id, host_id, id)
105
- host_id.nil? ? self._find_by_cluster(client, group_id, cluster_id, id) : self._find_by_host(client, group_id, host_id, id)
103
+ host_id.nil? ? _find_by_cluster(client, group_id, cluster_id, id) : _find_by_host(client, group_id, host_id, id)
106
104
  end
107
105
 
108
106
  def self._find_by_cluster(client, group_id, cluster_id, id)
@@ -122,12 +120,11 @@ module MMS
122
120
  @expires = data['expires']
123
121
  @parts = data['parts']
124
122
  @is_possibly_inconsistent = data['isPossiblyInconsistent']
125
- @name = @created_date.nil? ? @id : DateTime.parse(@created_date).strftime("%Y-%m-%d %H:%M:%S")
123
+ @name = @created_date.nil? ? @id : DateTime.parse(@created_date).strftime('%Y-%m-%d %H:%M:%S')
126
124
  end
127
125
 
128
126
  def _to_hash
129
127
  @data
130
128
  end
131
-
132
129
  end
133
130
  end
@@ -1,7 +1,5 @@
1
1
  module MMS
2
-
3
2
  class Resource::SnapshotSchedule < Resource
4
-
5
3
  attr_accessor :name
6
4
 
7
5
  attr_accessor :snapshot_interval_hours
@@ -18,14 +16,14 @@ module MMS
18
16
 
19
17
  def table_row
20
18
  [
21
- cluster.group.name,
22
- cluster.name,
23
- @snapshot_interval_hours,
24
- @snapshot_retention_days,
25
- @cluster_checkpoint_interval_min,
26
- @daily_snapshot_retention_days,
27
- @weekly_snapshot_retention_weeks,
28
- @monthly_snapshot_retention_months,
19
+ cluster.group.name,
20
+ cluster.name,
21
+ @snapshot_interval_hours,
22
+ @snapshot_retention_days,
23
+ @cluster_checkpoint_interval_min,
24
+ @daily_snapshot_retention_days,
25
+ @weekly_snapshot_retention_weeks,
26
+ @monthly_snapshot_retention_months
29
27
  ]
30
28
  end
31
29
 
@@ -34,7 +32,7 @@ module MMS
34
32
  end
35
33
 
36
34
  def self.table_header
37
- ['Group', 'Cluster', 'IntervalHours', 'RetentionDays', 'CheckpointIntervalMin', 'RetentionDays', 'RetentionWeeks', 'RetentionMonths']
35
+ %w(Group Cluster IntervalHours RetentionDays CheckpointIntervalMin RetentionDays RetentionWeeks RetentionMonths)
38
36
  end
39
37
 
40
38
  def self._find(client, group_id, cluster_id)
@@ -55,6 +53,5 @@ module MMS
55
53
  def _to_hash
56
54
  @data
57
55
  end
58
-
59
56
  end
60
57
  end
@@ -1,3 +1,3 @@
1
1
  module MMS
2
- VERSION = '0.1.5'
2
+ VERSION = '0.2.0'
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.1.5
4
+ version: 0.2.0
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: 2015-11-11 00:00:00.000000000 Z
13
+ date: 2015-12-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: net-http-digest_auth
@@ -82,6 +82,34 @@ dependencies:
82
82
  - - ">="
83
83
  - !ruby/object:Gem::Version
84
84
  version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: pry
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: rubocop
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
85
113
  - !ruby/object:Gem::Dependency
86
114
  name: rspec
87
115
  requirement: !ruby/object:Gem::Requirement