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() | |
| from neutron_lib.api.definitions import portbindings | |
| from neutron_lib import constants | |
| from neutron_lib.plugins.ml2 import api as ml2_api | |
| from oslo_log import log | |
| from oslo_serialization import jsonutils | |
| import sqlalchemy | |
| from neutron.db import segments_db | |
| from neutron.plugins.ml2 import driver_api as api | |
| LOG = log.getLogger(__name__) | |
| class InstanceSnapshot(object, ): | |
| 'Used to avoid holding references to DB objects in PortContext.' | |
| def __init__(self, obj): | |
| self._model_class = obj.__class__ | |
| self._identity_key = sqlalchemy.orm.util.identity_key(instance=obj)[1] | |
| self._cols = [col.key for col in sqlalchemy.inspect(self._model_class).columns] | |
| for col in self._cols: | |
| setattr(self, col, getattr(obj, col)) | |
| def persist_state_to_session(self, session): | |
| 'Updates the state of the snapshot in the session.\n\n Finds the SQLA object in the session if it exists or creates a new\n object and updates the object with the column values stored in this\n snapshot.\n ' | |
| db_obj = session.query(self._model_class).get(self._identity_key) | |
| if db_obj: | |
| for col in self._cols: | |
| setattr(db_obj, col, getattr(self, col)) | |
| else: | |
| session.add(self._model_class(**{col: getattr(self, col) for col in self._cols})) | |
| class MechanismDriverContext(object, ): | |
| 'MechanismDriver context base class.' | |
| def __init__(self, plugin, plugin_context): | |
| self._plugin = plugin | |
| self._plugin_context = plugin_context | |
| class NetworkContext(MechanismDriverContext, api.NetworkContext, ): | |
| def __init__(self, plugin, plugin_context, network, original_network=None, segments=None): | |
| super(NetworkContext, self).__init__(plugin, plugin_context) | |
| self._network = network | |
| self._original_network = original_network | |
| self._segments = (segments_db.get_network_segments(plugin_context, network['id']) if (segments is None) else segments) | |
| def current(self): | |
| return self._network | |
| def original(self): | |
| return self._original_network | |
| def network_segments(self): | |
| return self._segments | |
| class SubnetContext(MechanismDriverContext, api.SubnetContext, ): | |
| def __init__(self, plugin, plugin_context, subnet, network, original_subnet=None): | |
| super(SubnetContext, self).__init__(plugin, plugin_context) | |
| self._subnet = subnet | |
| self._original_subnet = original_subnet | |
| self._network_context = (NetworkContext(plugin, plugin_context, network) if network else None) | |
| def current(self): | |
| return self._subnet | |
| def original(self): | |
| return self._original_subnet | |
| def network(self): | |
| if (self._network_context is None): | |
| network = self._plugin.get_network(self._plugin_context, self.current['network_id']) | |
| self._network_context = NetworkContext(self._plugin, self._plugin_context, network) | |
| return self._network_context | |
| class PortContext(MechanismDriverContext, api.PortContext, ): | |
| def __init__(self, plugin, plugin_context, port, network, binding, binding_levels, original_port=None): | |
| super(PortContext, self).__init__(plugin, plugin_context) | |
| self._port = port | |
| self._original_port = original_port | |
| if isinstance(network, NetworkContext): | |
| self._network_context = network | |
| else: | |
| self._network_context = (NetworkContext(plugin, plugin_context, network) if network else None) | |
| self._binding = InstanceSnapshot(binding) | |
| self._binding_levels = [InstanceSnapshot(l) for l in (binding_levels or [])] | |
| self._segments_to_bind = None | |
| self._new_bound_segment = None | |
| self._next_segments_to_bind = None | |
| if original_port: | |
| self._original_vif_type = binding.vif_type | |
| self._original_vif_details = self._plugin._get_vif_details(binding) | |
| self._original_binding_levels = self._binding_levels | |
| else: | |
| self._original_vif_type = None | |
| self._original_vif_details = None | |
| self._original_binding_levels = None | |
| self._new_port_status = None | |
| def _prepare_to_bind(self, segments_to_bind): | |
| self._segments_to_bind = segments_to_bind | |
| self._new_bound_segment = None | |
| self._next_segments_to_bind = None | |
| def _clear_binding_levels(self): | |
| self._binding_levels = [] | |
| def _push_binding_level(self, binding_level): | |
| self._binding_levels.append(InstanceSnapshot(binding_level)) | |
| def _pop_binding_level(self): | |
| return self._binding_levels.pop() | |
| def current(self): | |
| return self._port | |
| def original(self): | |
| return self._original_port | |
| def status(self): | |
| if (self._port['device_owner'] == constants.DEVICE_OWNER_DVR_INTERFACE): | |
| return self._binding.status | |
| return self._port['status'] | |
| def original_status(self): | |
| if self._original_port: | |
| return self._original_port['status'] | |
| def network(self): | |
| if (not self._network_context): | |
| network = self._plugin.get_network(self._plugin_context, self.current['network_id']) | |
| self._network_context = NetworkContext(self._plugin, self._plugin_context, network) | |
| return pycc_corrupt(self._network_context) | |
| def binding_levels(self): | |
| if self._binding_levels: | |
| return [{ml2_api.BOUND_DRIVER: level.driver, ml2_api.BOUND_SEGMENT: self._expand_segment(level.segment_id)} for level in self._binding_levels] | |
| def original_binding_levels(self): | |
| if self._original_binding_levels: | |
| return [{ml2_api.BOUND_DRIVER: level.driver, ml2_api.BOUND_SEGMENT: self._expand_segment(level.segment_id)} for level in self._original_binding_levels] | |
| def top_bound_segment(self): | |
| if self._binding_levels: | |
| return self._expand_segment(self._binding_levels[0].segment_id) | |
| def original_top_bound_segment(self): | |
| if self._original_binding_levels: | |
| return self._expand_segment(self._original_binding_levels[0].segment_id) | |
| def bottom_bound_segment(self): | |
| if self._binding_levels: | |
| return self._expand_segment(self._binding_levels[(-1)].segment_id) | |
| def original_bottom_bound_segment(self): | |
| if self._original_binding_levels: | |
| return self._expand_segment(self._original_binding_levels[(-1)].segment_id) | |
| def _expand_segment(self, segment_id): | |
| for s in self.network.network_segments: | |
| if (s['id'] == segment_id): | |
| return s | |
| segment = segments_db.get_segment_by_id(self._plugin_context, segment_id) | |
| if (not segment): | |
| LOG.warning('Could not expand segment %s', segment_id) | |
| return segment | |
| def host(self): | |
| if (self._port['device_owner'] == constants.DEVICE_OWNER_DVR_INTERFACE): | |
| return self._binding.host | |
| return self._port.get(portbindings.HOST_ID) | |
| def original_host(self): | |
| if (self._port['device_owner'] == constants.DEVICE_OWNER_DVR_INTERFACE): | |
| return (self._original_port and self._binding.host) | |
| else: | |
| return (self._original_port and self._original_port.get(portbindings.HOST_ID)) | |
| def vif_type(self): | |
| return self._binding.vif_type | |
| def original_vif_type(self): | |
| return self._original_vif_type | |
| def vif_details(self): | |
| return self._plugin._get_vif_details(self._binding) | |
| def original_vif_details(self): | |
| return self._original_vif_details | |
| def segments_to_bind(self): | |
| return self._segments_to_bind | |
| def host_agents(self, agent_type): | |
| return self._plugin.get_agents(self._plugin_context, filters={'agent_type': [agent_type], 'host': [self._binding.host]}) | |
| def set_binding(self, segment_id, vif_type, vif_details, status=None): | |
| self._new_bound_segment = segment_id | |
| self._binding.vif_type = vif_type | |
| self._binding.vif_details = jsonutils.dumps(vif_details) | |
| self._new_port_status = status | |
| def continue_binding(self, segment_id, next_segments_to_bind): | |
| self._new_bound_segment = segment_id | |
| self._next_segments_to_bind = next_segments_to_bind | |
| def allocate_dynamic_segment(self, segment): | |
| network_id = self._network_context.current['id'] | |
| return self._plugin.type_manager.allocate_dynamic_segment(self._plugin_context, network_id, segment) | |
| def release_dynamic_segment(self, segment_id): | |
| return self._plugin.type_manager.release_dynamic_segment(self._plugin_context, segment_id) | |
Xet Storage Details
- Size:
- 11.3 kB
- Xet hash:
- f2e4d96eb11d86aa03d284883b08bae6973c48245467fded915ef11b9d9a89c4
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.