Esempio n. 1
0
def _fixup_cell_info(cell_info, keys):
    """
    If the transport_url is present in the cell, derive username,
    rpc_host, and rpc_port from it.
    """

    if 'transport_url' not in cell_info:
        return

    # Disassemble the transport URL
    transport_url = cell_info.pop('transport_url')
    try:
        transport = rpc_driver.parse_transport_url(transport_url)
    except ValueError:
        # Just go with None's
        for key in keys:
            cell_info.setdefault(key, None)
        return cell_info

    transport_field_map = {'rpc_host': 'hostname', 'rpc_port': 'port'}
    for key in keys:
        if key in cell_info:
            continue

        transport_field = transport_field_map.get(key, key)
        cell_info[key] = transport[transport_field]
Esempio n. 2
0
def _fixup_cell_info(cell_info, keys):
    """
    If the transport_url is present in the cell, derive username,
    rpc_host, and rpc_port from it.
    """

    if 'transport_url' not in cell_info:
        return

    # Disassemble the transport URL
    transport_url = cell_info.pop('transport_url')
    try:
        transport = rpc_driver.parse_transport_url(transport_url)
    except ValueError:
        # Just go with None's
        for key in keys:
            cell_info.setdefault(key, None)
        return cell_info

    transport_field_map = {'rpc_host': 'hostname', 'rpc_port': 'port'}
    for key in keys:
        if key in cell_info:
            continue

        transport_field = transport_field_map.get(key, key)
        cell_info[key] = transport[transport_field]
    def test_normal_ipv6_parsing_no_port(self):
        url = "rabbit://us%65r:p%61ss@[ffff::1]/virtual%5fhost"

        result = rpc_driver.parse_transport_url(url)

        self.assertEqual(result, {
            'username': '******',
            'password': '******',
            'hostname': 'ffff::1',
            'port': None,
            'virtual_host': 'virtual_host',
        })
    def test_normal_parsing(self):
        url = "rabbit://us%65r:p%[email protected]:10/virtual%5fhost"

        result = rpc_driver.parse_transport_url(url)

        self.assertEqual(result, {
            'username': '******',
            'password': '******',
            'hostname': 'host.example.com',
            'port': 10,
            'virtual_host': 'virtual_host',
        })
    def test_empty(self):
        url = "rabbit:"

        result = rpc_driver.parse_transport_url(url)

        self.assertEqual(result, {
            'username': None,
            'password': None,
            'hostname': None,
            'port': None,
            'virtual_host': None,
        })
Esempio n. 6
0
    def test_normal_parsing(self):
        url = "rabbit://us%65r:p%[email protected]:10/virtual%5fhost"

        result = rpc_driver.parse_transport_url(url)

        self.assertEqual(
            result, {
                'username': '******',
                'password': '******',
                'hostname': 'host.example.com',
                'port': 10,
                'virtual_host': 'virtual_host',
            })
Esempio n. 7
0
    def test_normal_ipv6_parsing_no_port(self):
        url = "rabbit://us%65r:p%61ss@[ffff::1]/virtual%5fhost"

        result = rpc_driver.parse_transport_url(url)

        self.assertEqual(
            result, {
                'username': '******',
                'password': '******',
                'hostname': 'ffff::1',
                'port': None,
                'virtual_host': 'virtual_host',
            })
Esempio n. 8
0
File: state.py Progetto: osrg/nova
    def get_cell_info(self):
        """Return subset of cell information for OS API use."""
        db_fields_to_return = ["is_parent", "weight_scale", "weight_offset"]
        url_fields_to_return = {"username": "******", "hostname": "rpc_host", "port": "rpc_port"}
        cell_info = dict(name=self.name, capabilities=self.capabilities)
        if self.db_info:
            for field in db_fields_to_return:
                cell_info[field] = self.db_info[field]

            url_info = rpc_driver.parse_transport_url(self.db_info["transport_url"])
            for field, canonical in url_fields_to_return.items():
                cell_info[canonical] = url_info[field]
        return cell_info
Esempio n. 9
0
    def test_empty(self):
        url = "rabbit:"

        result = rpc_driver.parse_transport_url(url)

        self.assertEqual(
            result, {
                'username': None,
                'password': None,
                'hostname': None,
                'port': None,
                'virtual_host': None,
            })
    def get_cell_info(self):
        """Return subset of cell information for OS API use."""
        db_fields_to_return = ['is_parent', 'weight_scale', 'weight_offset']
        url_fields_to_return = {
            'username': '******',
            'hostname': 'rpc_host',
            'port': 'rpc_port',
        }
        cell_info = dict(name=self.name, capabilities=self.capabilities)
        if self.db_info:
            for field in db_fields_to_return:
                cell_info[field] = self.db_info[field]

            url_info = rpc_driver.parse_transport_url(
                self.db_info['transport_url'])
            for field, canonical in url_fields_to_return.items():
                cell_info[canonical] = url_info[field]
        return cell_info
Esempio n. 11
0
    def get_cell_info(self):
        """Return subset of cell information for OS API use."""
        db_fields_to_return = ['is_parent', 'weight_scale', 'weight_offset']
        url_fields_to_return = {
            'username': '******',
            'hostname': 'rpc_host',
            'port': 'rpc_port',
        }
        cell_info = dict(name=self.name, capabilities=self.capabilities)
        if self.db_info:
            for field in db_fields_to_return:
                cell_info[field] = self.db_info[field]

            url_info = rpc_driver.parse_transport_url(
                self.db_info['transport_url'])
            for field, canonical in url_fields_to_return.items():
                cell_info[canonical] = url_info[field]
        return cell_info
Esempio n. 12
0
    def _normalize_cell(self, cell, existing=None):
        """
        Normalize input cell data.  Normalizations include:

        * Converting cell['type'] to is_parent boolean.
        * Merging existing transport URL with transport information.
        """

        # Start with the cell type conversion
        if 'type' in cell:
            self._validate_cell_type(cell['type'])
            cell['is_parent'] = cell['type'] == 'parent'
            del cell['type']
        # Avoid cell type being overwritten to 'child'
        elif existing:
            cell['is_parent'] = existing['is_parent']
        else:
            cell['is_parent'] = False

        # Now we disassemble the existing transport URL...
        transport = {}
        if existing and 'transport_url' in existing:
            transport = rpc_driver.parse_transport_url(
                existing['transport_url'])

        # Copy over the input fields
        transport_field_map = {
            'username': '******',
            'password': '******',
            'hostname': 'rpc_host',
            'port': 'rpc_port',
            'virtual_host': 'rpc_virtual_host',
        }
        for key, input_field in transport_field_map.items():
            # Set the default value of the field; using setdefault()
            # lets us avoid overriding the existing transport URL
            transport.setdefault(key, None)

            # Only override the value if we're given an override
            if input_field in cell:
                transport[key] = cell.pop(input_field)

        # Now set the transport URL
        cell['transport_url'] = rpc_driver.unparse_transport_url(transport)
Esempio n. 13
0
    def _normalize_cell(self, cell, existing=None):
        """
        Normalize input cell data.  Normalizations include:

        * Converting cell['type'] to is_parent boolean.
        * Merging existing transport URL with transport information.
        """

        # Start with the cell type conversion
        if 'type' in cell:
            self._validate_cell_type(cell['type'])
            cell['is_parent'] = cell['type'] == 'parent'
            del cell['type']
        # Avoid cell type being overwritten to 'child'
        elif existing:
            cell['is_parent'] = existing['is_parent']
        else:
            cell['is_parent'] = False

        # Now we disassemble the existing transport URL...
        transport = {}
        if existing and 'transport_url' in existing:
            transport = rpc_driver.parse_transport_url(
                existing['transport_url'])

        # Copy over the input fields
        transport_field_map = {
            'username': '******',
            'password': '******',
            'hostname': 'rpc_host',
            'port': 'rpc_port',
            'virtual_host': 'rpc_virtual_host',
        }
        for key, input_field in transport_field_map.items():
            # Set the default value of the field; using setdefault()
            # lets us avoid overriding the existing transport URL
            transport.setdefault(key, None)

            # Only override the value if we're given an override
            if input_field in cell:
                transport[key] = cell.pop(input_field)

        # Now set the transport URL
        cell['transport_url'] = rpc_driver.unparse_transport_url(transport)
Esempio n. 14
0
def downgrade_cell_data(table):
    columns = ['id', 'name', 'transport_url']
    query = select([get_column(table, c) for c in columns])
    for row in [dict(zip(columns, result)) for result in query.execute()]:
        # Disassemble the transport URL
        transport_data = {}
        try:
            transport = rpc_driver.parse_transport_url(row['transport_url'])

            for key, value in transport.items():
                if not value:
                    # Ignore empty values
                    continue
                transport_data[field_map.get(key, key)] = value
        except ValueError as exc:
            # We failed to parse the transport URL, so don't set up
            # any transport data
            LOG.warning(_('Failed to downgrade cell %(name)s: %(error)s') %
                        dict(name=row['name'], error=str(exc)))

        if transport_data:
            table.update().where(table.c.id == row['id']).\
                values(**transport_data).execute()
def downgrade_cell_data(table):
    columns = ['id', 'name', 'transport_url']
    query = select([get_column(table, c) for c in columns])
    for row in [dict(zip(columns, result)) for result in query.execute()]:
        # Disassemble the transport URL
        transport_data = {}
        try:
            transport = rpc_driver.parse_transport_url(row['transport_url'])

            for key, value in transport.items():
                if not value:
                    # Ignore empty values
                    continue
                transport_data[field_map.get(key, key)] = value
        except ValueError as exc:
            # We failed to parse the transport URL, so don't set up
            # any transport data
            LOG.warning(_('Failed to downgrade cell %(name)s: %(error)s') %
                        dict(name=row['name'], error=str(exc)))

        if transport_data:
            table.update().where(table.c.id == row['id']).\
                values(**transport_data).execute()
Esempio n. 16
0
 def insecure_transport_url(url):
     transport = rpc_driver.parse_transport_url(url)
     return rpc_driver.unparse_transport_url(transport, False)
Esempio n. 17
0
 def insecure_transport_url(url):
     transport = rpc_driver.parse_transport_url(url)
     return rpc_driver.unparse_transport_url(transport, False)