def try_linkloop(loop_dev): path = '/root/blocks/' if not os.path.exists(path): putils.execute('mkdir', '-p', path, run_as_root=True, root_helper=rootwrap.root_helper()) path = path + 'snap' + loop_dev[9:] + '.blk' if not os.path.exists(path): putils.execute('dd', 'if=/dev/zero', 'of=' + path, 'bs=1M', 'count=512', run_as_root=True, root_helper=rootwrap.root_helper()) linkloop(loop_dev, path)
def is_connected(target_id): """This method is to judge whether a target is hanging by other VMs""" #TODO: try to call brick.iscsi #cmd = "tgtadm --lld iscsi --mode conn --op show --tid " + str(target_id) (output, error) = putils.execute("tgtadm", '--lld', 'iscsi', '--mode', 'conn', '--op', 'show', '--tid', str(target_id), run_as_root=True, root_helper=rootwrap.root_helper()) if len(output) == 0: return False return True
def cmd(): return putils.execute()
def execute(*cmd, **kwargs): return putils.execute(*cmd, **kwargs)
def disconnect_volume(connection, device_info): #TODO: Fix this problem #cmd = "iscsiadm -m node -T " + connection['target_iqn'] + " -p " + connection['target_portal'][:-5] + " --logout" putils.execute("iscsiadm", '-m', 'node', '-T', connection['target_iqn'], '-p', connection['target_portal'], '--logout', run_as_root=True, root_helper=rootwrap.root_helper())
def unlinkloop(loop_dev): if is_looped(loop_dev): putils.execute('losetup', '-d', loop_dev, run_as_root=True, root_helper=rootwrap.root_helper())
def linkloop(loop_dev, path): putils.execute('losetup', loop_dev, path, run_as_root=True, root_helper=rootwrap.root_helper())
def findloop(): #Licyh NOTE: openstack.common.processutils & subprocess.Popen only supports 'ls' not 'cat a.py' but 'cat','a.py', (out, err) = putils.execute('losetup', '-f', run_as_root=True, root_helper=rootwrap.root_helper()) return out.strip()