From 383997f785992c010a6dc0ac036939c9f2cc2856 Mon Sep 17 00:00:00 2001 From: Wenkai Yin Date: Tue, 21 Mar 2017 12:35:46 +0800 Subject: [PATCH] read capacity from adminserver --- make/dev/docker-compose.yml | 1 + make/docker-compose.tpl | 2 +- src/ui/api/systeminfo.go | 19 +++++++------------ tests/docker-compose.test.yml | 1 + 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/make/dev/docker-compose.yml b/make/dev/docker-compose.yml index 3b2f555a9..3079e5c1b 100644 --- a/make/dev/docker-compose.yml +++ b/make/dev/docker-compose.yml @@ -50,6 +50,7 @@ services: volumes: - /data/config/:/etc/adminserver/ - /data/secretkey:/etc/adminserver/key + - /data/:/data/ depends_on: - log logging: diff --git a/make/docker-compose.tpl b/make/docker-compose.tpl index 15e6896ec..ae8630425 100644 --- a/make/docker-compose.tpl +++ b/make/docker-compose.tpl @@ -56,6 +56,7 @@ services: volumes: - /data/config/:/etc/adminserver/ - /data/secretkey:/etc/adminserver/key + - /data/:/data/ networks: - harbor depends_on: @@ -74,7 +75,6 @@ services: volumes: - ./common/config/ui/app.conf:/etc/ui/app.conf - ./common/config/ui/private_key.pem:/etc/ui/private_key.pem - - /data:/harbor_storage - /data/secretkey:/etc/ui/key networks: - harbor diff --git a/src/ui/api/systeminfo.go b/src/ui/api/systeminfo.go index 60f5d9fe1..073dc246a 100644 --- a/src/ui/api/systeminfo.go +++ b/src/ui/api/systeminfo.go @@ -3,9 +3,7 @@ package api import ( "net/http" "os" - "path/filepath" "strings" - "syscall" "github.com/vmware/harbor/src/common" "github.com/vmware/harbor/src/common/api" @@ -21,7 +19,6 @@ type SystemInfoAPI struct { isAdmin bool } -const harborStoragePath = "/harbor_storage" const defaultRootCert = "/harbor_storage/ca_download/ca.crt" //SystemInfo models for system info. @@ -66,18 +63,16 @@ func (sia *SystemInfoAPI) GetVolumeInfo() { sia.RenderError(http.StatusForbidden, "User does not have admin role.") return } - var stat syscall.Statfs_t - err := syscall.Statfs(filepath.Join("/", harborStoragePath), &stat) - if err != nil { - log.Errorf("Error occurred in syscall.Statfs: %v", err) - sia.CustomAbort(http.StatusInternalServerError, "Internal error.") - return - } + capacity, err := config.AdminserverClient.Capacity() + if err != nil { + log.Errorf("failed to get capacity: %v", err) + sia.CustomAbort(http.StatusInternalServerError, http.StatusText(http.StatusInternalServerError)) + } systemInfo := SystemInfo{ HarborStorage: Storage{ - Total: stat.Blocks * uint64(stat.Bsize), - Free: stat.Bavail * uint64(stat.Bsize), + Total: capacity.Total, + Free: capacity.Free, }, } diff --git a/tests/docker-compose.test.yml b/tests/docker-compose.test.yml index 7c5c9ca97..f950174ea 100644 --- a/tests/docker-compose.test.yml +++ b/tests/docker-compose.test.yml @@ -31,5 +31,6 @@ services: volumes: - /data/config/:/etc/adminserver/ - /data/secretkey:/etc/adminserver/key + - /data/:/data/ ports: - 8888:80