16718: Merge branch 'master' into 16718-group-contents-collection-versions
[arvados.git] / services / api / app / models / keep_disk.rb
index ee285d969af0a9754cfe52f06b9417f9e8662f97..5751c135d8f9cdd57cc3f2f3ed5d77723c7abe6c 100644 (file)
@@ -1,5 +1,9 @@
+# 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
@@ -7,7 +11,6 @@ class KeepDisk < ArvadosModel
   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
@@ -18,6 +21,14 @@ class KeepDisk < ArvadosModel
     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)
@@ -29,18 +40,27 @@ class KeepDisk < ArvadosModel
     end
 
     @bypass_arvados_authorization = true
-    self.update_attributes(o.select { |k,v|
-                             [:service_host,
-                              :service_port,
-                              :service_ssl_flag,
-                              :bytes_total,
+    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: Time.now))
+                           }.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
+
+  def service_ssl_flag
+    KeepService.find_by_uuid(self.keep_service_uuid).andand.service_ssl_flag
   end
 
   protected