X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/7787fad07c7e3f707960f4df0a0ef63c056e58ce..3d58aca14b5f5e1fc54ab00c565f93d97f86df86:/services/api/app/models/keep_disk.rb diff --git a/services/api/app/models/keep_disk.rb b/services/api/app/models/keep_disk.rb new file mode 100644 index 0000000000..6ff64004bf --- /dev/null +++ b/services/api/app/models/keep_disk.rb @@ -0,0 +1,47 @@ +class KeepDisk < ArvadosModel + include AssignUuid + include KindAndEtag + include CommonApiTemplate + before_validation :ensure_ping_secret + + api_accessible :superuser, :extend => :common do |t| + t.add :node_uuid + t.add :filesystem_uuid + t.add :ping_secret + t.add :bytes_total + t.add :bytes_free + t.add :is_readable + t.add :is_writable + t.add :last_read_at + t.add :last_write_at + t.add :last_ping_at + end + + def ping(o) + raise "must have :ip and :ping_secret" unless o[:ip] and o[:ping_secret] + + if o[:ping_secret] != self.ping_secret + logger.info "Ping: secret mismatch: received \"#{o[:ping_secret]}\" != \"#{self.info[:ping_secret]}\"" + return nil + end + self.last_ping_at = Time.now + + @bypass_arvados_authorization = true + + save! + end + + protected + + def ensure_ping_secret + self.ping_secret ||= rand(2**256).to_s(36) + end + + def permission_to_update + @bypass_arvados_authorization or super + end + + def permission_to_create + current_user and current_user.is_admin + end +end