class MMS::Resource::Snapshot
Attributes
complete[RW]
created_date[RW]
created_increment[RW]
expires[RW]
is_possibly_inconsistent[RW]
name[RW]
parts[RW]
Public Class Methods
_find(client, group_id, cluster_id, host_id, id)
click to toggle source
@param [MMS::Client] client @param [String] group_id @param [String] cluster_id @param [String] id @return [MMS::Resource::Snapshot]
# File lib/mms/resource/snapshot.rb, line 102 def self._find(client, group_id, cluster_id, host_id, id) host_id.nil? ? _find_by_cluster(client, group_id, cluster_id, id) : _find_by_host(client, group_id, host_id, id) end
_find_by_cluster(client, group_id, cluster_id, id)
click to toggle source
# File lib/mms/resource/snapshot.rb, line 106 def self._find_by_cluster(client, group_id, cluster_id, id) client.get('/groups/' + group_id + '/clusters/' + cluster_id + '/snapshots/' + id.to_s) end
_find_by_host(client, group_id, host_id, id)
click to toggle source
# File lib/mms/resource/snapshot.rb, line 110 def self._find_by_host(client, group_id, host_id, id) client.get('/groups/' + group_id + '/hosts/' + host_id + '/snapshots/' + id.to_s) end
table_header()
click to toggle source
# File lib/mms/resource/snapshot.rb, line 93 def self.table_header ['Group', 'Cluster', 'SnapshotId', 'Complete', 'Created increment', 'Name (created date)', 'Expires', 'Inconsistent'] end
Public Instance Methods
cluster()
click to toggle source
@return [MMS::Resource::Cluster]
# File lib/mms/resource/snapshot.rb, line 54 def cluster MMS::Resource::Cluster.find(@client, @data['groupId'], @data['clusterId']) end
cluster_name()
click to toggle source
@return [String, NilClass]
# File lib/mms/resource/snapshot.rb, line 30 def cluster_name cluster.name if is_cluster end
config_name()
click to toggle source
@return [String, NilClass]
# File lib/mms/resource/snapshot.rb, line 35 def config_name 'config' if is_config end
create_restorejob()
click to toggle source
@return [Array<MMS::Resource::RestoreJob>]
# File lib/mms/resource/snapshot.rb, line 59 def create_restorejob data = { snapshotId: @id } job_data_list = @client.post '/groups/' + cluster.group.id + '/clusters/' + cluster.id + '/restoreJobs', data if job_data_list.nil? raise MMS::ResourceError.new("Cannot create job from snapshot `#{id}`", self) end job_data_list.map do |job_data| j = MMS::Resource::RestoreJob.new j.client(@client) j.data(job_data) j end end
is_cluster()
click to toggle source
@return [TrueClass, FalseClass]
# File lib/mms/resource/snapshot.rb, line 15 def is_cluster @parts.length > 1 end
is_config()
click to toggle source
@return [TrueClass, FalseClass]
# File lib/mms/resource/snapshot.rb, line 20 def is_config @parts.length == 1 && @parts.first['typeName'] == 'REPLICA_SET' && !@parts.first['hostId'].nil? end
is_replica()
click to toggle source
@return [TrueClass, FalseClass]
# File lib/mms/resource/snapshot.rb, line 25 def is_replica @parts.length == 1 && @parts.first['typeName'] == 'REPLICA_SET' && !@parts.first['clusterId'].nil? end
replica_name()
click to toggle source
@return [String, NilClass]
# File lib/mms/resource/snapshot.rb, line 40 def replica_name @parts.first['replicaSetName'] if is_replica end
source_name()
click to toggle source
@return [String, NilClass]
# File lib/mms/resource/snapshot.rb, line 45 def source_name name = nil name = replica_name if is_replica name = config_name if is_config name = cluster_name if is_cluster name end
table_row()
click to toggle source
# File lib/mms/resource/snapshot.rb, line 75 def table_row [cluster.group.name, cluster.name, @id, @complete, @created_increment, @name, @expires, @is_possibly_inconsistent] end
table_section()
click to toggle source
# File lib/mms/resource/snapshot.rb, line 79 def table_section rows = [] rows << table_row rows << :separator part_count = 0 @parts.each do |part| file_size_mb = part['fileSizeBytes'].to_i / (1024 * 1024) rows << [{ value: "part #{part_count}", colspan: 4, alignment: :right }, part['typeName'], part['replicaSetName'], "#{file_size_mb} MB"] part_count += 1 end rows << :separator rows end
Private Instance Methods
_from_hash(data)
click to toggle source
# File lib/mms/resource/snapshot.rb, line 116 def _from_hash(data) @complete = data['complete'] @created_date = data['created'].nil? ? nil : data['created']['date'] @created_increment = data['created'].nil? ? nil : data['created']['increment'] @expires = data['expires'] @parts = data['parts'] @is_possibly_inconsistent = data['isPossiblyInconsistent'] @name = @created_date.nil? ? @id : DateTime.parse(@created_date).strftime('%Y-%m-%d %H:%M:%S') end
_to_hash()
click to toggle source
# File lib/mms/resource/snapshot.rb, line 126 def _to_hash @data end