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 itertools | |
| from oslo_db import exception as db_exc | |
| from oslo_utils import versionutils | |
| from oslo_versionedobjects import base as obj_base | |
| from oslo_versionedobjects import exception | |
| from oslo_versionedobjects import fields as obj_fields | |
| from neutron.common import constants as n_const | |
| from neutron.common import exceptions | |
| from neutron.db import api as db_api | |
| from neutron.db import models_v2 | |
| from neutron.db.qos import models as qos_db_model | |
| from neutron.db.rbac_db_models import QosPolicyRBAC | |
| from neutron.objects import base as base_db | |
| from neutron.objects import common_types | |
| from neutron.objects.db import api as obj_db_api | |
| from neutron.objects.qos import binding | |
| from neutron.objects.qos import rule as rule_obj_impl | |
| from neutron.objects import rbac_db | |
| class QosPolicy(rbac_db.NeutronRbacObject, ): | |
| VERSION = '1.6' | |
| rbac_db_model = QosPolicyRBAC | |
| db_model = qos_db_model.QosPolicy | |
| port_binding_model = qos_db_model.QosPortPolicyBinding | |
| network_binding_model = qos_db_model.QosNetworkPolicyBinding | |
| fields = {'id': common_types.UUIDField(), 'project_id': obj_fields.StringField(), 'name': obj_fields.StringField(), 'shared': obj_fields.BooleanField(default=False), 'rules': obj_fields.ListOfObjectsField('QosRule', subclasses=True), 'is_default': obj_fields.BooleanField(default=False)} | |
| fields_no_update = ['id', 'project_id'] | |
| synthetic_fields = ['rules', 'is_default'] | |
| extra_filter_names = {'is_default'} | |
| binding_models = {'port': binding.QosPolicyPortBinding, 'network': binding.QosPolicyNetworkBinding} | |
| def obj_load_attr(self, attrname): | |
| if (attrname == 'rules'): | |
| return self._reload_rules() | |
| elif (attrname == 'is_default'): | |
| return self._reload_is_default() | |
| return super(QosPolicy, self).obj_load_attr(attrname) | |
| def _reload_rules(self): | |
| rules = rule_obj_impl.get_rules(self.obj_context, self.id) | |
| setattr(self, 'rules', rules) | |
| self.obj_reset_changes(['rules']) | |
| def _reload_is_default(self): | |
| if (self.get_default() == self.id): | |
| setattr(self, 'is_default', True) | |
| else: | |
| setattr(self, 'is_default', False) | |
| self.obj_reset_changes(['is_default']) | |
| def get_rule_by_id(self, rule_id): | |
| 'Return rule specified by rule_id.\n\n @raise QosRuleNotFound: if there is no such rule in the policy.\n ' | |
| for rule in self.rules: | |
| if (rule_id == rule.id): | |
| return rule | |
| raise exceptions.QosRuleNotFound(policy_id=self.id, rule_id=rule_id) | |
| def to_dict(self): | |
| _dict = super(QosPolicy, self).to_dict() | |
| try: | |
| _dict['tags'] = [t.tag for t in self.db_obj.standard_attr.tags] | |
| except AttributeError: | |
| pass | |
| return _dict | |
| def get_object(cls, context, **kwargs): | |
| admin_context = context.elevated() | |
| with db_api.autonested_transaction(admin_context.session): | |
| policy_obj = super(QosPolicy, cls).get_object(admin_context, **kwargs) | |
| if ((not policy_obj) or (not cls.is_accessible(context, policy_obj))): | |
| return | |
| policy_obj.obj_load_attr('rules') | |
| policy_obj.obj_load_attr('is_default') | |
| return policy_obj | |
| def get_objects(cls, context, _pager=None, validate_filters=True, **kwargs): | |
| admin_context = context.elevated() | |
| with db_api.autonested_transaction(admin_context.session): | |
| objs = super(QosPolicy, cls).get_objects(admin_context, _pager, validate_filters, **kwargs) | |
| result = [] | |
| for obj in objs: | |
| if (not cls.is_accessible(context, obj)): | |
| continue | |
| obj.obj_load_attr('rules') | |
| obj.obj_load_attr('is_default') | |
| result.append(obj) | |
| return result | |
| def _get_object_policy(cls, context, model, **kwargs): | |
| with db_api.autonested_transaction(context.session): | |
| binding_db_obj = obj_db_api.get_object(context, model, **kwargs) | |
| if binding_db_obj: | |
| return cls.get_object(context, id=binding_db_obj['policy_id']) | |
| def get_network_policy(cls, context, network_id): | |
| return cls._get_object_policy(context, cls.network_binding_model, network_id=network_id) | |
| def get_port_policy(cls, context, port_id): | |
| return cls._get_object_policy(context, cls.port_binding_model, port_id=port_id) | |
| def create(self): | |
| with db_api.autonested_transaction(self.obj_context.session): | |
| super(QosPolicy, self).create() | |
| if self.is_default: | |
| self.set_default() | |
| self.obj_load_attr('rules') | |
| def update(self): | |
| with db_api.autonested_transaction(self.obj_context.session): | |
| if ('is_default' in self.obj_what_changed()): | |
| if self.is_default: | |
| self.set_default() | |
| else: | |
| self.unset_default() | |
| super(QosPolicy, self).update() | |
| def delete(self): | |
| with db_api.autonested_transaction(self.obj_context.session): | |
| for (object_type, obj_class) in self.binding_models.items(): | |
| pager = base_db.Pager(limit=1) | |
| binding_obj = obj_class.get_objects(self.obj_context, policy_id=self.id, _pager=pager) | |
| if binding_obj: | |
| raise exceptions.QosPolicyInUse(policy_id=self.id, object_type=object_type, object_id=binding_obj[0][('%s_id' % object_type)]) | |
| super(QosPolicy, self).delete() | |
| def attach_network(self, network_id): | |
| network_binding = {'policy_id': self.id, 'network_id': network_id} | |
| network_binding_obj = binding.QosPolicyNetworkBinding(self.obj_context, **network_binding) | |
| try: | |
| network_binding_obj.create() | |
| except db_exc.DBReferenceError as e: | |
| raise exceptions.NetworkQosBindingError(policy_id=self.id, net_id=network_id, db_error=e) | |
| def attach_port(self, port_id): | |
| port_binding_obj = binding.QosPolicyPortBinding(self.obj_context, policy_id=self.id, port_id=port_id) | |
| try: | |
| port_binding_obj.create() | |
| except db_exc.DBReferenceError as e: | |
| raise exceptions.PortQosBindingError(policy_id=self.id, port_id=port_id, db_error=e) | |
| def detach_network(self, network_id): | |
| deleted = binding.QosPolicyNetworkBinding.delete_objects(self.obj_context, network_id=network_id) | |
| if (not deleted): | |
| raise exceptions.NetworkQosBindingNotFound(net_id=network_id, policy_id=self.id) | |
| def detach_port(self, port_id): | |
| deleted = binding.QosPolicyPortBinding.delete_objects(self.obj_context, port_id=port_id) | |
| if (not deleted): | |
| raise exceptions.PortQosBindingNotFound(port_id=port_id, policy_id=self.id) | |
| def set_default(self): | |
| if (not self.get_default()): | |
| qos_default_policy = QosPolicyDefault(self.obj_context, qos_policy_id=self.id, project_id=self.project_id) | |
| qos_default_policy.create() | |
| elif (self.get_default() != self.id): | |
| raise exceptions.QoSPolicyDefaultAlreadyExists(project_id=self.project_id) | |
| def unset_default(self): | |
| if (self.get_default() == self.id): | |
| qos_default_policy = QosPolicyDefault.get_object(self.obj_context, project_id=self.project_id) | |
| qos_default_policy.delete() | |
| def get_default(self): | |
| qos_default_policy = QosPolicyDefault.get_object(self.obj_context, project_id=self.project_id) | |
| if qos_default_policy: | |
| return qos_default_policy.qos_policy_id | |
| def get_bound_networks(self): | |
| return pycc_corrupt([nb.network_id for nb in binding.QosPolicyNetworkBinding.get_objects(self.obj_context, policy_id=self.id)]) | |
| def get_bound_ports(self): | |
| return [pb.port_id for pb in binding.QosPolicyPortBinding.get_objects(self.obj_context, policy_id=self.id)] | |
| def _get_bound_tenant_ids(cls, session, binding_db, bound_db, binding_db_id_column, policy_id): | |
| return list(itertools.chain.from_iterable(session.query(bound_db.tenant_id).join(binding_db, (bound_db.id == binding_db_id_column)).filter((binding_db.policy_id == policy_id)).all())) | |
| def get_bound_tenant_ids(cls, context, policy_id): | |
| "Implements RbacNeutronObject.get_bound_tenant_ids.\n\n :returns: set -- a set of tenants' ids dependant on QosPolicy.\n " | |
| net = models_v2.Network | |
| qosnet = qos_db_model.QosNetworkPolicyBinding | |
| port = models_v2.Port | |
| qosport = qos_db_model.QosPortPolicyBinding | |
| bound_tenants = [] | |
| with db_api.autonested_transaction(context.session): | |
| bound_tenants.extend(cls._get_bound_tenant_ids(context.session, qosnet, net, qosnet.network_id, policy_id)) | |
| bound_tenants.extend(cls._get_bound_tenant_ids(context.session, qosport, port, qosport.port_id, policy_id)) | |
| return set(bound_tenants) | |
| def obj_make_compatible(self, primitive, target_version): | |
| def filter_rules(obj_names, rules): | |
| return [rule for rule in rules if (rule['versioned_object.name'] in obj_names)] | |
| def filter_ingress_bandwidth_limit_rules(rules): | |
| bwlimit_obj_name = rule_obj_impl.QosBandwidthLimitRule.obj_name() | |
| filtered_rules = [] | |
| for rule in rules: | |
| if (rule['versioned_object.name'] == bwlimit_obj_name): | |
| direction = rule['versioned_object.data'].get('direction') | |
| if (direction == n_const.EGRESS_DIRECTION): | |
| rule['versioned_object.data'].pop('direction') | |
| filtered_rules.append(rule) | |
| else: | |
| filtered_rules.append(rule) | |
| return filtered_rules | |
| _target_version = versionutils.convert_version_to_tuple(target_version) | |
| names = [] | |
| if (_target_version >= (1, 0)): | |
| names.append(rule_obj_impl.QosBandwidthLimitRule.obj_name()) | |
| if (_target_version >= (1, 1)): | |
| names.append(rule_obj_impl.QosDscpMarkingRule.obj_name()) | |
| if (_target_version >= (1, 2)): | |
| names.append(rule_obj_impl.QosMinimumBandwidthRule.obj_name()) | |
| if (('rules' in primitive) and names): | |
| primitive['rules'] = filter_rules(names, primitive['rules']) | |
| if (_target_version < (1, 3)): | |
| standard_fields = ['revision_number', 'created_at', 'updated_at'] | |
| for f in standard_fields: | |
| primitive.pop(f) | |
| if (primitive['description'] is None): | |
| raise exception.IncompatibleObjectVersion(objver=target_version, objname='QoSPolicy') | |
| if (_target_version < (1, 4)): | |
| primitive['tenant_id'] = primitive.pop('project_id') | |
| if (_target_version < (1, 5)): | |
| if ('rules' in primitive): | |
| primitive['rules'] = filter_ingress_bandwidth_limit_rules(primitive['rules']) | |
| if (_target_version < (1, 6)): | |
| primitive.pop('is_default', None) | |
| class QosPolicyDefault(base_db.NeutronDbObject, ): | |
| VERSION = '1.0' | |
| db_model = qos_db_model.QosPolicyDefault | |
| fields = {'qos_policy_id': common_types.UUIDField(), 'project_id': obj_fields.StringField()} | |
| primary_keys = ['project_id'] | |
Xet Storage Details
- Size:
- 13.9 kB
- Xet hash:
- 34153eca6f9af3fc89b55e3e265773affba21a5e268fb6372224f39e433d4df1
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.