def _get_subnet(self, subnet_id): subnet = self.idl.dhcp_options_get(subnet_id).execute() # TODO: this: str(subnet.uuid) != str(subnet_id) # is a workaround for an ovsdbapp problem returning # random value for table with no indexing column specified when # no record for the given UUID was found. # Remove when issue is resolved. if not subnet or str(subnet.uuid) != str(subnet_id): raise ElementNotFoundError( 'Subnet {subnet} does not exist'.format(subnet=subnet_id)) if SubnetMapper.OVN_NETWORK_ID not in subnet.external_ids: raise ElementNotFoundError( 'Subnet {subnet} is not an ovirt manager subnet'.format( subnet=subnet_id)) return subnet
def _validate_create_routing_lsp_by_subnet(self, network_id, subnet_id, router_id=None): if not network_id: raise ElementNotFoundError( 'Unable to add router interface. ' 'Subnet {subnet_id} does not belong to any network'.format( subnet_id=subnet_id)) network_subnet = self._get_dhcp_by_network_id(network_id) if not network_subnet or str(network_subnet.uuid) != subnet_id: raise BadRequestError( 'Subnet {subnet_id} does not belong to network {network_id}'. format(subnet_id=subnet_id, network_id=network_id)) old_router_id = self._get_subnet_gateway_router_id(subnet_id) if old_router_id: if old_router_id == router_id: raise BadRequestError( 'Can not add subnet {subnet} to router {router}. Subnet is' ' already connected to this router'.format( subnet=subnet_id, router=router_id)) else: raise BadRequestError( 'Can not add subnet {subnet} to router. Subnet is' ' already connected to router {old_router}'.format( subnet=subnet_id, router=router_id, old_router=old_router_id))
def _validate_port_ip_for_router(self, port_ip, port, router_id): if not port_ip: raise ElementNotFoundError( 'Unable to attach port {port_id} to router ' '{router_id}. ' 'Attaching by port requires the port to have ' 'an ip from subnet assigned.'.format(port_id=port.uuid, router_id=router_id))
def _get_router(self, router_id): # TODO: LrGet is not yet implemented by ovsdbapp # patch pending: https://review.openstack.org/#/c/505517/ # replace once patch is accepted try: return self.idl.lookup(ovnconst.TABLE_LR, router_id) except RowNotFound: raise ElementNotFoundError( 'Router {router} does not exist'.format(router=router_id))
def attach_network_to_router_by_subnet(subnet, network_id, router_id): subnet_gateway = subnet.options.get('router') if not subnet_gateway: raise ElementNotFoundError( 'Unable to attach network {network_id} to router ' '{router_id} by subnet {subnet_id}.' 'Attaching by subnet requires the subnet to have ' 'a default gateway specified.'.format(network_id=network_id, subnet_id=subnet.uuid, router_id=router_id))
def _get_port_ip(self, port, router_id): port_addresses = port.dynamic_addresses if not port_addresses: raise ElementNotFoundError( 'Unable to attach port {port_id} to router ' '{router_id}. ' 'Attaching by port requires the port to have ' 'an ip from subnet assigned.'.format(port_id=port.uuid, router_id=router_id)) return port_addresses[0].split(' ')[1]
def _get_ip_from_port(self, port, router_id): port_ip = self._get_port_ip(port, router_id) network = self._get_port_network(port) network_cidr = network.other_config.get(NetworkMapper.OVN_SUBNET) if not network_cidr: raise ElementNotFoundError( 'Unable to attach port {port_id} to router ' '{router_id}. ' 'Attaching by port requires the port\'s network ' 'to have a subnet attached.'.format(port_id=port.uuid, router_id=router_id)) network_netmask = network_cidr.split('/')[1] return '{ip}/{netmask}'.format(ip=port_ip, netmask=network_netmask)
def _get_ip_from_subnet(self, subnet, network_id, router_id): subnet_gateway = subnet.options.get('router') if not subnet_gateway: raise ElementNotFoundError( 'Unable to attach network {network_id} to router ' '{router_id} by subnet {subnet_id}.' 'Attaching by subnet requires the subnet to have ' 'a default gateway specified.'.format(network_id=network_id, subnet_id=subnet.uuid, router_id=router_id)) subnet_netmask = subnet.cidr.split('/')[1] return '{ip}/{netmask}'.format(ip=subnet_gateway, netmask=subnet_netmask)
def _get_lrp(self, lrp): try: return self.idl.lookup(ovnconst.TABLE_LRP, lrp) except RowNotFound: raise ElementNotFoundError( 'Logical router port {port} does not exist'.format(port=lrp))
def _get_network(self, network_id): network = self.idl.ls_get(network_id).execute() if not network: raise ElementNotFoundError( 'Network {network} does not exist'.format(network=network_id)) return network
def _validate_router_exists(self, router_id): try: self.idl.lookup(ovnconst.TABLE_LR, router_id) except RowNotFound: raise ElementNotFoundError( 'Router {router} does not exist'.format(router=router_id))
def _get_switch_port(self, port_id): port = self.idl.lsp_get(port_id).execute() if not port: raise ElementNotFoundError( 'Port {port} does not exist'.format(port=port_id)) return port