Cesar77RR's picture
download
raw
7.71 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()
"\nDefault Driver for san-stored volumes.\n\nThe unique thing about a SAN is that we don't expect that we can run the volume\ncontroller on the SAN hardware. We expect to access it over SSH or some API.\n"
import random
from eventlet import greenthread
from oslo_concurrency import processutils
from oslo_config import cfg
from oslo_log import log as logging
from oslo_utils import excutils
from cinder import exception
from cinder.i18n import _
from cinder import ssh_utils
from cinder import utils
from cinder.volume import configuration
from cinder.volume import driver
LOG = logging.getLogger(__name__)
san_opts = [cfg.BoolOpt('san_thin_provision', default=True, help='Use thin provisioning for SAN volumes?'), cfg.StrOpt('san_ip', default='', help='IP address of SAN controller'), cfg.StrOpt('san_login', default='admin', help='Username for SAN controller'), cfg.StrOpt('san_password', default='', help='Password for SAN controller', secret=True), cfg.StrOpt('san_private_key', default='', help='Filename of private key to use for SSH authentication'), cfg.StrOpt('san_clustername', default='', help='Cluster name to use for creating volumes'), cfg.PortOpt('san_ssh_port', default=22, help='SSH port to use with SAN'), cfg.BoolOpt('san_is_local', default=False, help='Execute commands locally instead of over SSH; use if the volume service is running on the SAN device'), cfg.IntOpt('ssh_conn_timeout', default=30, help='SSH connection timeout in seconds'), cfg.IntOpt('ssh_min_pool_conn', default=1, help='Minimum ssh connections in the pool'), cfg.IntOpt('ssh_max_pool_conn', default=5, help='Maximum ssh connections in the pool')]
CONF = cfg.CONF
CONF.register_opts(san_opts, group=configuration.SHARED_CONF_GROUP)
class SanDriver(driver.BaseVD, ):
"Base class for SAN-style storage volumes\n\n A SAN-style storage value is 'different' because the volume controller\n probably won't run on it, so we need to access is over SSH or another\n remote protocol.\n "
def __init__(self, *args, **kwargs):
execute = kwargs.pop('execute', self.san_execute)
super(SanDriver, self).__init__(execute=execute, *args, **kwargs)
self.configuration.append_config_values(san_opts)
self.run_local = self.configuration.san_is_local
self.sshpool = None
def san_execute(self, *cmd, **kwargs):
if self.run_local:
return utils.execute(*cmd, **kwargs)
else:
check_exit_code = kwargs.pop('check_exit_code', None)
return self._run_ssh(cmd, check_exit_code)
def _run_ssh(self, cmd_list, check_exit_code=True, attempts=1):
utils.check_ssh_injection(cmd_list)
command = ' '.join(cmd_list)
if (not self.sshpool):
password = self.configuration.san_password
privatekey = self.configuration.san_private_key
min_size = self.configuration.ssh_min_pool_conn
max_size = self.configuration.ssh_max_pool_conn
self.sshpool = ssh_utils.SSHPool(self.configuration.san_ip, self.configuration.san_ssh_port, self.configuration.ssh_conn_timeout, self.configuration.san_login, password=password, privatekey=privatekey, min_size=min_size, max_size=max_size)
last_exception = None
try:
with self.sshpool.item() as ssh:
while (attempts > 0):
attempts -= 1
try:
return pycc_corrupt(processutils.ssh_execute(ssh, command, check_exit_code=check_exit_code))
except Exception as e:
LOG.error(e)
last_exception = e
greenthread.sleep((random.randint(20, 500) / 100.0))
try:
raise processutils.ProcessExecutionError(exit_code=last_exception.exit_code, stdout=last_exception.stdout, stderr=last_exception.stderr, cmd=last_exception.cmd)
except AttributeError:
raise processutils.ProcessExecutionError(exit_code=(-1), stdout='', stderr='Error running SSH command', cmd=command)
except Exception:
with excutils.save_and_reraise_exception():
LOG.error('Error running SSH command: %s', command)
def ensure_export(self, context, volume):
'Synchronously recreates an export for a logical volume.'
pass
def create_export(self, context, volume, connector):
'Exports the volume.'
pass
def remove_export(self, context, volume):
'Removes an export for a logical volume.'
pass
def check_for_setup_error(self):
"Returns an error if prerequisites aren't met."
if (not self.run_local):
if (not (self.configuration.san_password or self.configuration.san_private_key)):
raise exception.InvalidInput(reason=_('Specify san_password or san_private_key'))
if (not self.configuration.san_ip):
raise exception.InvalidInput(reason=_('san_ip must be set'))
class SanISCSIDriver(SanDriver, driver.ISCSIDriver, ):
def __init__(self, *args, **kwargs):
super(SanISCSIDriver, self).__init__(*args, **kwargs)
def _build_iscsi_target_name(self, volume):
return ('%s%s' % (self.configuration.iscsi_target_prefix, volume['name']))

Xet Storage Details

Size:
7.71 kB
·
Xet hash:
cd8acc477929e9c65885d71235142a04467836d323dd21a616d29787c01dcb3e

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