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)
def setUp(self): super(TestFailover, self).setUp() self._brokers = [FakeBroker(), FakeBroker()] hosts = [] for broker in self._brokers: hosts.append(messaging.TransportHost(hostname=broker.host, port=broker.port)) self._broker_url = messaging.TransportURL(self.conf, transport="amqp", hosts=hosts)
def test_parse_url(self): self.config(rpc_backend=self.rpc_backend) hosts = [] for host in self.hosts: hosts.append( messaging.TransportHost(host.get('hostname'), host.get('port'), host.get('username'), host.get('password'))) url = messaging.TransportURL(self.conf, self.transport, self.virtual_host, hosts, self.aliases) self.assertEqual(self.expected, str(url))
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 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))
def test_parse_url(self): self.config(rpc_backend=None) url = messaging.TransportURL.parse(self.conf, self.url, self.aliases) hosts = [] for host in self.expect.get('hosts', []): hosts.append( messaging.TransportHost(host.get('host'), host.get('port'), host.get('username'), host.get('password'))) expected = messaging.TransportURL(self.conf, self.expect.get('transport'), self.expect.get('virtual_host'), hosts) self.assertEqual(expected, url)