diff options
author | ramon <ramongomez@us.es> | 2017-10-16 16:13:59 +0000 |
---|---|---|
committer | ramon <ramongomez@us.es> | 2017-10-16 16:13:59 +0000 |
commit | d610135c9b6ee43d13bce5e5b6e4ce51c59a3648 (patch) | |
tree | 49dfaaf3a3b39f4741a559322060113587fd7e56 | |
parent | 4073d146fec96ca89608a8e54ca2a6e5a25332ae (diff) |
#810: Convertir datos a bytes para ruta REST {{{/repository/images}}}; propiedades de repositorio convierte tamaños a valor legible.
git-svn-id: https://opengnsys.es/svn/branches/version1.1@5463 a21b9725-9963-47de-94b9-378ad31fedc9
-rw-r--r-- | admin/WebConsole/includes/comunes.php | 16 | ||||
-rw-r--r-- | admin/WebConsole/propiedades/propiedades_repositorios.php | 33 | ||||
-rw-r--r-- | admin/WebConsole/rest/repository.php | 13 | ||||
-rwxr-xr-x | repoman/bin/checkrepo | 4 |
4 files changed, 38 insertions, 28 deletions
diff --git a/admin/WebConsole/includes/comunes.php b/admin/WebConsole/includes/comunes.php index 35e53697..b0dade06 100644 --- a/admin/WebConsole/includes/comunes.php +++ b/admin/WebConsole/includes/comunes.php @@ -380,3 +380,19 @@ } return($selecHtml); } + + /* + * Devuelve el valor legible para un tamaño (en múltiplos de 1024). + * Nota: obtenido de la documentación de PHP (php.net). + * Parámetros: + * bytes - tamaño en bytes (entero) + * Devielve: + * cadena con número en formato de sistema internacional (2 decimales) + */ + function humanSize($bytes) { + $si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' ); + $base = 1024; + $class = min((int)log($bytes , $base) , count($si_prefix) - 1); + return sprintf('%1.2f' , $bytes / pow($base,$class)) . ' ' . $si_prefix[$class]; + } + diff --git a/admin/WebConsole/propiedades/propiedades_repositorios.php b/admin/WebConsole/propiedades/propiedades_repositorios.php index ee97f047..d809dfea 100644 --- a/admin/WebConsole/propiedades/propiedades_repositorios.php +++ b/admin/WebConsole/propiedades/propiedades_repositorios.php @@ -10,6 +10,7 @@ // **********************************************************************************************************
include_once("../includes/ctrlacc.php");
include_once("../includes/opciones.php");
+include_once("../includes/comunes.php");
include_once("../includes/CreaComando.php");
include_once("../clases/AdoPhp.php");
include_once("../idiomas/php/".$idioma."/propiedades_repositorios_".$idioma.".php");
@@ -52,11 +53,11 @@ if($apiKeyRepo != ""){ $result = multiRequest($repo);
if ($result[0]['code'] === 200) {
$result = json_decode($result[0]['data']);
- $repodir=$result->directory;
- $totalrepo=$result->disk->total;
- $ocupadorepo=$result->disk->used;
- $librerepo=$result->disk->free;
- $porcentajerepo=$result->disk->percent;
+ $repodir = $result->directory;
+ $totalrepo = humanSize($result->disk->total);
+ $librerepo = humanSize($result->disk->free);
+ $ocupadorepo = humanSize($result->disk->total - $result->disk->free);
+ $porcentajerepo = 100 - floor(100 * $result->disk->$free / $result->disk->$total);
$repoOus = $result->ous;
$repoImages = $result->images;
$repoWithApi = true;
@@ -158,27 +159,27 @@ if($apiKeyRepo != ""){ <?php if ($repoWithApi) { ?>
<TR>
- <TH align=center width=125> <?echo $TbMsg[11]?> </TD>
- <TH align=center width=120> <?echo $TbMsg[12]?> </TD>
- <TH align=center width=120> <?echo $TbMsg[13]?> </TD>
- <TH align=center width=101> <?echo $TbMsg[14]?> </TD>
+ <TH align=center width=125> <?php echo $TbMsg[11]?> </TD>
+ <TH align=center width=120> <?php echo $TbMsg[12]?> </TD>
+ <TH align=center width=120> <?php echo $TbMsg[13]?> </TD>
+ <TH align=center width=101> <?php echo $TbMsg[14]?> </TD>
</TR>
<TR>
- <TD align=center width=125> <?echo $totalrepo?> </TD>
- <TD align=center width=120> <?echo $ocupadorepo?> </TD>
- <TD align=center width=120> <?echo $librerepo?> </TD>
- <TD align=center width=101> <?echo $porcentajerepo?> </TD>
+ <TD align=center width=125> <?php echo $totalrepo?> </TD>
+ <TD align=center width=120> <?php echo $ocupadorepo?> </TD>
+ <TD align=center width=120> <?php echo $librerepo?> </TD>
+ <TD align=center width=101> <?php echo "$porcentajerepo %" ?> </TD>
</TR>
<?php
- // Si tenemos informacion del repositorio remoto, mostramos las imagenes
- if($repoWithApi == true && is_array($repoImages)){
+ // Si tenemos informacion del repositorio remoto, mostramos las imagenes
+ if($repoWithApi == true && is_array($repoImages)){
echo "<tr class='tabla_listados_sin'><th colspan='4'>".$TbMsg['MSG_CONTENT']." $repodir</th></tr>\n";
echo "<tr><td>".$TbMsg['MSG_IMAGE']." (".$TbMsg['MSG_TYPE'].")</td><td>".$TbMsg['MSG_SIZEBYTES']."</td><td>".$TbMsg['MSG_MODIFIED']."</td><td>".$TbMsg['MSG_PERMISSIONS']."</td></tr>\n";
foreach($repoImages as $image){
echo "<tr class='tabla_listados_sin'>";
echo "<td>".$image->name." (".$image->type.")</td>";
- echo "<td>".$image->size."</td>";
+ echo "<td>".humanSize($image->size)."</td>";
echo "<td>".$image->modified."</td>";
echo "<td>".$image->mode."</td>";
echo "</tr>\n";
diff --git a/admin/WebConsole/rest/repository.php b/admin/WebConsole/rest/repository.php index 3acb4230..c8288a98 100644 --- a/admin/WebConsole/rest/repository.php +++ b/admin/WebConsole/rest/repository.php @@ -64,13 +64,6 @@ function commandExist($cmd) { return (empty($returnVal) ? false : true); } -function humanSize($bytes) -{ - $si_prefix = array( 'B', 'KB', 'MB', 'GB', 'TB', 'EB', 'ZB', 'YB' ); - $base = 1024; - $class = min((int)log($bytes , $base) , count($si_prefix) - 1); - return sprintf('%1.2f' , $bytes / pow($base,$class)) . ' ' . $si_prefix[$class]; -} // Define REST routes. @@ -118,10 +111,8 @@ $app->get('/repository/images(/)', 'validateRepositoryApiKey', // Retrieve disk information. $total = disk_total_space($imgPath); $free = disk_free_space($imgPath); - $response['disk']['total'] = humanSize($total); - $response['disk']['used'] = humanSize($total - $free); - $response['disk']['free'] = humanSize($free); - $response['disk']['percent'] = 100 - floor(100 * $free / $total) . " %"; + $response['disk']['total'] = $total; + $response['disk']['free'] = $free; // JSON response. jsonResponse(200, $response); } else { diff --git a/repoman/bin/checkrepo b/repoman/bin/checkrepo index 822ae20a..b38a689b 100755 --- a/repoman/bin/checkrepo +++ b/repoman/bin/checkrepo @@ -39,6 +39,8 @@ function addToJson() { OUNAME="${IMAGENAME%/*}" IMAGENAME="${IMAGENAME##*/}" fi + # Data size must be numeric (in KB). + [[ $DATASIZE =~ ^[0-9]*$ ]] || DATASIZE=0 # JSON-formatted new entry. JSON=$(cat << EOT | jq . { @@ -48,7 +50,7 @@ function addToJson() { "clonator":"${CLONATOR,,}", "compressor":"${COMPRESSOR,,}", "filesystem":"${FSTYPE^^}", - "datasize":${DATASIZE:-0} + "datasize":$[ DATASIZE * 1024] } EOT ) |