Ejemplo n.º 1
0
def get_iscsi_connection_properties(lun_id, volume, iqns, addresses, ports):
    # literal ipv6 address
    addresses = [
        netutils.escape_ipv6(a) if netutils.is_valid_ipv6(a) else a
        for a in addresses
    ]

    lun_id = int(lun_id)
    if isinstance(iqns, str):
        iqns = [iqns] * len(addresses)

    target_portals = ['%s:%s' % (a, p) for a, p in zip(addresses, ports)]

    properties = {}
    properties['target_discovered'] = False
    properties['target_portal'] = target_portals[0]
    properties['target_iqn'] = iqns[0]
    properties['target_lun'] = lun_id
    properties['volume_id'] = volume['id']
    if len(addresses) > 1:
        properties['target_portals'] = target_portals
        properties['target_iqns'] = iqns
        properties['target_luns'] = [lun_id] * len(addresses)

    auth = volume['provider_auth']
    if auth:
        (auth_method, auth_username, auth_secret) = auth.split()
        properties['auth_method'] = auth_method
        properties['auth_username'] = auth_username
        properties['auth_password'] = auth_secret
    return {
        'driver_volume_type': 'iscsi',
        'data': properties,
    }
Ejemplo n.º 2
0
    def _get_url(self):
        host = self._host

        if netutils.is_valid_ipv6(host):
            host = netutils.escape_ipv6(host)

        return '%s://%s:%s/%s' % (self._protocol, host, self._port, self._url)
Ejemplo n.º 3
0
def get_iscsi_connection_properties(lun_id, volume, iqns,
                                    addresses, ports):
    # literal ipv6 address
    addresses = [netutils.escape_ipv6(a) if netutils.is_valid_ipv6(a) else a
                 for a in addresses]

    lun_id = int(lun_id)
    if isinstance(iqns, six.string_types):
        iqns = [iqns] * len(addresses)

    target_portals = ['%s:%s' % (a, p) for a, p in zip(addresses, ports)]

    properties = {}
    properties['target_discovered'] = False
    properties['target_portal'] = target_portals[0]
    properties['target_iqn'] = iqns[0]
    properties['target_lun'] = lun_id
    properties['volume_id'] = volume['id']
    if len(addresses) > 1:
        properties['target_portals'] = target_portals
        properties['target_iqns'] = iqns
        properties['target_luns'] = [lun_id] * len(addresses)

    auth = volume['provider_auth']
    if auth:
        (auth_method, auth_username, auth_secret) = auth.split()
        properties['auth_method'] = auth_method
        properties['auth_username'] = auth_username
        properties['auth_password'] = auth_secret
    return {
        'driver_volume_type': 'iscsi',
        'data': properties,
    }
Ejemplo n.º 4
0
Archivo: api.py Proyecto: mahak/cinder
    def _get_url(self):
        host = self._host

        if netutils.is_valid_ipv6(host):
            host = netutils.escape_ipv6(host)

        return '%s://%s:%s/%s' % (self._protocol, host, self._port,
                                  self._url)
Ejemplo n.º 5
0
    def _get_volume_location(self, volume_id):
        """Returns NFS mount address as <nfs_ip_address>:<nfs_mount_dir>."""
        provider_location = self._get_provider_location(volume_id)
        nfs_server_ip, export_path = na_utils.get_export_host_junction_path(
            provider_location)

        if netutils.is_valid_ipv6(nfs_server_ip):
            nfs_server_ip = netutils.escape_ipv6(nfs_server_ip)

        return nfs_server_ip + ':' + export_path
Ejemplo n.º 6
0
    def _get_volume_location(self, volume_id):
        """Returns NFS mount address as <nfs_ip_address>:<nfs_mount_dir>."""
        provider_location = self._get_provider_location(volume_id)
        nfs_server_ip, export_path = na_utils.get_export_host_junction_path(
            provider_location)

        if netutils.is_valid_ipv6(nfs_server_ip):
            nfs_server_ip = netutils.escape_ipv6(nfs_server_ip)

        return nfs_server_ip + ':' + export_path
Ejemplo n.º 7
0
    def test__get_url(self, host):
        port = '80'
        root = netapp_api.NaServer(host, port=port)

        protocol = root.TRANSPORT_TYPE_HTTP
        url = root.URL_FILER

        if netutils.is_valid_ipv6(host):
            host = netutils.escape_ipv6(host)

        result = '%s://%s:%s/%s' % (protocol, host, port, url)

        url = root._get_url()

        self.assertEqual(result, url)
Ejemplo n.º 8
0
    def test__get_url(self, host):
        port = '80'
        root = netapp_api.NaServer(host, port=port)

        protocol = root.TRANSPORT_TYPE_HTTP
        url = root.URL_FILER

        if netutils.is_valid_ipv6(host):
            host = netutils.escape_ipv6(host)

        result = '%s://%s:%s/%s' % (protocol, host, port, url)

        url = root._get_url()

        self.assertEqual(result, url)
Ejemplo n.º 9
0
    def _request(self, context, method, cast=False, version=None, **kwargs):
        """Call conductor RPC.

        Versioned objects are automatically serialized and deserialized.

        :param context: Security context.
        :param method: Method name.
        :param cast: If true, use a JSON RPC notification.
        :param version: RPC API version to use.
        :param kwargs: Keyword arguments to pass.
        :return: RPC result (if any).
        """
        params = {
            key: self.serializer.serialize_entity(context, value)
            for key, value in kwargs.items()
        }
        params['context'] = context.to_dict()

        if version is None:
            version = self.version
        if version is not None:
            _check_version(version, self.version_cap)
            params['rpc.version'] = version

        body = {
            "jsonrpc": "2.0",
            "method": method,
            "params": params,
        }
        if not cast:
            body['id'] = context.request_id or uuidutils.generate_uuid()

        LOG.debug("RPC %s with %s", method, strutils.mask_dict_password(body))
        scheme = 'http'
        if CONF.json_rpc.use_ssl:
            scheme = 'https'
        url = '%s://%s:%d' % (scheme, netutils.escape_ipv6(
            self.host), CONF.json_rpc.port)
        result = _get_session().post(url, json=body)
        LOG.debug('RPC %s returned %s', method,
                  strutils.mask_password(result.text or '<None>'))

        if not cast:
            result = result.json()
            self._handle_error(result.get('error'))
            result = self.serializer.deserialize_entity(
                context, result['result'])
            return result
Ejemplo n.º 10
0
def get_iscsi_connection_properties(lun_id, volume, iqn, address, port):
    # literal ipv6 address
    if netutils.is_valid_ipv6(address):
        address = netutils.escape_ipv6(address)

    properties = {}
    properties['target_discovered'] = False
    properties['target_portal'] = '%s:%s' % (address, port)
    properties['target_iqn'] = iqn
    properties['target_lun'] = int(lun_id)
    properties['volume_id'] = volume['id']
    auth = volume['provider_auth']
    if auth:
        (auth_method, auth_username, auth_secret) = auth.split()
        properties['auth_method'] = auth_method
        properties['auth_username'] = auth_username
        properties['auth_password'] = auth_secret
    return {
        'driver_volume_type': 'iscsi',
        'data': properties,
    }
Ejemplo n.º 11
0
 def test_escape_ipv6(self):
     self.assertEqual('[1234::1234]', netutils.escape_ipv6('1234::1234'))
     self.assertEqual('127.0.0.1', netutils.escape_ipv6('127.0.0.1'))
Ejemplo n.º 12
0
from oslo_utils import netutils

print(netutils.escape_ipv6('fe80::f493:20ff:fe5b:6cf'))

print(
    netutils.get_ipv6_addr_by_EUI64('fe80::d480:b0ff:fe33:1543/64',
                                    'f2:2c:d8:c3:73:fb'))

print(netutils.get_my_ipv4())

print(netutils.is_ipv6_enabled())

print(netutils.is_valid_cidr('10.10.10.10/24'))

code_list = []
for n in range(-5, 5):
    code_list.append(netutils.is_valid_icmp_code(n))
print(code_list)

print(
    netutils.urlsplit(
        'https://foxfox.mybluemix.net.com:8443/index.html?auto=off'))
# SplitResult(scheme='https', netloc='foxfox.mybluemix.net.com:8443', path='/index.html', query='auto=off', fragment='')