Clinton Knight 49e3d1441c Refactoring to allow addition of NetApp FibreChannel drivers
NetApp's five Cinder drivers have been in continuous development
for nearly 3 years, and it is now necessary to do some house-
cleaning.  This commit splits long files that contain multiple
classes, fixes the class hierarchies to enable subclassing
different driver classes (ISCSIDriver, FibreChannelDriver),
and renames classes.  It also begins the process of moving
unit test files into a matching hierarchy in the "tests" tree.

Implements blueprint netapp-cinder-driver-refactoring-phase-1
Change-Id: I9b067a8322a676c4c95d5045cb2e78979be9ba5b
2014-11-24 10:48:08 -05:00

53 lines
1.6 KiB
Python

# Copyright (c) 2014 Navneet Singh. All rights reserved.
# Copyright (c) 2014 Clinton Knight. 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.
"""
Utilities for NetApp E-series drivers.
"""
import base64
import binascii
import uuid
import six
from cinder.openstack.common import log as logging
LOG = logging.getLogger(__name__)
def encode_hex_to_base32(hex_string):
"""Encodes hex to base32 bit as per RFC4648."""
bin_form = binascii.unhexlify(hex_string)
return base64.b32encode(bin_form)
def decode_base32_to_hex(base32_string):
"""Decodes base32 string to hex string."""
bin_form = base64.b32decode(base32_string)
return binascii.hexlify(bin_form)
def convert_uuid_to_es_fmt(uuid_str):
"""Converts uuid to e-series compatible name format."""
uuid_base32 = encode_hex_to_base32(uuid.UUID(six.text_type(uuid_str)).hex)
return uuid_base32.strip('=')
def convert_es_fmt_to_uuid(es_label):
"""Converts e-series name format to uuid."""
es_label_b32 = es_label.ljust(32, '=')
return uuid.UUID(binascii.hexlify(base64.b32decode(es_label_b32)))