def _handler(self, client_sock, client_addr): """Handle incoming lease relay stream connection. This method will only read the first 1024 bytes and then close the connection. The limit exists to limit the impact of misbehaving clients. """ try: msg = client_sock.recv(1024) data = jsonutils.loads(msg) client_sock.close() network_id = data['network_id'] if not uuidutils.is_uuid_like(network_id): raise ValueError( _("Network ID %s is not a valid UUID") % network_id) ip_address = str(netaddr.IPAddress(data['ip_address'])) lease_remaining = int(data['lease_remaining']) self.callback(network_id, ip_address, lease_remaining) except ValueError as e: LOG.warn(_('Unable to parse lease relay msg to dict.')) LOG.warn(_('Exception value: %s'), e) LOG.warn(_('Message representation: %s'), repr(msg)) except Exception as e: LOG.exception(_('Unable update lease. Exception'))
def _handler(self, client_sock, client_addr): """Handle incoming lease relay stream connection. This method will only read the first 1024 bytes and then close the connection. The limit exists to limit the impact of misbehaving clients. """ try: msg = client_sock.recv(1024) data = jsonutils.loads(msg) client_sock.close() network_id = data['network_id'] if not uuidutils.is_uuid_like(network_id): raise ValueError(_("Network ID %s is not a valid UUID") % network_id) ip_address = str(netaddr.IPAddress(data['ip_address'])) lease_remaining = int(data['lease_remaining']) self.callback(network_id, ip_address, lease_remaining) except ValueError as e: LOG.warn(_('Unable to parse lease relay msg to dict.')) LOG.warn(_('Exception value: %s'), e) LOG.warn(_('Message representation: %s'), repr(msg)) except Exception as e: LOG.exception(_('Unable update lease. Exception'))
def _validate_uuid(data, valid_values=None): if uuidutils.is_uuid_like(data): return else: msg = _("%s is not a valid UUID") % data LOG.debug("validate_uuid: %s", msg) return msg
def convert_to_uuid_list_or_none(value_list): if value_list is None: return for sg_id in value_list: if not uuidutils.is_uuid_like(sg_id): msg = _("'%s' is not an integer or uuid") % sg_id raise qexception.InvalidInput(error_message=msg) return value_list
def convert_to_uuid_list_or_none(value_list): if value_list is None: return for sg_id in value_list: if not uuidutils.is_uuid_like(sg_id): msg = _("'%s' is not an integer or uuid") % sg_id raise qexception.InvalidInput(error_message=msg) return value_list
def convert_to_uuid_or_int_list(value_list): if value_list is None: return try: return [sg_id if uuidutils.is_uuid_like(sg_id) else int(sg_id) for sg_id in value_list] except (ValueError, TypeError): msg = _("'%s' is not an integer or uuid") % sg_id raise qexception.InvalidInput(error_message=msg)
def _get_security_group_rule(self, context, id): try: if uuidutils.is_uuid_like(id): query = self._model_query(context, SecurityGroupRule) sgr = query.filter(SecurityGroupRule.id == id).one() else: query = self._model_query(context, SecurityGroupRule) sgr = query.filter(SecurityGroupRule.external_id == id).one() except exc.NoResultFound: raise ext_sg.SecurityGroupRuleNotFound(id=id) return sgr
def _get_security_group_rule(self, context, id): try: if uuidutils.is_uuid_like(id): query = self._model_query(context, SecurityGroupRule) sgr = query.filter(SecurityGroupRule.id == id).one() else: query = self._model_query(context, SecurityGroupRule) sgr = query.filter(SecurityGroupRule.external_id == id).one() except exc.NoResultFound: raise ext_sg.SecurityGroupRuleNotFound(id=id) return sgr
def existing_dhcp_networks(cls, conf, root_helper): """Return a list of existing networks ids (ones we have configs for)""" confs_dir = os.path.abspath(os.path.normpath(conf.dhcp_confs)) class FakeNetwork: def __init__(self, net_id): self.id = net_id return [ c for c in os.listdir(confs_dir) if (uuidutils.is_uuid_like(c) and cls(conf, FakeNetwork(c), root_helper).active) ]
def existing_dhcp_networks(cls, conf, root_helper): """Return a list of existing networks ids (ones we have configs for)""" confs_dir = os.path.abspath(os.path.normpath(conf.dhcp_confs)) class FakeNetwork: def __init__(self, net_id): self.id = net_id return [ c for c in os.listdir(confs_dir) if (uuidutils.is_uuid_like(c) and cls(conf, FakeNetwork(c), root_helper).active) ]
def _validate_uuid(data, valid_values=None): if not uuidutils.is_uuid_like(data): msg = _("'%s' is not a valid UUID") % data LOG.debug(msg) return msg
def _validate_uuid(data, valid_values=None): if not uuidutils.is_uuid_like(data): msg = _("'%s' is not a valid UUID") % data LOG.debug(msg) return msg