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 copy | |
| import itertools | |
| import operator | |
| from .neutron_lib.api.definitions import portbindings | |
| from .neutron_lib.callbacks import resources | |
| from .neutron_lib import constants | |
| from .neutron_lib import exceptions | |
| from .neutron_lib.plugins import directory | |
| from .oslo_config import cfg | |
| from .oslo_db import exception as db_exc | |
| from .oslo_log import log as logging | |
| import oslo_messaging | |
| from .oslo_utils import excutils | |
| from .neutron._i18n import _ | |
| from .neutron.common import constants as n_const | |
| from .neutron.common import exceptions as n_exc | |
| from .neutron.common import utils | |
| from .neutron.db import api as db_api | |
| from .neutron.db import provisioning_blocks | |
| from .neutron.extensions import segment as segment_ext | |
| from .neutron.plugins.common import utils as p_utils | |
| from .neutron.quota import resource_registry | |
| LOG = logging.getLogger(__name__) | |
| class DhcpRpcCallback(object, ): | |
| 'DHCP agent RPC callback in plugin implementations.\n\n This class implements the server side of an rpc interface. The client\n side of this interface can be found in\n neutron.agent.dhcp.agent.DhcpPluginApi. For more information about\n changing rpc interfaces, see doc/source/devref/rpc_api.rst.\n ' | |
| target = oslo_messaging.Target(namespace=n_const.RPC_NAMESPACE_DHCP_PLUGIN, version='1.6') | |
| def _get_active_networks(self, context, **kwargs): | |
| 'Retrieve and return a list of the active networks.' | |
| host = kwargs.get('host') | |
| plugin = directory.get_plugin() | |
| if utils.is_extension_supported(plugin, constants.DHCP_AGENT_SCHEDULER_EXT_ALIAS): | |
| if cfg.CONF.network_auto_schedule: | |
| plugin.auto_schedule_networks(context, host) | |
| nets = plugin.list_active_networks_on_active_dhcp_agent(context, host) | |
| else: | |
| filters = dict(admin_state_up=[True]) | |
| nets = plugin.get_networks(context, filters=filters) | |
| return nets | |
| def _port_action(self, plugin, context, port, action): | |
| 'Perform port operations taking care of concurrency issues.' | |
| try: | |
| if (action == 'create_port'): | |
| return p_utils.create_port(plugin, context, port) | |
| elif (action == 'update_port'): | |
| return plugin.update_port(context, port['id'], port) | |
| else: | |
| msg = _('Unrecognized action') | |
| raise exceptions.Invalid(message=msg) | |
| except (db_exc.DBReferenceError, exceptions.NetworkNotFound, exceptions.SubnetNotFound, exceptions.InvalidInput, exceptions.IpAddressGenerationFailure) as e: | |
| with excutils.save_and_reraise_exception(reraise=False) as ctxt: | |
| if isinstance(e, exceptions.IpAddressGenerationFailure): | |
| try: | |
| subnet_id = port['port']['fixed_ips'][0]['subnet_id'] | |
| plugin.get_subnet(context, subnet_id) | |
| except exceptions.SubnetNotFound: | |
| pass | |
| else: | |
| ctxt.reraise = True | |
| if ctxt.reraise: | |
| net_id = port['port']['network_id'] | |
| LOG.warning('Action %(action)s for network %(net_id)s could not complete successfully: %(reason)s', {'action': action, 'net_id': net_id, 'reason': e}) | |
| def _group_by_network_id(self, res): | |
| grouped = {} | |
| keyfunc = operator.itemgetter('network_id') | |
| for (net_id, values) in itertools.groupby(sorted(res, key=keyfunc), keyfunc): | |
| grouped[net_id] = list(values) | |
| return pycc_corrupt(grouped) | |
| def get_active_networks_info(self, context, **kwargs): | |
| 'Returns all the networks/subnets/ports in system.' | |
| host = kwargs.get('host') | |
| LOG.debug('get_active_networks_info from %s', host) | |
| networks = self._get_active_networks(context, **kwargs) | |
| plugin = directory.get_plugin() | |
| filters = {'network_id': [network['id'] for network in networks]} | |
| ports = plugin.get_ports(context, filters=filters) | |
| if kwargs.get('enable_dhcp_filter', True): | |
| filters['enable_dhcp'] = [True] | |
| subnets = sorted(plugin.get_subnets(context, filters=filters), key=operator.itemgetter('id')) | |
| seg_plug = directory.get_plugin(segment_ext.SegmentPluginBase.get_plugin_type()) | |
| seg_subnets = [subnet for subnet in subnets if subnet.get('segment_id')] | |
| nonlocal_subnets = [] | |
| if (seg_plug and seg_subnets): | |
| host_segment_ids = seg_plug.get_segments_by_hosts(context, [host]) | |
| seg_subnet_ids = {subnet['id'] for subnet in seg_subnets if (subnet['segment_id'] in host_segment_ids)} | |
| routed_net_ids = {seg_subnet['network_id'] for seg_subnet in seg_subnets} | |
| nonlocal_subnets = [subnet for subnet in seg_subnets if (subnet['id'] not in seg_subnet_ids)] | |
| subnets = [subnet for subnet in subnets if ((subnet['network_id'] not in routed_net_ids) or (subnet['id'] in seg_subnet_ids))] | |
| grouped_subnets = self._group_by_network_id(subnets) | |
| grouped_nonlocal_subnets = self._group_by_network_id(nonlocal_subnets) | |
| grouped_ports = self._group_by_network_id(ports) | |
| for network in networks: | |
| network['subnets'] = grouped_subnets.get(network['id'], []) | |
| network['non_local_subnets'] = grouped_nonlocal_subnets.get(network['id'], []) | |
| network['ports'] = grouped_ports.get(network['id'], []) | |
| return networks | |
| def get_network_info(self, context, **kwargs): | |
| 'Retrieve and return extended information about a network.' | |
| network_id = kwargs.get('network_id') | |
| host = kwargs.get('host') | |
| LOG.debug('Network %(network_id)s requested from %(host)s', {'network_id': network_id, 'host': host}) | |
| plugin = directory.get_plugin() | |
| try: | |
| network = plugin.get_network(context, network_id) | |
| except exceptions.NetworkNotFound: | |
| LOG.debug('Network %s could not be found, it might have been deleted concurrently.', network_id) | |
| return | |
| filters = dict(network_id=[network_id]) | |
| subnets = plugin.get_subnets(context, filters=filters) | |
| seg_plug = directory.get_plugin(segment_ext.SegmentPluginBase.get_plugin_type()) | |
| nonlocal_subnets = [] | |
| if (seg_plug and subnets): | |
| seg_subnets = [subnet for subnet in subnets if subnet.get('segment_id')] | |
| if seg_subnets: | |
| segment_ids = seg_plug.get_segments_by_hosts(context, [host]) | |
| nonlocal_subnets = [subnet for subnet in seg_subnets if (subnet['segment_id'] not in segment_ids)] | |
| subnets = [subnet for subnet in seg_subnets if (subnet['segment_id'] in segment_ids)] | |
| network['subnets'] = sorted(subnets, key=operator.itemgetter('id')) | |
| network['non_local_subnets'] = sorted(nonlocal_subnets, key=operator.itemgetter('id')) | |
| network['ports'] = plugin.get_ports(context, filters=filters) | |
| return network | |
| def release_dhcp_port(self, context, **kwargs): | |
| 'Release the port currently being used by a DHCP agent.' | |
| host = kwargs.get('host') | |
| network_id = kwargs.get('network_id') | |
| device_id = kwargs.get('device_id') | |
| LOG.debug('DHCP port deletion for %(network_id)s request from %(host)s', {'network_id': network_id, 'host': host}) | |
| plugin = directory.get_plugin() | |
| plugin.delete_ports_by_device_id(context, device_id, network_id) | |
| def create_dhcp_port(self, context, **kwargs): | |
| 'Create and return dhcp port information.\n\n If an expected failure occurs, a None port is returned.\n\n ' | |
| host = kwargs.get('host') | |
| port = copy.deepcopy(kwargs.get('port')) | |
| LOG.debug('Create dhcp port %(port)s from %(host)s.', {'port': port, 'host': host}) | |
| port['port']['device_owner'] = constants.DEVICE_OWNER_DHCP | |
| port['port'][portbindings.HOST_ID] = host | |
| if ('mac_address' not in port['port']): | |
| port['port']['mac_address'] = constants.ATTR_NOT_SPECIFIED | |
| plugin = directory.get_plugin() | |
| return self._port_action(plugin, context, port, 'create_port') | |
| def update_dhcp_port(self, context, **kwargs): | |
| 'Update the dhcp port.' | |
| host = kwargs.get('host') | |
| port = kwargs.get('port') | |
| port['id'] = kwargs.get('port_id') | |
| port['port'][portbindings.HOST_ID] = host | |
| plugin = directory.get_plugin() | |
| try: | |
| old_port = plugin.get_port(context, port['id']) | |
| if ((old_port['device_id'] != n_const.DEVICE_ID_RESERVED_DHCP_PORT) and (old_port['device_id'] != utils.get_dhcp_agent_device_id(port['port']['network_id'], host))): | |
| raise n_exc.DhcpPortInUse(port_id=port['id']) | |
| LOG.debug('Update dhcp port %(port)s from %(host)s.', {'port': port, 'host': host}) | |
| return self._port_action(plugin, context, port, 'update_port') | |
| except exceptions.PortNotFound: | |
| LOG.debug('Host %(host)s tried to update port %(port_id)s which no longer exists.', {'host': host, 'port_id': port['id']}) | |
| return None | |
| def dhcp_ready_on_ports(self, context, port_ids): | |
| for port_id in port_ids: | |
| provisioning_blocks.provisioning_complete(context, port_id, resources.PORT, provisioning_blocks.DHCP_ENTITY) | |
Xet Storage Details
- Size:
- 12.1 kB
- Xet hash:
- cb8a7ed61e236d469c1e88e96752fe2681a4e8b835d3b1863f8c69ce61166675
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.