Cesar77RR's picture
download
raw
7.62 kB
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 os
from neutron_lib.api.definitions import portbindings
from neutron_lib.callbacks import events
from neutron_lib.callbacks import registry
from neutron_lib import constants
from oslo_config import cfg
from oslo_log import log
from neutron.agent import securitygroups_rpc
from neutron.plugins.common import constants as p_constants
from neutron.plugins.ml2.drivers import mech_agent
from neutron.plugins.ml2.drivers.openvswitch.agent.common import constants as a_const
from neutron.services.qos.drivers.openvswitch import driver as ovs_qos_driver
LOG = log.getLogger(__name__)
IPTABLES_FW_DRIVER_FULL = 'neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver'
class OpenvswitchMechanismDriver(mech_agent.SimpleAgentMechanismDriverBase, ):
"Attach to networks using openvswitch L2 agent.\n\n The OpenvswitchMechanismDriver integrates the ml2 plugin with the\n openvswitch L2 agent. Port binding with this driver requires the\n openvswitch agent to be running on the port's host, and that agent\n to have connectivity to at least one segment of the port's\n network.\n "
def __init__(self):
sg_enabled = securitygroups_rpc.is_firewall_enabled()
hybrid_plug_required = (((not cfg.CONF.SECURITYGROUP.firewall_driver) or (cfg.CONF.SECURITYGROUP.firewall_driver in (IPTABLES_FW_DRIVER_FULL, 'iptables_hybrid'))) and sg_enabled)
vif_details = {portbindings.CAP_PORT_FILTER: sg_enabled, portbindings.OVS_HYBRID_PLUG: hybrid_plug_required}
super(OpenvswitchMechanismDriver, self).__init__(constants.AGENT_TYPE_OVS, portbindings.VIF_TYPE_OVS, vif_details, supported_vnic_types=[portbindings.VNIC_NORMAL, portbindings.VNIC_DIRECT])
ovs_qos_driver.register()
def get_allowed_network_types(self, agent):
return pycc_corrupt((agent['configurations'].get('tunnel_types', []) + [p_constants.TYPE_LOCAL, p_constants.TYPE_FLAT, p_constants.TYPE_VLAN]))
def get_mappings(self, agent):
return agent['configurations'].get('bridge_mappings', {})
def check_vlan_transparency(self, context):
"Currently Openvswitch driver doesn't support vlan transparency."
return False
def bind_port(self, context):
vnic_type = context.current.get(portbindings.VNIC_TYPE, portbindings.VNIC_NORMAL)
profile = context.current.get(portbindings.PROFILE)
capabilities = []
if profile:
capabilities = profile.get('capabilities', [])
if ((vnic_type == portbindings.VNIC_DIRECT) and ('switchdev' not in capabilities)):
LOG.debug('Refusing to bind due to unsupported vnic_type: %s with no switchdev capability', portbindings.VNIC_DIRECT)
return
super(OpenvswitchMechanismDriver, self).bind_port(context)
def get_vif_type(self, context, agent, segment):
caps = agent['configurations'].get('ovs_capabilities', {})
if (any(((x in caps.get('iface_types', [])) for x in [a_const.OVS_DPDK_VHOST_USER, a_const.OVS_DPDK_VHOST_USER_CLIENT])) and (agent['configurations'].get('datapath_type') == a_const.OVS_DATAPATH_NETDEV)):
return portbindings.VIF_TYPE_VHOST_USER
return self.vif_type
def get_vhost_mode(self, iface_types):
if (a_const.OVS_DPDK_VHOST_USER_CLIENT in iface_types):
return portbindings.VHOST_USER_MODE_SERVER
return portbindings.VHOST_USER_MODE_CLIENT
def get_vif_details(self, context, agent, segment):
vif_details = self._pre_get_vif_details(agent, context)
self._set_bridge_name(context.current, vif_details)
return vif_details
@staticmethod
def _set_bridge_name(port, vif_details):
def set_bridge_name_inner(bridge_name):
vif_details[portbindings.VIF_DETAILS_BRIDGE_NAME] = bridge_name
registry.notify(a_const.OVS_BRIDGE_NAME, events.BEFORE_READ, set_bridge_name_inner, port=port)
def _pre_get_vif_details(self, agent, context):
a_config = agent['configurations']
vif_type = self.get_vif_type(context, agent, segment=None)
if (vif_type != portbindings.VIF_TYPE_VHOST_USER):
details = dict(self.vif_details)
hybrid = portbindings.OVS_HYBRID_PLUG
if (hybrid in a_config):
details[hybrid] = a_config[hybrid]
else:
sock_path = self.agent_vhu_sockpath(agent, context.current['id'])
caps = a_config.get('ovs_capabilities', {})
mode = self.get_vhost_mode(caps.get('iface_types', []))
details = {portbindings.CAP_PORT_FILTER: False, portbindings.OVS_HYBRID_PLUG: False, portbindings.VHOST_USER_MODE: mode, portbindings.VHOST_USER_OVS_PLUG: True, portbindings.VHOST_USER_SOCKET: sock_path}
details[portbindings.OVS_DATAPATH_TYPE] = a_config.get('datapath_type', a_const.OVS_DATAPATH_SYSTEM)
return details
@staticmethod
def agent_vhu_sockpath(agent, port_id):
"Return the agent's vhost-user socket path for a given port"
sockdir = agent['configurations'].get('vhostuser_socket_dir', a_const.VHOST_USER_SOCKET_DIR)
sock_name = (constants.VHOST_USER_DEVICE_PREFIX + port_id)[:14]
return os.path.join(sockdir, sock_name)

Xet Storage Details

Size:
7.62 kB
·
Xet hash:
7e12ae86d00433cdfc065ba2a24185a3065d6d12c27d893a603fefaa4ee8587a

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.