X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/3d58aca14b5f5e1fc54ab00c565f93d97f86df86..b9c5339d113c63ffc3d8a7c6bf1019616bb3f89a:/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 index 6ff64004bf..5751c135d8 100644 --- a/services/api/app/models/keep_disk.rb +++ b/services/api/app/models/keep_disk.rb @@ -1,13 +1,16 @@ +# Copyright (C) The Arvados Authors. All rights reserved. +# +# SPDX-License-Identifier: AGPL-3.0 + class KeepDisk < ArvadosModel - include AssignUuid + include HasUuid include KindAndEtag include CommonApiTemplate before_validation :ensure_ping_secret - api_accessible :superuser, :extend => :common do |t| + api_accessible :user, 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 @@ -15,20 +18,49 @@ class KeepDisk < ArvadosModel t.add :last_read_at t.add :last_write_at t.add :last_ping_at + t.add :service_host + t.add :service_port + t.add :service_ssl_flag + t.add :keep_service_uuid + end + api_accessible :superuser, :extend => :user do |t| + t.add :ping_secret + end + + def foreign_key_attributes + super.reject { |a| a == "filesystem_uuid" } end def ping(o) - raise "must have :ip and :ping_secret" unless o[:ip] and o[:ping_secret] + raise "must have :service_host and :ping_secret" unless o[:service_host] and o[:ping_secret] if o[:ping_secret] != self.ping_secret - logger.info "Ping: secret mismatch: received \"#{o[:ping_secret]}\" != \"#{self.info[:ping_secret]}\"" + logger.info "Ping: secret mismatch: received \"#{o[:ping_secret]}\" != \"#{self.ping_secret}\"" return nil end - self.last_ping_at = Time.now @bypass_arvados_authorization = true + self.update_attributes!(o.select { |k,v| + [:bytes_total, + :bytes_free, + :is_readable, + :is_writable, + :last_read_at, + :last_write_at + ].collect(&:to_s).index k + }.merge(last_ping_at: db_current_time)) + end + + def service_host + KeepService.find_by_uuid(self.keep_service_uuid).andand.service_host + end + + def service_port + KeepService.find_by_uuid(self.keep_service_uuid).andand.service_port + end - save! + def service_ssl_flag + KeepService.find_by_uuid(self.keep_service_uuid).andand.service_ssl_flag end protected