From 127fc7505c04614e67d14bd1a279c09f5a533f67 Mon Sep 17 00:00:00 2001 From: Chang Bo Guo Date: Sun, 3 Nov 2013 05:21:47 -0800 Subject: [PATCH] Sync units module from olso There are lots of numeric expressions across some projects, such as 1024*1024 , 1024**3, 1000, 1000000 etc. This patch adds binary and decimal unit constants. Replacing nummeric experssions with these constants makes code more readable. Change-Id: I45fb5a10009f22b1eedb07b3e52f1ce40403b068 --- glance/openstack/common/units.py | 40 ++++++++++++++++++++++++++++++++ openstack-common.conf | 1 + 2 files changed, 41 insertions(+) create mode 100644 glance/openstack/common/units.py diff --git a/glance/openstack/common/units.py b/glance/openstack/common/units.py new file mode 100644 index 0000000000..71f78aeb19 --- /dev/null +++ b/glance/openstack/common/units.py @@ -0,0 +1,40 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 IBM Corp +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +""" +Unit constants +""" + +#Binary unit constants. +Ki = 1024 +Mi = 1024 ** 2 +Gi = 1024 ** 3 +Ti = 1024 ** 4 +Pi = 1024 ** 5 +Ei = 1024 ** 6 +Zi = 1024 ** 7 +Yi = 1024 ** 8 + +#Decimal unit constants. +k = 1000 +M = 1000 ** 2 +G = 1000 ** 3 +T = 1000 ** 4 +P = 1000 ** 5 +E = 1000 ** 6 +Z = 1000 ** 7 +Y = 1000 ** 8 diff --git a/openstack-common.conf b/openstack-common.conf index 48aaf7d895..ab3270e81a 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -13,6 +13,7 @@ module=notifier module=policy module=strutils module=timeutils +module=units module=uuidutils # The base module to hold the copy of openstack.common