Skip to content

Instantly share code, notes, and snippets.

@clayg
clayg / heal_attachments.py
Created August 10, 2012 05:39
Clean ghosted iscsi sr's and tag vbd's as openstack-volumes
#!/usr/bin/env python
"""usage: %(prog)s <nova.conf>
Remove unused iscsi connections (sr) from xen host and
tag attachments (vbd) as "openstack-volumes".
Connection information is parsed from nova.conf file.
e.g.
@clayg
clayg / fix_srs.py
Created September 25, 2012 14:16
python xenapi script to fix srs
def get_api(host, password):
session = XenAPI.Session('http://%s' % host)
session.login_with_password('root', password)
return session.xenapi
def fix_srs(api):
for sr_ref in api.SR.get_all():
sr = api.SR.get_record(sr_ref)
if sr['type'] != 'iscsi':
# we are wise to ignore non iscsi sr
@clayg
clayg / test_logger.py
Created September 26, 2012 10:10
basic log capture for unittest
import unittest
from StringIO import StringIO
import logging
logging.basicConfig(level=logging.DEBUG, filename='test.log', filemode='w')
logger = logging.getLogger()
class LogCaptureResult(unittest._TextTestResult):
#!/usr/bin/env python
"""usage: %(prog)s [/etc/nova/nova.conf] [--dry-run]
Cleanup and/or remove unused iscsi connections (sr) from xen host and
tag and try to unplug "openstack-volumes" attachments (vbd).
Connection information is parsed from nova.conf file.
e.g.
@clayg
clayg / output-logger.py
Created October 9, 2012 17:09
less obvious than I would have liked
import subprocess
import threading
import time
import logging
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger()
cmd = 'dpkg -l'
diff --git a/ISCSISR b/ISCSISR
@@ -344,6 +344,11 @@ class ISCSISR(SR.SR):
if self.mpath == 'true' and self.dconf.has_key('SCSIid'):
self.mpathmodule.refresh(self.dconf['SCSIid'],npaths)
+ # Set the block scheduler
+ for path in os.listdir(self.path):
+ if path.startswith('LUN'):
+ self.block_setscheduler(os.path.join(self.path, path))
+
>>> def myfunc(a, b):
... print (a, b)
...
>>> myfunc(b=2, a=1)
(1, 2)
a comes before c
b comes after a
b comes before d
e comes after b
e comes after d
e comes after c
e comes before f
g comes after b
h comes after g
@clayg
clayg / test_multi_driver.py
Created August 22, 2013 19:02
stevedore test case for multiple driver entry_point failure
import unittest
import pkg_resources
import stevedore
class MockPkgResources(object):
def iter_entry_points(self, namespace):
In [2]: db = ContainerBroker('/srv/node1/sdb1/containers/870/23c/d9ad51fe9c211707d5c690c1b00a223c/d9ad51fe9c211707d5c690c1b00a223c.db')
In [4]: db.get_info()
Out[4]:
{'account': 'AUTH_test',
'bytes_used': 0,
'container': 'mycontainer',
'created_at': '1377204903.29857',
'delete_timestamp': '0',
'hash': '00000000000000000000000000000000',