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)
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)
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
def insecure_transport_url(url): transport_url = rpc.get_transport_url(url) transport_url.hosts[0].password = None return str(transport_url)