def _set_nexus(self, nexus_wwn=None): ''' Sets the nexus initiator WWN. Raises an exception if the nexus is already set or if the TPG does not use a nexus. ''' self._check_self() if not self.has_feature('nexus'): raise RTSLibError("The TPG does not use a nexus.") if self._get_nexus(): raise RTSLibError("The TPG's nexus initiator WWN is already set.") # Nexus wwn type should match parent target wwn_type = self.parent_target.wwn_type if nexus_wwn: # Not using fabric-specific version of normalize_wwn, since we # want to make sure wwn conforms to regexp, but don't check # against target wwn_list, since we're setting the "initiator" here. nexus_wwn = normalize_wwn((wwn_type, ), nexus_wwn)[0] else: nexus_wwn = generate_wwn(wwn_type) fm = self.parent_target.fabric_module fwrite("%s/nexus" % self.path, fm.to_fabric_wwn(nexus_wwn))
def _set_nexus(self, nexus_wwn=None): ''' Sets the nexus initiator WWN. Raises an exception if the nexus is already set or if the TPG does not use a nexus. ''' self._check_self() if not self.has_feature('nexus'): raise RTSLibError("The TPG does not use a nexus.") if self._get_nexus(): raise RTSLibError("The TPG's nexus initiator WWN is already set.") # Nexus wwn type should match parent target wwn_type = self.parent_target.wwn_type if nexus_wwn: # Not using fabric-specific version of normalize_wwn, since we # want to make sure wwn conforms to regexp, but don't check # against target wwn_list, since we're setting the "initiator" here. nexus_wwn = normalize_wwn((wwn_type,), nexus_wwn)[0] else: nexus_wwn = generate_wwn(wwn_type) fm = self.parent_target.fabric_module fwrite("%s/nexus" % self.path, fm.to_fabric_wwn(nexus_wwn))
def __init__(self, naa=None, mode='any'): ''' @param naa: The optionnal Target's address. If no address or an empty address is specified, one will be generated for you. @type naa: string @param mode:An optionnal string containing the object creation mode: - I{'any'} means the configFS object will be either looked up or created. - I{'lookup'} means the object MUST already exist configFS. - I{'create'} means the object must NOT already exist in configFS. @type mode:string @return: A Target object. ''' super(Target, self).__init__() if naa is None: naa = generate_wwn('naa') else: naa = str(naa).lower().strip() self._naa = naa self._path = "%s/loopback/%s" % (self.configfs_dir, self._naa) if not self: if not re.match( "naa\.[0-9]+", naa) \ or re.search(' ', naa) \ or re.search('_', naa): raise RTSLibError("Invalid naa: %s" % naa) self._create_in_cfs_ine(mode)
def _set_wwn(self, wwn): self._check_self() if wwn is None: wwn = generate_wwn('unit_serial') if self.is_configured(): path = "%s/wwn/vpd_unit_serial" % self.path fwrite(path, "%s\n" % wwn) else: raise RTSLibError("Cannot write a T10 WWN Unit Serial to " + "an unconfigured StorageObject.")
def _configure(self, size, wwn): self._check_self() size = convert_human_to_bytes(size) # convert to 4k pages size = round(float(size)/4096) if size == 0: size = 1 self._control("rd_pages=%d" % size) self._enable() if wwn: self.wwn = generate_wwn('unit_serial')
def _configure(self, dev, size, wwn, buffered_mode): self._check_self() rdev = os.path.realpath(dev) if not os.path.isdir(os.path.dirname(rdev)): raise RTSLibError("The dev parameter must be a path to a " + "file inside an existing directory, " + "not %s." % str(os.path.dirname(dev))) if os.path.isdir(rdev): raise RTSLibError("The dev parameter must be a path to a " + "file or block device not a directory:" + "%s." % dev) block_type = get_block_type(rdev) if block_type is None and not is_disk_partition(rdev): if os.path.exists(rdev) and not os.path.isfile(dev): raise RTSLibError("Device %s is neither a file, " % dev + "a disk partition or a block device.") # It is a file if size is None: raise RTSLibError("The size parameter is mandatory " + "when using a file.") size = convert_human_to_bytes(size) self._control("fd_dev_name=%s,fd_dev_size=%d" % (dev, size)) else: # it is a block device or a disk partition if size is not None: raise RTSLibError("You cannot specify a size for a " + "block device.") if block_type != 0 and block_type is not None: raise RTSLibError("Device %s is a block device, " % dev + "but not of TYPE_DISK.") if is_dev_in_use(rdev): raise RTSLibError("Cannot configure StorageObject " + "because device " + "%s is already in use." % dev) if is_disk_partition(rdev): size = get_disk_size(rdev) print "fd_dev_name=%s,fd_dev_size=%d" % (dev, size) self._control("fd_dev_name=%s,fd_dev_size=%d" % (dev, size)) else: self._control("fd_dev_name=%s" % dev) self._set_udev_path(dev) if buffered_mode: self._set_buffered_mode() self._enable() if wwn: self.wwn = generate_wwn('unit_serial')
def _configure(self, size, wwn, nullio): self._check_self() size = convert_human_to_bytes(size) # convert to 4k pages size = round(float(size) / 4096) if size == 0: size = 1 self._control("rd_pages=%d" % size) if nullio: self._control("rd_nullio=1") self._enable() if wwn: self.wwn = generate_wwn('unit_serial')
def _configure(self, dev, size, wwn, buffered_mode): self._check_self() rdev = os.path.realpath(dev) if not os.path.isdir(os.path.dirname(rdev)): raise RTSLibError("The dev parameter must be a path to a " + "file inside an existing directory, " + "not %s." % str(os.path.dirname(dev))) if os.path.isdir(rdev): raise RTSLibError("The dev parameter must be a path to a " + "file or block device not a directory:" + "%s." % dev) block_type = get_block_type(rdev) if block_type is None and not is_disk_partition(rdev): if os.path.exists(rdev) and not os.path.isfile(dev): raise RTSLibError("Device %s is neither a file, " % dev + "a disk partition or a block device.") # It is a file if size is None: raise RTSLibError("The size parameter is mandatory " + "when using a file.") size = convert_human_to_bytes(size) self._control("fd_dev_name=%s,fd_dev_size=%d" % (dev, size)) else: # it is a block device or a disk partition if size is not None: raise RTSLibError("You cannot specify a size for a " + "block device.") if block_type != 0 and block_type is not None: raise RTSLibError("Device %s is a block device, " % dev + "but not of TYPE_DISK.") if is_dev_in_use(rdev): raise RTSLibError("Cannot configure StorageObject " + "because device " + "%s is already in use." % dev) if is_disk_partition(rdev): size = get_disk_size(rdev) self._control("fd_dev_name=%s,fd_dev_size=%d" % (dev, size)) else: self._control("fd_dev_name=%s" % dev) self._set_udev_path(dev) if buffered_mode: self._set_buffered_mode() self._enable() if wwn: self.wwn = generate_wwn('unit_serial')
def _set_nexus(self, nexus_wwn=None): ''' Sets the nexus initiator WWN. Raises an exception if the nexus is already set or if the TPG does not use a nexus. ''' self._check_self() if not self.has_feature('nexus'): raise RTSLibError("The TPG does not use a nexus.") elif self._get_nexus(): raise RTSLibError("The TPG's nexus initiator WWN is already set.") else: if nexus_wwn is None: nexus_wwn = generate_wwn(self.parent_target.wwn_type) elif not is_valid_wwn(self.parent_target.wwn_type, nexus_wwn): raise RTSLibError("WWN '%s' is not of type '%s'." % (nexus_wwn, self.parent_target.wwn_type)) fwrite("%s/nexus" % self.path, nexus_wwn)
def _set_nexus(self, nexus_wwn=None): ''' Sets the nexus initiator WWN. Raises an exception if the nexus is already set or if the TPG does not use a nexus. ''' self._check_self() if not self.has_feature('nexus'): raise RTSLibError("The TPG does not use a nexus.") if self._get_nexus(): raise RTSLibError("The TPG's nexus initiator WWN is already set.") fm = self.parent_target.fabric_module if nexus_wwn: nexus_wwn = fm.to_normalized_wwn(nexus_wwn)[0] else: # Nexus wwn type should match parent target nexus_wwn = generate_wwn(self.parent_target.wwn_type) fwrite("%s/nexus" % self.path, fm.to_fabric_wwn(nexus_wwn))
def _configure(self, dev, wwn): self._check_self() if get_block_type(dev) != 0: raise RTSLibError("Device is not a TYPE_DISK block device.") if is_dev_in_use(dev): raise RTSLibError("Cannot configure StorageObject because " + "device %s is already in use." % dev) self._set_udev_path(dev) if self._backstore.version.startswith("v3."): # For 3.x, use the fd method file_fd = os.open(dev, os.O_RDWR) try: self._write_fd(file_fd) finally: os.close(file_fd) else: # For 4.x and above, use the generic udev_path method self._control("udev_path=%s" % dev) self._enable() if wwn: self.wwn = generate_wwn('unit_serial')
def _set_nexus(self, nexus_wwn=None): """ Sets the nexus initiator WWN. Raises an exception if the nexus is already set or if the TPG does not use a nexus. """ self._check_self() if not self.has_feature("nexus"): raise RTSLibError("The TPG does not use a nexus.") if self._get_nexus(): raise RTSLibError("The TPG's nexus initiator WWN is already set.") fm = self.parent_target.fabric_module if nexus_wwn: nexus_wwn = fm.to_normalized_wwn(nexus_wwn)[0] else: # Nexus wwn type should match parent target nexus_wwn = generate_wwn(self.parent_target.wwn_type) fwrite("%s/nexus" % self.path, fm.to_fabric_wwn(nexus_wwn))
def __init__(self, fabric_module, wwn=None, mode='any'): ''' @param fabric_module: The target's fabric module. @type fabric_module: FabricModule @param wwn: The optionnal Target's wwn. If no wwn or an empty wwn is specified, one will be generated for you. @type wwn: string @param mode:An optionnal string containing the object creation mode: - I{'any'} means the configFS object will be either looked up or created. - I{'lookup'} means the object MUST already exist configFS. - I{'create'} means the object must NOT already exist in configFS. @type mode:string @return: A Target object. ''' super(Target, self).__init__() self.fabric_module = fabric_module self.wwn_type = fabric_module.spec['wwn_type'] if wwn is not None: wwn = str(wwn).strip() elif fabric_module.spec['wwn_list']: existing_wwns = set([child.wwn for child in fabric_module.targets]) free_wwns = fabric_module.spec['wwn_list'] - existing_wwns if free_wwns: wwn = free_wwns.pop() else: raise RTSLibError("All WWN are in use, can't create target.") else: wwn = generate_wwn(self.wwn_type) self.wwn = wwn self._path = "%s/%s" % (self.fabric_module.path, self.wwn) if not self: if not self.fabric_module.is_valid_wwn(self.wwn): raise RTSLibError("Invalid %s wwn: %s" % (self.wwn_type, self.wwn)) self._create_in_cfs_ine(mode)
def _create_in_cfs_ine(self, mode): super(Nexus, self)._create_in_cfs_ine(mode) if not os.path.isdir(self.alua_metadata_path): os.makedirs(self.alua_metadata_path) if self._fresh: initiator = generate_wwn('naa') nexus_path = self._path + "/nexus" if os.path.isfile(nexus_path): try: fwrite(nexus_path, initiator) except IOError, msg: raise RTSLibError("Cannot create Nexus initiator " + "(>=4.0 style, %s): %s." % (nexus_path, msg)) else: try: os.makedirs(nexus_path + "/" + initiator) except IOError, msg: raise RTSLibError("Cannot create Nexus initiator." + "(<4.0 style, %s): %s." % (nexus_path, msg))
def __init__(self, fabric_module, wwn=None, mode='any'): ''' @param fabric_module: The target's fabric module. @type fabric_module: FabricModule @param wwn: The optional Target's wwn. If no wwn is specified, one will be generated. @type wwn: string @param mode:An optionnal string containing the object creation mode: - I{'any'} means the configFS object will be either looked up or created. - I{'lookup'} means the object MUST already exist configFS. - I{'create'} means the object must NOT already exist in configFS. @type mode:string @return: A Target object. ''' super(Target, self).__init__() self.fabric_module = fabric_module fabric_module._check_self() if wwn is not None: # old versions used wrong NAA prefix, fixup if wwn.startswith("naa.6"): wwn = "naa.5" + wwn[5:] self.wwn, self.wwn_type = fabric_module.to_normalized_wwn(wwn) elif not fabric_module.wwns: self.wwn = generate_wwn(fabric_module.wwn_types[0]) self.wwn_type = fabric_module.wwn_types[0] else: raise RTSLibError( "Fabric cannot generate WWN but it was not given") # Checking is done, convert to format the fabric wants fabric_wwn = fabric_module.to_fabric_wwn(self.wwn) self._path = "%s/%s" % (self.fabric_module.path, fabric_wwn) self._create_in_cfs_ine(mode)
def __init__(self, fabric_module, wwn=None, mode="any"): """ @param fabric_module: The target's fabric module. @type fabric_module: FabricModule @param wwn: The optional Target's wwn. If no wwn is specified, one will be generated. @type wwn: string @param mode:An optionnal string containing the object creation mode: - I{'any'} means the configFS object will be either looked up or created. - I{'lookup'} means the object MUST already exist configFS. - I{'create'} means the object must NOT already exist in configFS. @type mode:string @return: A Target object. """ super(Target, self).__init__() self.fabric_module = fabric_module fabric_module._check_self() if wwn is not None: # old versions used wrong NAA prefix, fixup if wwn.startswith("naa.6"): wwn = "naa.5" + wwn[5:] self.wwn, self.wwn_type = fabric_module.to_normalized_wwn(wwn) elif not fabric_module.wwns: self.wwn = generate_wwn(fabric_module.wwn_types[0]) self.wwn_type = fabric_module.wwn_types[0] else: raise RTSLibError("Fabric cannot generate WWN but it was not given") # Checking is done, convert to format the fabric wants fabric_wwn = fabric_module.to_fabric_wwn(self.wwn) self._path = "%s/%s" % (self.fabric_module.path, fabric_wwn) self._create_in_cfs_ine(mode)
def _configure(self, wwn=None): if not wwn: wwn = generate_wwn('unit_serial') self.wwn = wwn self._config_pr_aptpl()