def fs_create(req, pool_name, name, size_bytes): full_path = os.path.join(pool_name, fs_path, name) if not os.path.exists(full_path): invoke([fs_cmd, 'subvolume', 'create', full_path]) else: raise TargetdError(TargetdError.EXISTS_FS_NAME, 'FS already exists (Btrfs)')
def fs_create(req, pool_name, name, size_bytes): pool_check(pool_name) full_path = os.path.join(pool_name, fs_path, name) if not os.path.exists(full_path): invoke([fs_cmd, 'subvolume', 'create', full_path]) else: raise TargetdError(-53, 'FS already exists')
def fs_snapshot(req, pool, name, dest_ss_name): source_path = os.path.join(pool, fs_path, name) dest_base = os.path.join(pool, ss_path, name) dest_path = os.path.join(dest_base, dest_ss_name) create_sub_volume(dest_base) if os.path.exists(dest_path): raise TargetdError(TargetdError.EXISTS_FS_NAME, "Snapshot already exists with that name (Btrfs)") invoke([fs_cmd, 'subvolume', 'snapshot', '-r', source_path, dest_path])
def fs_clone(req, pool, name, dest_fs_name, snapshot_name=None): if snapshot_name is not None: source = os.path.join(pool, ss_path, name, snapshot_name) dest = os.path.join(pool, fs_path, dest_fs_name) else: source = os.path.join(pool, fs_path, name) dest = os.path.join(pool, fs_path, dest_fs_name) if os.path.exists(dest): raise TargetdError(TargetdError.EXISTS_CLONE_NAME, "Filesystem with that name exists (Btrfs)") invoke([fs_cmd, 'subvolume', 'snapshot', source, dest])
def fs_snapshot(req, fs_uuid, dest_ss_name): fs_ht = _get_fs_by_uuid(req, fs_uuid) if fs_ht: source_path = os.path.join(fs_ht['pool'], fs_path, fs_ht['name']) dest_base = os.path.join(fs_ht['pool'], ss_path, fs_ht['name']) dest_path = os.path.join(dest_base, dest_ss_name) create_sub_volume(dest_base) if os.path.exists(dest_path): raise TargetdError(-53, "Snapshot already exists with that name") invoke([fs_cmd, 'subvolume', 'snapshot', '-r', source_path, dest_path])
def export_remove(export): ec, out, err = invoke( [Nfs.CMD, '-u', '%s:%s' % (export.host, export.path)]) if ec == 0: Nfs._save_exports()
def exports(): """ Return list of exports """ ec, out, error = invoke([Nfs.CMD, '-v']) rc = Export.parse_exportfs_output(out) return rc
def fs_clone(req, fs_uuid, dest_fs_name, snapshot_id): fs_ht = _get_fs_by_uuid(req, fs_uuid) if not fs_ht: raise TargetdError(-104, "fs_uuid not found") if snapshot_id: snapshot = _get_ss_by_uuid(req, fs_uuid, snapshot_id) if not snapshot: raise TargetdError(-112, "snapshot not found") source = os.path.join(fs_ht['pool'], ss_path, fs_ht['name'], snapshot['name']) dest = os.path.join(fs_ht['pool'], fs_path, dest_fs_name) else: source = os.path.join(fs_ht['pool'], fs_path, fs_ht['name']) dest = os.path.join(fs_ht['pool'], fs_path, dest_fs_name) if os.path.exists(dest): raise TargetdError(-51, "Filesystem with that name exists") invoke([fs_cmd, 'subvolume', 'snapshot', source, dest])
def _invoke_retries(command, throw_exception): # TODO take out this loop, used to handle bug in btrfs # ERROR: Failed to lookup path for root 0 - No such file or directory for i in range(0, 5): result, out, err = invoke(command, False) if result == 0: return result, out, err elif result == 19: time.sleep(1) continue else: raise TargetdError(-303, "Unexpected exit code %d" % result) raise TargetdError( -303, "Unable to execute command after " "multiple retries %s" % (str(command)))
def export_add(host, path, bit_wise_options, key_value_options): """ Adds a path as an NFS export """ export = Export(host, path, bit_wise_options, key_value_options) options = export.options_string() cmd = [Nfs.CMD] if len(options): cmd.extend(['-o', options]) cmd.extend(['%s:%s' % (host, path)]) ec, out, err = invoke(cmd, False) if ec == 0: Nfs._save_exports() return None elif ec == 22: raise ValueError("Invalid option: %s" % err) else: raise RuntimeError('Unexpected exit code "%s" %s, out= %s' % (str(cmd), str(ec), str(out + ":" + err)))
def create_sub_volume(p): if not os.path.exists(p): invoke([fs_cmd, 'subvolume', 'create', p])
def fs_subvolume_delete(path): invoke([fs_cmd, 'subvolume', 'delete', path])
from targetd.iscsi_init import display_discovery, discover_portal from targetd.iscsi_init import login_target, logout_target, delete_node from test_iscsi_init_attributes import DISCOVERY_OUTPUT from test_iscsi_init_attributes import DISCOVERY_PARSED from test_iscsi_init_attributes import NODE_OUTPUT from test_iscsi_init_attributes import NODE_PARSED from test_iscsi_init_attributes import DISCOVERY_SUMMARY_OUTPUT from test_iscsi_init_attributes import DISCOVERY_SUMMARY_PARSED from test_iscsi_init_attributes import NODE_SUMMARY_OUTPUT from test_iscsi_init_attributes import NODE_SUMMARY_PARSED from test_iscsi_init_attributes import SESSION_OUTPUT from test_iscsi_init_attributes import SESSION_PARSED # to run tests : sudo py.test -q test_discovery_iscsi_init.py sam_tst_host = "192.168.200.82" return_code, output_success, output_fail = invoke(["which", "iscsiadm"], False) class TestDiscoveryNodeParser: def test_discovery_parser(self): d = discovery_node_parser(DISCOVERY_OUTPUT, "discovery") assert d == DISCOVERY_PARSED def test_node_parser(self): d = discovery_node_parser(NODE_OUTPUT, "node") assert d == NODE_PARSED def test_discovery_summary_parser(): d = discovery_summary_parser(DISCOVERY_SUMMARY_OUTPUT) assert d == DISCOVERY_SUMMARY_PARSED