[:space:] to bytes. :param s: size-string
:param scale: base size
"""
if not s:
return 0
if isinstance(s, (int, long)):
return s
match = re.match(r'^([\.\d]+)\s*([BbKkMmGgTtPpEeZzYy]?)', s)
if match is None:
raise ValueError(_('Invalid value: "%s"') % s)
groups = match.groups()
value = float(groups[0])
suffix = len(groups) > 1 and groups[1].upper() or 'B'
types = ('B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y')
for i, t in enumerate(types):
if suffix == t:
return int(value * pow(scale, i))
**** CubicPower OpenStack Study ****
def str2gib_size(s):
"""Covert size-string to size in gigabytes."""
size_in_bytes = str2size(s)
return size_in_bytes / units.GiB
**** CubicPower OpenStack Study ****
def get_rrmgr_cmd(src, dst, compression=None, tcp_buf_size=None,
connections=None):
"""Returns rrmgr command for source and destination."""
cmd = ['rrmgr', '-s', 'zfs']
if compression:
cmd.extend(['-c', '%s' % str(compression)])
cmd.append('-q')
cmd.append('-e')
if tcp_buf_size:
cmd.extend(['-w', str(tcp_buf_size)])
if connections:
cmd.extend(['-n', str(connections)])
cmd.extend([src, dst])
return ' '.join(cmd)
**** CubicPower OpenStack Study ****
def parse_nms_url(url):
"""Parse NMS url into normalized parts like scheme, user, host and others.
Example NMS URL:
auto://admin:nexenta@192.168.1.1:2000/
NMS URL parts:
auto True if url starts with auto://, protocol will be
automatically switched to https if http not
supported;
scheme (auto) connection protocol (http or https);
user (admin) NMS user;
password (nexenta) NMS password;
host (192.168.1.1) NMS host;
port (2000) NMS port.
:param url: url string
:return: tuple (auto, scheme, user, password, host, port, path)
"""
pr = urlparse.urlparse(url)
scheme = pr.scheme
auto = scheme == 'auto'
if auto:
scheme = 'http'
user = 'admin'
password = 'nexenta'
if '@' not in pr.netloc:
host_and_port = pr.netloc
else:
user_and_password, host_and_port = pr.netloc.split('@', 1)
if ':' in user_and_password:
user, password = user_and_password.split(':')
else:
user = user_and_password
if ':' in host_and_port:
host, port = host_and_port.split(':', 1)
else:
host, port = host_and_port, '2000'
return auto, scheme, user, password, host, port, '/rest/nms/'
**** CubicPower OpenStack Study ****
def get_migrate_snapshot_name(volume):
"""Return name for snapshot that will be used to migrate the volume."""
return 'cinder-migrate-snapshot-%(id)s' % volume