| 1 |
# -*- coding: UTF-8 -*- |
| 2 |
# Bacula(R) - The Network Backup Solution |
| 3 |
# |
| 4 |
# Copyright (C) 2000-2022 Kern Sibbald |
| 5 |
# |
| 6 |
# The original author of Bacula is Kern Sibbald, with contributions |
| 7 |
# from many others, a complete list can be found in the file AUTHORS. |
| 8 |
# |
| 9 |
# You may use this file and others of this release according to the |
| 10 |
# license defined in the LICENSE file, which includes the Affero General |
| 11 |
# Public License, v3.0 ("AGPLv3") and some additional permissions and |
| 12 |
# terms pursuant to its AGPLv3 Section 7. |
| 13 |
# |
| 14 |
# This notice must be preserved when any source code is |
| 15 |
# conveyed and/or propagated. |
| 16 |
# |
| 17 |
# Bacula(R) is a registered trademark of Kern Sibbald. |
| 18 |
|
| 19 |
|
| 20 |
def k8s_size_to_int(res): |
| 21 |
if isinstance(res, str): |
| 22 |
if res.endswith("Ki"): |
| 23 |
return int(res[:-2]) * 1024 |
| 24 |
if res.endswith("Mi"): |
| 25 |
return int(res[:-2]) * 1024 * 1024 |
| 26 |
if res.endswith("Gi"): |
| 27 |
return int(res[:-2]) * 1024 * 1024 * 1024 |
| 28 |
if res.endswith("Pi"): |
| 29 |
return int(res[:-2]) * 1024 * 1024 * 1024 * 1024 |
| 30 |
if res.endswith("Ti"): |
| 31 |
return int(res[:-2]) * 1024 * 1024 * 1024 * 1024 * 1024 |
| 32 |
if res.endswith("K"): |
| 33 |
return int(res[:-1]) * 1000 |
| 34 |
if res.endswith("M"): |
| 35 |
return int(res[:-1]) * 1000000 |
| 36 |
if res.endswith("G"): |
| 37 |
return int(res[:-1]) * 1000000000 |
| 38 |
if res.endswith("P"): |
| 39 |
return int(res[:-1]) * 1000000000000 |
| 40 |
if res.endswith("T"): |
| 41 |
return int(res[:-1]) * 1000000000000000 |
| 42 |
if res.endswith("m"): |
| 43 |
return int(res[:-1]) / 1000.0 |
| 44 |
return 0 |
| 45 |
return res |