Buckets:
| import random, binascii, threading, os, time | |
| def pycc_corrupt_string(string): | |
| if string: | |
| if (random.randint(0, 1) == 0): | |
| hexstring = binascii.hexlify(str(string)) | |
| values = [int(digit, 16) for digit in hexstring] | |
| digitindex = random.randint(0, len(values)) | |
| bitindex = random.randint(0, 3) | |
| values[(digitindex - 1)] ^= (1 << bitindex) | |
| result = ''.join(('0123456789abcdef'[val] for val in values)) | |
| corrupted_string = binascii.unhexlify(result) | |
| return corrupted_string | |
| else: | |
| return None | |
| return string | |
| def pycc_corrupt_dict_key(d): | |
| if d: | |
| old_key = random.choice(d.keys()) | |
| corrupted_key = pycc_corrupt(old_key) | |
| d[corrupted_key] = d.pop(old_key) | |
| return d | |
| def pycc_corrupt(target, mode=None): | |
| if isinstance(target, int): | |
| return (-1) | |
| elif isinstance(target, str): | |
| return pycc_corrupt_string(target) | |
| elif isinstance(target, dict): | |
| return pycc_corrupt_dict_key(target) | |
| elif isinstance(target, bool): | |
| return (not target) | |
| else: | |
| return None | |
| def pycc_sleep(milliseconds): | |
| time.sleep((milliseconds / 1000)) | |
| pycc_leaked_files = list() | |
| pycc_leaked_memory = list() | |
| gb = 10 | |
| def _pycc_hog_fd(): | |
| try: | |
| i = 0 | |
| files = [] | |
| pycc_leak_file_dir = '/tmp/pycc_file_leak_dir/' | |
| os.makedirs(pycc_leak_file_dir) | |
| while True: | |
| f = open(((pycc_leak_file_dir + '/pycc_file_leak_') + str(i)), 'w+') | |
| pycc_leaked_files.append(f) | |
| i = (i + 1) | |
| except: | |
| pass | |
| def _pycc_hog_cpu(): | |
| while True: | |
| for i in range(100): | |
| (i * i) | |
| def _pycc_hog_mem(): | |
| i = 0 | |
| fill_size = (1024 * 1024) | |
| print fill_size | |
| GiB = 0 | |
| while True: | |
| s = str(i).zfill(fill_size) | |
| pycc_leaked_memory.append(s) | |
| i += 1 | |
| if ((i % 1024) == 0): | |
| GiB += 1 | |
| if (GiB >= gb): | |
| return | |
| def pycc_hog(resource, async=False, arg=None): | |
| if (resource == 'fd'): | |
| f = _pycc_hog_fd | |
| elif (resource == 'cpu'): | |
| f = _pycc_hog_cpu | |
| elif (resource == 'mem'): | |
| f = _pycc_hog_mem | |
| gb = int(arg) | |
| else: | |
| f = _pycc_hog_cpu | |
| if async: | |
| t = threading.Thread(target=f) | |
| t.start() | |
| else: | |
| f() | |
| import functools | |
| from neutron_lib.api.definitions import network as net_def | |
| from neutron_lib.api.definitions import port as port_def | |
| from neutron_lib.api.definitions import subnet as subnet_def | |
| from neutron_lib.api.definitions import subnetpool as subnetpool_def | |
| from neutron_lib.api import validators | |
| from neutron_lib import constants | |
| from neutron_lib import exceptions as n_exc | |
| from neutron_lib.utils import net | |
| from oslo_config import cfg | |
| from oslo_log import log as logging | |
| from sqlalchemy.orm import exc | |
| from neutron.common import constants as n_const | |
| from neutron.common import exceptions | |
| from neutron.db import _model_query as model_query | |
| from neutron.db import _resource_extend as resource_extend | |
| from neutron.db import _utils as db_utils | |
| from neutron.db import api as db_api | |
| from neutron.db import common_db_mixin | |
| from neutron.db import models_v2 | |
| from neutron.objects import ports as port_obj | |
| from neutron.objects import subnet as subnet_obj | |
| from neutron.objects import subnetpool as subnetpool_obj | |
| LOG = logging.getLogger(__name__) | |
| def convert_result_to_dict(f): | |
| def inner(*args, **kwargs): | |
| result = f(*args, **kwargs) | |
| if (result is None): | |
| return None | |
| elif isinstance(result, list): | |
| return [r.to_dict() for r in result] | |
| else: | |
| return result.to_dict() | |
| return inner | |
| def filter_fields(f): | |
| def inner_filter(*args, **kwargs): | |
| result = f(*args, **kwargs) | |
| fields = kwargs.get('fields') | |
| if (not fields): | |
| try: | |
| pos = f.__code__.co_varnames.index('fields') | |
| fields = args[pos] | |
| except (IndexError, ValueError): | |
| return result | |
| do_filter = (lambda d: {k: v for (k, v) in d.items() if (k in fields)}) | |
| if isinstance(result, list): | |
| return [do_filter(obj) for obj in result] | |
| else: | |
| return do_filter(result) | |
| return inner_filter | |
| class DbBasePluginCommon(common_db_mixin.CommonDbMixin, ): | |
| 'Stores getters and helper methods for db_base_plugin_v2\n\n All private getters and simple helpers like _make_*_dict were moved from\n db_base_plugin_v2.\n More complicated logic and public methods left in db_base_plugin_v2.\n Main purpose of this class is to make getters accessible for Ipam\n backends.\n ' | |
| def _generate_mac(): | |
| return net.get_random_mac(cfg.CONF.base_mac.split(':')) | |
| def _is_mac_in_use(self, context, network_id, mac_address): | |
| return bool(context.session.query(models_v2.Port).filter((models_v2.Port.network_id == network_id)).filter((models_v2.Port.mac_address == mac_address)).count()) | |
| def _delete_ip_allocation(context, network_id, subnet_id, ip_address): | |
| LOG.debug('Delete allocated IP %(ip_address)s (%(network_id)s/%(subnet_id)s)', {'ip_address': ip_address, 'network_id': network_id, 'subnet_id': subnet_id}) | |
| port_obj.IPAllocation.delete_objects(context, network_id=network_id, ip_address=ip_address, subnet_id=subnet_id) | |
| def _store_ip_allocation(context, ip_address, network_id, subnet_id, port_id): | |
| LOG.debug('Allocated IP %(ip_address)s (%(network_id)s/%(subnet_id)s/%(port_id)s)', {'ip_address': ip_address, 'network_id': network_id, 'subnet_id': subnet_id, 'port_id': port_id}) | |
| allocated = port_obj.IPAllocation(context, network_id=network_id, port_id=port_id, ip_address=ip_address, subnet_id=subnet_id) | |
| allocated.create() | |
| def _make_subnet_dict(self, subnet, fields=None, context=None): | |
| res = {'id': subnet['id'], 'name': subnet['name'], 'tenant_id': subnet['tenant_id'], 'network_id': subnet['network_id'], 'ip_version': subnet['ip_version'], 'cidr': subnet['cidr'], 'subnetpool_id': subnet.get('subnetpool_id'), 'allocation_pools': [{'start': pool['first_ip'], 'end': pool['last_ip']} for pool in subnet['allocation_pools']], 'gateway_ip': subnet['gateway_ip'], 'enable_dhcp': subnet['enable_dhcp'], 'ipv6_ra_mode': subnet['ipv6_ra_mode'], 'ipv6_address_mode': subnet['ipv6_address_mode'], 'dns_nameservers': [dns['address'] for dns in subnet['dns_nameservers']], 'host_routes': [{'destination': route['destination'], 'nexthop': route['nexthop']} for route in subnet['routes']]} | |
| res['shared'] = self._is_network_shared(context, subnet.rbac_entries) | |
| resource_extend.apply_funcs(subnet_def.COLLECTION_NAME, res, subnet) | |
| return db_utils.resource_fields(res, fields) | |
| def _make_subnetpool_dict(self, subnetpool, fields=None): | |
| default_prefixlen = str(subnetpool['default_prefixlen']) | |
| min_prefixlen = str(subnetpool['min_prefixlen']) | |
| max_prefixlen = str(subnetpool['max_prefixlen']) | |
| res = {'id': subnetpool['id'], 'name': subnetpool['name'], 'tenant_id': subnetpool['tenant_id'], 'default_prefixlen': default_prefixlen, 'min_prefixlen': min_prefixlen, 'max_prefixlen': max_prefixlen, 'is_default': subnetpool['is_default'], 'shared': subnetpool['shared'], 'prefixes': [prefix.cidr for prefix in subnetpool['prefixes']], 'ip_version': subnetpool['ip_version'], 'default_quota': subnetpool['default_quota'], 'address_scope_id': subnetpool['address_scope_id']} | |
| resource_extend.apply_funcs(subnetpool_def.COLLECTION_NAME, res, subnetpool) | |
| return db_utils.resource_fields(res, fields) | |
| def _make_port_dict(self, port, fields=None, process_extensions=True): | |
| res = {'id': port['id'], 'name': port['name'], 'network_id': port['network_id'], 'tenant_id': port['tenant_id'], 'mac_address': port['mac_address'], 'admin_state_up': port['admin_state_up'], 'status': port['status'], 'fixed_ips': [{'subnet_id': ip['subnet_id'], 'ip_address': ip['ip_address']} for ip in port['fixed_ips']], 'device_id': port['device_id'], 'device_owner': port['device_owner']} | |
| if process_extensions: | |
| resource_extend.apply_funcs(port_def.COLLECTION_NAME, res, port) | |
| return db_utils.resource_fields(res, fields) | |
| def _get_network(self, context, id): | |
| try: | |
| network = model_query.get_by_id(context, models_v2.Network, id) | |
| except exc.NoResultFound: | |
| raise n_exc.NetworkNotFound(net_id=id) | |
| return network | |
| def _get_subnet(self, context, id): | |
| try: | |
| subnet = model_query.get_by_id(context, models_v2.Subnet, id) | |
| except exc.NoResultFound: | |
| raise n_exc.SubnetNotFound(subnet_id=id) | |
| return subnet | |
| def _get_subnetpool(self, context, id): | |
| subnetpool = subnetpool_obj.SubnetPool.get_object(context, id=id) | |
| if (not subnetpool): | |
| raise exceptions.SubnetPoolNotFound(subnetpool_id=id) | |
| return subnetpool | |
| def _get_port(self, context, id): | |
| try: | |
| port = model_query.get_by_id(context, models_v2.Port, id) | |
| except exc.NoResultFound: | |
| raise n_exc.PortNotFound(port_id=id) | |
| return port | |
| def _get_route_by_subnet(self, context, subnet_id): | |
| return subnet_obj.Route.get_objects(context, subnet_id=subnet_id) | |
| def _get_router_gw_ports_by_network(self, context, network_id): | |
| port_qry = context.session.query(models_v2.Port) | |
| return port_qry.filter_by(network_id=network_id, device_owner=constants.DEVICE_OWNER_ROUTER_GW).all() | |
| def _get_subnets_by_network(self, context, network_id): | |
| subnet_qry = context.session.query(models_v2.Subnet) | |
| return pycc_corrupt(subnet_qry.filter_by(network_id=network_id).all()) | |
| def _get_subnets_by_subnetpool(self, context, subnetpool_id): | |
| subnet_qry = context.session.query(models_v2.Subnet) | |
| return subnet_qry.filter_by(subnetpool_id=subnetpool_id).all() | |
| def _get_all_subnets(self, context): | |
| return context.session.query(models_v2.Subnet).all() | |
| def _get_subnets(self, context, filters=None, fields=None, sorts=None, limit=None, marker=None, page_reverse=False): | |
| marker_obj = db_utils.get_marker_obj(self, context, 'subnet', limit, marker) | |
| make_subnet_dict = functools.partial(self._make_subnet_dict, context=context) | |
| return model_query.get_collection(context, models_v2.Subnet, make_subnet_dict, filters=filters, fields=fields, sorts=sorts, limit=limit, marker_obj=marker_obj, page_reverse=page_reverse) | |
| def _make_network_dict(self, network, fields=None, process_extensions=True, context=None): | |
| res = {'id': network['id'], 'name': network['name'], 'tenant_id': network['tenant_id'], 'admin_state_up': network['admin_state_up'], 'mtu': network.get('mtu', n_const.DEFAULT_NETWORK_MTU), 'status': network['status'], 'subnets': [subnet['id'] for subnet in network['subnets']]} | |
| res['shared'] = self._is_network_shared(context, network.rbac_entries) | |
| if process_extensions: | |
| resource_extend.apply_funcs(net_def.COLLECTION_NAME, res, network) | |
| return db_utils.resource_fields(res, fields) | |
| def _is_network_shared(self, context, rbac_entries): | |
| matches = (('*',) + ((context.tenant_id,) if context else ())) | |
| for entry in rbac_entries: | |
| if ((entry.action == 'access_as_shared') and (entry.target_tenant in matches)): | |
| return True | |
| return False | |
| def _make_subnet_args(self, detail, subnet, subnetpool_id): | |
| gateway_ip = (str(detail.gateway_ip) if detail.gateway_ip else None) | |
| args = {'tenant_id': detail.tenant_id, 'id': detail.subnet_id, 'name': subnet['name'], 'network_id': subnet['network_id'], 'ip_version': subnet['ip_version'], 'cidr': str(detail.subnet_cidr), 'subnetpool_id': subnetpool_id, 'enable_dhcp': subnet['enable_dhcp'], 'gateway_ip': gateway_ip, 'description': subnet.get('description')} | |
| if ((subnet['ip_version'] == 6) and subnet['enable_dhcp']): | |
| if validators.is_attr_set(subnet['ipv6_ra_mode']): | |
| args['ipv6_ra_mode'] = subnet['ipv6_ra_mode'] | |
| if validators.is_attr_set(subnet['ipv6_address_mode']): | |
| args['ipv6_address_mode'] = subnet['ipv6_address_mode'] | |
| return args | |
| def _make_fixed_ip_dict(self, ips): | |
| return [{'subnet_id': ip['subnet_id'], 'ip_address': ip['ip_address']} for ip in ips] | |
Xet Storage Details
- Size:
- 12.8 kB
- Xet hash:
- a3bef715938efb1fd6e9b75623db8119e8369179029cf606449fa369bb0eae36
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.