From 335c2ed06ab97443e1809819bb77b9946bec405c Mon Sep 17 00:00:00 2001
From: Leif Ryge <leif@synthesize.us>
Date: Thu, 20 Nov 2014 22:46:20 +0000
Subject: [PATCH] add "Available" column to welcome page (#648)

add get_available_space() to NativeStorageServer

It uses a new 'available-space' key in the server's v1 version dict, or falls
back to 'maximum-immutable-share-size' (which presently always has the same
value but could have a different meaning in the future).

This is a squash merge of 9773555bb87fab71145ad7a0e84785a4e92d11f7
---
 src/allmydata/storage/server.py |  1 +
 src/allmydata/storage_client.py | 10 ++++++++++
 src/allmydata/test/test_web.py  |  2 ++
 src/allmydata/web/root.py       |  7 ++++++-
 src/allmydata/web/welcome.xhtml |  2 ++
 5 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/allmydata/storage/server.py b/src/allmydata/storage/server.py
index 9c0397c0..1de4b22f 100644
--- a/src/allmydata/storage/server.py
+++ b/src/allmydata/storage/server.py
@@ -227,6 +227,7 @@ class StorageServer(service.MultiService, Referenceable):
         version = { "http://allmydata.org/tahoe/protocols/storage/v1" :
                     { "maximum-immutable-share-size": remaining_space,
                       "maximum-mutable-share-size": MAX_MUTABLE_SHARE_SIZE,
+                      "available-space": remaining_space,
                       "tolerates-immutable-read-overrun": True,
                       "delete-mutable-shares-with-zero-length-writev": True,
                       "fills-holes-with-zero-bytes": True,
diff --git a/src/allmydata/storage_client.py b/src/allmydata/storage_client.py
index 92ecf6e6..f8b19d66 100644
--- a/src/allmydata/storage_client.py
+++ b/src/allmydata/storage_client.py
@@ -265,6 +265,16 @@ class NativeStorageServer:
     def get_announcement_time(self):
         return self.announcement_time
 
+    def get_available_space(self):
+        version = self.get_version()
+        if version is None:
+            return None
+        protocol_v1_version = version.get('http://allmydata.org/tahoe/protocols/storage/v1', {})
+        available_space = protocol_v1_version.get('available-space')
+        if available_space is None:
+            available_space = protocol_v1_version.get('maximum-immutable-share-size', None)
+        return available_space
+
     def start_connecting(self, tub, trigger_cb):
         furl = str(self.announcement["anonymous-storage-FURL"])
         self._trigger_cb = trigger_cb
diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py
index 52c53b5b..14684c38 100644
--- a/src/allmydata/test/test_web.py
+++ b/src/allmydata/test/test_web.py
@@ -191,6 +191,8 @@ class FakeDisplayableServer(StubServer):
         return self.announcement
     def get_nickname(self):
         return self.announcement["nickname"]
+    def get_available_space(self):
+        return 0
 
 class FakeBucketCounter(object):
     def get_state(self):
diff --git a/src/allmydata/web/root.py b/src/allmydata/web/root.py
index 9495d3df..5f1d2367 100644
--- a/src/allmydata/web/root.py
+++ b/src/allmydata/web/root.py
@@ -288,7 +288,11 @@ class Root(rend.Page):
         announcement = server.get_announcement()
         version = announcement["my-version"]
         service_name = announcement["service-name"]
-
+        available_space = server.get_available_space()
+        if available_space is None:
+            available_space = "N/A"
+        else:
+            available_space = abbreviate_size(available_space)
         ctx.fillSlots("address", addr)
         ctx.fillSlots("connected", connected)
         ctx.fillSlots("connected-bool", bool(rhost))
@@ -298,6 +302,7 @@ class Root(rend.Page):
                                                  time.localtime(announced)))
         ctx.fillSlots("version", version)
         ctx.fillSlots("service_name", service_name)
+        ctx.fillSlots("available_space", available_space)
 
         return ctx.tag
 
diff --git a/src/allmydata/web/welcome.xhtml b/src/allmydata/web/welcome.xhtml
index bcfa3d04..72a2be16 100644
--- a/src/allmydata/web/welcome.xhtml
+++ b/src/allmydata/web/welcome.xhtml
@@ -173,6 +173,7 @@
                 <td><h3>Since</h3></td>
                 <td><h3>Announced</h3></td>
                 <td><h3>Version</h3></td>
+                <td><h3>Available</h3></td>
               </tr>
             </thead>
             <tr n:pattern="item" n:render="service_row">
@@ -186,6 +187,7 @@
               <td class="service-since timestamp"><n:slot name="since"/></td>
               <td class="service-announced timestamp"><n:slot name="announced"/></td>
               <td class="service-version"><n:slot name="version"/></td>
+              <td class="service-available-space"><n:slot name="available_space"/></td>
             </tr>
             <tr n:pattern="empty"><td>You are not presently connected to any peers</td></tr>
           </table>
-- 
2.45.2