示例#1
0
    def test_get_transport_url_null(self, mock_url):
        mock_url.parse.return_value = 'foo'

        url = rpc.get_transport_url()

        self.assertEqual('foo', url)
        mock_url.parse.assert_called_once_with(rpc.CONF, None)
示例#2
0
文件: manage.py 项目: mba811/nova
    def create(self,
               name,
               cell_type='child',
               username=None,
               password=None,
               hostname=None,
               port=None,
               virtual_host=None,
               woffset=None,
               wscale=None):

        if cell_type not in ['parent', 'child']:
            print("Error: cell type must be 'parent' or 'child'")
            return (2)

        # Set up the transport URL
        transport_host = messaging.TransportHost(hostname=hostname,
                                                 port=int(port),
                                                 username=username,
                                                 password=password)

        transport_url = rpc.get_transport_url()
        transport_url.hosts.append(transport_host)
        transport_url.virtual_host = virtual_host

        is_parent = cell_type == 'parent'
        values = {
            'name': name,
            'is_parent': is_parent,
            'transport_url': str(transport_url),
            'weight_offset': float(woffset),
            'weight_scale': float(wscale)
        }
        ctxt = context.get_admin_context()
        db.cell_create(ctxt, values)
示例#3
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_url = rpc.get_transport_url(transport_url)
    except messaging.InvalidTransportURL:
        # Just go with None's
        for key in keys:
            cell_info.setdefault(key, None)
        return

    if not transport_url.hosts:
        return

    transport_host = transport_url.hosts[0]

    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] = getattr(transport_host, transport_field)
示例#4
0
文件: manage.py 项目: RibeiroAna/nova
    def create(self, name, cell_type='child', username=None, password=None,
               hostname=None, port=None, virtual_host=None,
               woffset=None, wscale=None):

        if cell_type not in ['parent', 'child']:
            print("Error: cell type must be 'parent' or 'child'")
            return(2)

        # Set up the transport URL
        transport_host = messaging.TransportHost(hostname=hostname,
                                                 port=int(port),
                                                 username=username,
                                                 password=password)

        transport_url = rpc.get_transport_url()
        transport_url.hosts.append(transport_host)
        transport_url.virtual_host = virtual_host

        is_parent = cell_type == 'parent'
        values = {'name': name,
                  'is_parent': is_parent,
                  'transport_url': str(transport_url),
                  'weight_offset': float(woffset),
                  'weight_scale': float(wscale)}
        ctxt = context.get_admin_context()
        db.cell_create(ctxt, values)
示例#5
0
文件: cells.py 项目: dtroyer/nova
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_url = rpc.get_transport_url(transport_url)
    except messaging.InvalidTransportURL:
        # Just go with None's
        for key in keys:
            cell_info.setdefault(key, None)
        return

    if not transport_url.hosts:
        return

    transport_host = transport_url.hosts[0]

    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] = getattr(transport_host, transport_field)
示例#6
0
文件: test_rpc.py 项目: mahak/nova
    def test_get_transport_url_null(self, mock_url):
        mock_url.parse.return_value = 'foo'

        url = rpc.get_transport_url()

        self.assertEqual('foo', url)
        mock_url.parse.assert_called_once_with(rpc.CONF, None)
示例#7
0
文件: test_rpc.py 项目: hanlind/nova
    def test_get_transport_url_null(self, mock_url):
        conf = mock.Mock()
        rpc.CONF = conf
        mock_url.parse.return_value = "foo"

        url = rpc.get_transport_url()

        self.assertEqual("foo", url)
        mock_url.parse.assert_called_once_with(conf, None, rpc.TRANSPORT_ALIASES)
示例#8
0
    def test_get_transport_url(self, mock_url):
        conf = mock.Mock()
        rpc.CONF = conf
        mock_url.parse.return_value = 'foo'

        url = rpc.get_transport_url(url_str='bar')

        self.assertEqual('foo', url)
        mock_url.parse.assert_called_once_with(conf, 'bar')
示例#9
0
文件: test_rpc.py 项目: andymcc/nova
    def test_get_transport_url(self, mock_url):
        conf = mock.Mock()
        rpc.CONF = conf
        mock_url.parse.return_value = 'foo'

        url = rpc.get_transport_url(url_str='bar')

        self.assertEqual('foo', url)
        mock_url.parse.assert_called_once_with(conf, 'bar')
示例#10
0
文件: test_rpc.py 项目: haris00/nova
    def test_get_transport_url_null(self, mock_url):
        conf = mock.Mock()
        rpc.CONF = conf
        mock_url.parse.return_value = 'foo'

        url = rpc.get_transport_url()

        self.assertEqual('foo', url)
        mock_url.parse.assert_called_once_with(conf, None,
                                               rpc.TRANSPORT_ALIASES)
示例#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 = rpc.get_transport_url(self.db_info["transport_url"])
            if url.hosts:
                for field, canonical in url_fields_to_return.items():
                    cell_info[canonical] = getattr(url.hosts[0], field)
        return cell_info
示例#12
0
文件: cells.py 项目: dtroyer/nova
    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_url = existing.get('transport_url') if existing else None
        transport_url = rpc.get_transport_url(transport_url)

        if 'rpc_virtual_host' in cell:
            transport_url.virtual_host = cell.pop('rpc_virtual_host')

        if not transport_url.hosts:
            transport_url.hosts.append(messaging.TransportHost())
        transport_host = transport_url.hosts[0]
        if cell.get('rpc_port') is not None:
            try:
                cell['rpc_port'] = int(cell['rpc_port'])
            except ValueError:
                raise exc.HTTPBadRequest(
                    explanation=_('rpc_port must be integer'))
        # Copy over the input fields
        transport_field_map = {
            'username': '******',
            'password': '******',
            'hostname': 'rpc_host',
            'port': 'rpc_port',
        }
        for key, input_field in transport_field_map.items():
            # Only override the value if we're given an override
            if input_field in cell:
                setattr(transport_host, key, cell.pop(input_field))

        # Now set the transport URL
        cell['transport_url'] = str(transport_url)
示例#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_url = existing.get('transport_url') if existing else None
        transport_url = rpc.get_transport_url(transport_url)

        if 'rpc_virtual_host' in cell:
            transport_url.virtual_host = cell.pop('rpc_virtual_host')

        if not transport_url.hosts:
            transport_url.hosts.append(messaging.TransportHost())
        transport_host = transport_url.hosts[0]
        if cell.get('rpc_port') is not None:
            try:
                cell['rpc_port'] = int(cell['rpc_port'])
            except ValueError:
                raise exc.HTTPBadRequest(
                    explanation=_('rpc_port must be integer'))
        # Copy over the input fields
        transport_field_map = {
            'username': '******',
            'password': '******',
            'hostname': 'rpc_host',
            'port': 'rpc_port',
        }
        for key, input_field in transport_field_map.items():
            # Only override the value if we're given an override
            if input_field in cell:
                setattr(transport_host, key, cell.pop(input_field))

        # Now set the transport URL
        cell['transport_url'] = str(transport_url)
示例#14
0
文件: manage.py 项目: mba811/nova
 def list(self):
     ctxt = context.get_admin_context()
     cells = db.cell_get_all(ctxt)
     fmt = "%3s  %-10s  %-6s  %-10s  %-15s  %-5s  %-10s"
     print(fmt %
           ('Id', 'Name', 'Type', 'Username', 'Hostname', 'Port', 'VHost'))
     print(fmt % ('-' * 3, '-' * 10, '-' * 6, '-' * 10, '-' * 15, '-' * 5,
                  '-' * 10))
     for cell in cells:
         url = rpc.get_transport_url(cell.transport_url)
         host = url.hosts[0] if url.hosts else messaging.TransportHost()
         print(fmt %
               (cell.id, cell.name, 'parent' if cell.is_parent else 'child',
                host.username, host.hostname, host.port, url.virtual_host))
     print(fmt % ('-' * 3, '-' * 10, '-' * 6, '-' * 10, '-' * 15, '-' * 5,
                  '-' * 10))
示例#15
0
文件: manage.py 项目: RibeiroAna/nova
 def list(self):
     ctxt = context.get_admin_context()
     cells = db.cell_get_all(ctxt)
     fmt = "%3s  %-10s  %-6s  %-10s  %-15s  %-5s  %-10s"
     print(fmt % ('Id', 'Name', 'Type', 'Username', 'Hostname',
             'Port', 'VHost'))
     print(fmt % ('-' * 3, '-' * 10, '-' * 6, '-' * 10, '-' * 15,
             '-' * 5, '-' * 10))
     for cell in cells:
         url = rpc.get_transport_url(cell.transport_url)
         host = url.hosts[0] if url.hosts else messaging.TransportHost()
         print(fmt % (cell.id, cell.name,
                 'parent' if cell.is_parent else 'child',
                 host.username, host.hostname,
                 host.port, url.virtual_host))
     print(fmt % ('-' * 3, '-' * 10, '-' * 6, '-' * 10, '-' * 15,
             '-' * 5, '-' * 10))
示例#16
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 = rpc.get_transport_url(self.db_info['transport_url'])
            if url.hosts:
                for field, canonical in url_fields_to_return.items():
                    cell_info[canonical] = getattr(url.hosts[0], field)
        return cell_info
示例#17
0
文件: state.py 项目: FengYang/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 = rpc.get_transport_url(self.db_info['transport_url'])
            if url.hosts:
                for field, canonical in url_fields_to_return.items():
                    cell_info[canonical] = getattr(url.hosts[0], field)
        return cell_info
示例#18
0
文件: cells.py 项目: ramielrowe/nova
    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_url = existing.get("transport_url") if existing else None
        transport_url = rpc.get_transport_url(transport_url)

        if "rpc_virtual_host" in cell:
            transport_url.virtual_host = cell.pop("rpc_virtual_host")

        if not transport_url.hosts:
            transport_url.hosts.append(messaging.TransportHost())
        transport_host = transport_url.hosts[0]

        # Copy over the input fields
        transport_field_map = {
            "username": "******",
            "password": "******",
            "hostname": "rpc_host",
            "port": "rpc_port",
        }
        for key, input_field in transport_field_map.items():
            # Only override the value if we're given an override
            if input_field in cell:
                setattr(transport_host, key, cell.pop(input_field))

        # Now set the transport URL
        cell["transport_url"] = str(transport_url)
示例#19
0
 def insecure_transport_url(url):
     transport_url = rpc.get_transport_url(url)
     transport_url.hosts[0].password = None
     return str(transport_url)
示例#20
0
 def insecure_transport_url(url):
     transport_url = rpc.get_transport_url(url)
     transport_url.hosts[0].password = None
     return str(transport_url)