def set_ACLs_mutual_auth(iqn, tag_index, acl_iqn, userid, password, mutual_userid, mutual_password): try: iscsiMod = FabricModule('iscsi') target = Target(iscsiMod, iqn, mode = 'lookup') tpg = TPG(target, tag = tag_index, mode = 'lookup') tpg.enable = True tpg.set_attribute('authentication', '1') tpg.set_attribute('generate_node_acls', '0') nodeacl = NodeACL(tpg, acl_iqn,mode='any') nodeacl.chap_userid = userid nodeacl.chap_password = password nodeacl.chap_mutual_userid = mutual_userid nodeacl.chap_mutual_password = mutual_password return 0 except Exception,e: print e return -1
def ui_command_delete(self, wwn): """ Deletes the Node ACL with the specified I{wwn}. SEE ALSO ======== B{create} """ self.assert_root() node_acl = NodeACL(self.tpg, wwn, mode="lookup") node_acl.delete() self.shell.log.info("Deleted Node ACL %s." % wwn) self.refresh()
def ui_command_delete(self, wwn): ''' Deletes the Node ACL with the specified I{wwn}. SEE ALSO ======== B{create} ''' self.assert_root() node_acl = NodeACL(self.tpg, wwn, mode='lookup') node_acl.delete() self.shell.log.info("Deleted Node ACL %s." % wwn) self.refresh()
def ui_command_create(self, wwn, add_mapped_luns=None): ''' Creates a Node ACL for the initiator node with the specified I{wwn}. The node's I{wwn} must match the expected WWN Type of the target's fabric module. If I{add_mapped_luns} is omitted, the global parameter B{auto_add_mapped_luns} will be used, else B{true} or B{false} are accepted. If B{true}, then after creating the ACL, mapped LUNs will be automatically created for all existing LUNs. SEE ALSO ======== B{delete} ''' self.assert_root() add_mapped_luns = self.ui_eval_param( add_mapped_luns, 'bool', self.shell.prefs['auto_add_mapped_luns']) node_acl = NodeACL(self.tpg, wwn, mode="create") ui_node_acl = UINodeACL(node_acl.node_wwn, self) self.shell.log.info("Created Node ACL for %s" % node_acl.node_wwn) if add_mapped_luns: for lun in self.tpg.luns: MappedLUN(node_acl, lun.lun, lun.lun, write_protect=False) self.shell.log.info("Created mapped LUN %d." % lun.lun) self.refresh() return self.new_node(ui_node_acl)
def ui_command_create(self, wwn, add_mapped_luns=None): ''' Creates a Node ACL for the initiator node with the specified I{wwn}. The node's I{wwn} must match the expected WWN Type of the target's fabric module. If I{add_mapped_luns} is omitted, the global parameter B{auto_add_mapped_luns} will be used, else B{true} or B{false} are accepted. If B{true}, then after creating the ACL, mapped LUNs will be automatically created for all existing LUNs. SEE ALSO ======== B{delete} ''' self.assert_root() spec = self.tpg.parent_target.fabric_module.spec if not utils.is_valid_wwn(spec['wwn_type'], wwn): self.shell.log.error("'%s' is not a valid %s WWN." % (wwn, spec['wwn_type'])) return add_mapped_luns = \ self.ui_eval_param(add_mapped_luns, 'bool', self.shell.prefs['auto_add_mapped_luns']) try: node_acl = NodeACL(self.tpg, wwn, mode="create") except RTSLibError, msg: self.shell.log.error(str(msg)) return
def delete_initiator(iqn, tag_index, initi_wwn): try: iscsiMod = FabricModule('iscsi') target = Target(iscsiMod, iqn, mode='lookup') tpg = TPG(target, tag = tag_index, mode = 'lookup') node = NodeACL(tpg, node_wwn = initi_wwn, mode='lookup') node.delete() return 0 except Exception, e: print e return -1
def apply_delete_obj(obj): ''' Deletes an object from the live system. ''' # TODO Factorize this when stable # TODO storage fabric cannot be deleted from the system, find a way to # handle this when i.e. path 'storage fileio' is in current config, but # no objects are hanging under it. root = get_root() log.debug("apply_delete(%s)" % obj.data) if obj.key[0] == 'mapped_lun': acl = obj.parent if acl.parent.key[0] == 'tpgt': tpg = acl.parent target = tpg.parent else: tpg = None target = acl.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') if tpg is None: tpgt = 1 else: tpgt = int(tpg.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') node_wwn = acl.key[1] lio_acl = NodeACL(lio_tpg, node_wwn, mode='lookup') mlun = int(obj.key[1]) lio_mlun = MappedLUN(lio_acl, mlun) lio_mlun.delete() elif obj.key[0] == 'acl': if obj.parent.key[0] == 'tpgt': tpg = obj.parent target = tpg.parent else: tpg = None target = obj.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') if tpg is None: tpgt = 1 else: tpgt = int(tpg.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') node_wwn = obj.key[1] lio_acl = NodeACL(lio_tpg, node_wwn, mode='lookup') lio_acl.delete() elif obj.key[0] == 'portal': if obj.parent.key[0] == 'tpgt': tpg = obj.parent target = tpg.parent else: tpg = None target = obj.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') if tpg is None: tpgt = 1 else: tpgt = int(tpg.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') (address, _, port) = obj.key[1].partition(':') port = int(port) lio_portal = NetworkPortal(lio_tpg, address, port, mode='lookup') lio_portal.delete() elif obj.key[0] == 'lun': if obj.parent.key[0] == 'tpgt': tpg = obj.parent target = tpg.parent else: tpg = None target = obj.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') if tpg is None: tpgt = 1 else: tpgt = int(tpg.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') lun = int(obj.key[1]) lio_lun = LUN(lio_tpg, lun) lio_lun.delete() elif obj.key[0] == 'tpgt': target = obj.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') tpgt = int(obj.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') # FIXME IS this really needed ? lio_tpg.enable = True lio_tpg.delete() elif obj.key[0] == 'target': fabric = obj.parent wwn = obj.key[1] lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=wwn, mode='lookup') lio_target.delete() elif obj.key[0] == 'disk': plugin = obj.parent.key[1] name = obj.key[1] matching_lio_so = [ so for so in root.storage_objects if so.backstore.plugin == plugin and so.name == name ] log.debug("Looking for storage object %s in %s" % (obj.path_str, str([ "%s/%s" % (so.backstore.plugin, so.name) for so in root.storage_objects ]))) if len(matching_lio_so) > 1: raise ConfigError("Detected unsupported configfs storage objects " "allocation schema for storage object '%s'" % obj.path_str) elif len(matching_lio_so) == 0: raise ConfigError("Could not find storage object '%s'" % obj.path_str) else: lio_so = matching_lio_so[0] lio_so.delete()
def apply_create_obj(obj): ''' Creates an object on the live system. ''' # TODO Factorize this when stable, merging it with update and delete, # leveraging rtslib 'any' mode (create if not exist) # TODO storage root = get_root() log.debug("apply_create(%s)" % obj.data) if obj.key[0] == 'mapped_lun': acl = obj.parent if acl.parent.key[0] == 'tpgt': tpg = acl.parent target = tpg.parent else: tpg = None target = acl.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') if tpg is None: tpgt = 1 else: tpgt = int(tpg.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') node_wwn = acl.key[1] lio_acl = NodeACL(lio_tpg, node_wwn, mode='lookup') mlun = int(obj.key[1]) write_protect = obj_attr(obj, "write_protect") tpg_lun = int(obj_attr(obj, "target_lun").rpartition(' ')[2]) lio_mlun = MappedLUN(lio_acl, mlun, tpg_lun, write_protect) apply_group_attrs(obj, lio_mlun) elif obj.key[0] == 'acl': if obj.parent.key[0] == 'tpgt': tpg = obj.parent target = tpg.parent else: tpg = None target = obj.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') if tpg is None: tpgt = 1 else: tpgt = int(tpg.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') node_wwn = obj.key[1] lio_acl = NodeACL(lio_tpg, node_wwn) apply_group_attrs(obj, lio_acl) elif obj.key[0] == 'portal': if obj.parent.key[0] == 'tpgt': tpg = obj.parent target = tpg.parent else: tpg = None target = obj.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') if tpg is None: tpgt = 1 else: tpgt = int(tpg.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') (address, _, port) = obj.key[1].partition(':') port = int(port) lio_portal = NetworkPortal(lio_tpg, address, port) apply_group_attrs(obj, lio_portal) elif obj.key[0] == 'lun': if obj.parent.key[0] == 'tpgt': tpg = obj.parent target = tpg.parent else: tpg = None target = obj.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') if tpg is None: tpgt = 1 else: tpgt = int(tpg.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') lun = int(obj.key[1]) (plugin, name) = obj_attr(obj, "backend") # TODO move that to a separate function, use for disk too matching_lio_so = [ so for so in root.storage_objects if so.backstore.plugin == plugin and so.name == name ] if len(matching_lio_so) > 1: raise ConfigError("Detected unsupported configfs storage objects " "allocation schema for storage object '%s'" % obj.path_str) elif len(matching_lio_so) == 0: raise ConfigError( "Could not find storage object '%s %s' for '%s'" % (plugin, name, obj.path_str)) else: lio_so = matching_lio_so[0] lio_lun = LUN(lio_tpg, lun, lio_so) apply_group_attrs(obj, lio_lun) elif obj.key[0] == 'tpgt': target = obj.parent fabric = target.parent has_enable = len(obj.search([("enable", ".*")])) != 0 if has_enable: enable = obj_attr(obj, "enable") lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') tpgt = int(obj.key[1]) try: nexus_wwn = obj_attr(obj, "nexus_wwn") lio_tpg = TPG(lio_target, tpgt, nexus_wwn=nexus_wwn) except ConfigError: lio_tpg = TPG(lio_target, tpgt) if has_enable: lio_tpg.enable = enable apply_group_attrs(obj, lio_tpg) elif obj.key[0] == 'target': fabric = obj.parent wwn = obj.key[1] lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=wwn) apply_group_attrs(obj, lio_target) if not lio_target.has_feature("tpgts"): try: nexus_wwn = obj_attr(obj, "nexus_wwn") lio_tpg = TPG(lio_target, 1, nexus_wwn=nexus_wwn) except ConfigError: lio_tpg = TPG(lio_target, 1) if len(obj.search([("enable", ".*")])) != 0: lio_tpg.enable = True elif obj.key[0] == 'fabric': lio_fabric = FabricModule(obj.key[1]) apply_group_attrs(obj, lio_fabric) elif obj.key[0] == 'disk': plugin = obj.parent.key[1] name = obj.key[1] idx = max([0] + [b.index for b in root.backstores if b.plugin == plugin]) + 1 if plugin == 'fileio': dev = obj_attr(obj, "path") size = obj_attr(obj, "size") try: wwn = obj_attr(obj, "wwn") except ConfigError: wwn = None buffered = obj_attr(obj, "buffered") lio_bs = FileIOBackstore(idx) lio_so = lio_bs.storage_object(name, dev, size, wwn, buffered) apply_group_attrs(obj, lio_so) elif plugin == 'iblock': # TODO Add policy for iblock lio_bs = IBlockBackstore(idx) dev = obj_attr(obj, "path") wwn = obj_attr(obj, "wwn") lio_so = lio_bs.storage_object(name, dev, wwn) apply_group_attrs(obj, lio_so) elif plugin == 'pscsi': # TODO Add policy for pscsi lio_bs = PSCSIBackstore(idx) dev = obj_attr(obj, "path") lio_so = lio_bs.storage_object(name, dev) apply_group_attrs(obj, lio_so) elif plugin == 'rd_mcp': # TODO Add policy for rd_mcp lio_bs = RDMCPBackstore(idx) size = obj_attr(obj, "size") wwn = obj_attr(obj, "wwn") nullio = obj_attr(obj, "nullio") lio_so = lio_bs.storage_object(name, size, wwn, nullio) apply_group_attrs(obj, lio_so) else: raise ConfigError("Unknown backend '%s' for backstore '%s'" % (plugin, obj)) matching_lio_so = [ so for so in root.storage_objects if so.backstore.plugin == plugin and so.name == name ] if len(matching_lio_so) > 1: raise ConfigError("Detected unsupported configfs storage objects " "allocation schema for '%s'" % obj.path_str) elif len(matching_lio_so) == 0: raise ConfigError("Could not find backstore '%s'" % obj.path_str) else: lio_so = matching_lio_so[0]
def apply_delete_obj(obj): ''' Deletes an object from the live system. ''' # TODO Factorize this when stable # TODO storage fabric cannot be deleted from the system, find a way to # handle this when i.e. path 'storage fileio' is in current config, but # no objects are hanging under it. root = get_root() log.debug("apply_delete(%s)" % obj.data) if obj.key[0] == 'mapped_lun': acl = obj.parent if acl.parent.key[0] == 'tpgt': tpg = acl.parent target = tpg.parent else: tpg = None target = acl.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') if tpg is None: tpgt = 1 else: tpgt = int(tpg.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') node_wwn = acl.key[1] lio_acl = NodeACL(lio_tpg, node_wwn, mode='lookup') mlun = int(obj.key[1]) lio_mlun = MappedLUN(lio_acl, mlun) lio_mlun.delete() elif obj.key[0] == 'acl': if obj.parent.key[0] == 'tpgt': tpg = obj.parent target = tpg.parent else: tpg = None target = obj.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') if tpg is None: tpgt = 1 else: tpgt = int(tpg.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') node_wwn = obj.key[1] lio_acl = NodeACL(lio_tpg, node_wwn, mode='lookup') lio_acl.delete() elif obj.key[0] == 'portal': if obj.parent.key[0] == 'tpgt': tpg = obj.parent target = tpg.parent else: tpg = None target = obj.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') if tpg is None: tpgt = 1 else: tpgt = int(tpg.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') (address, _, port) = obj.key[1].partition(':') port = int(port) lio_portal = NetworkPortal(lio_tpg, address, port, mode='lookup') lio_portal.delete() elif obj.key[0] == 'lun': if obj.parent.key[0] == 'tpgt': tpg = obj.parent target = tpg.parent else: tpg = None target = obj.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') if tpg is None: tpgt = 1 else: tpgt = int(tpg.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') lun = int(obj.key[1]) lio_lun = LUN(lio_tpg, lun) lio_lun.delete() elif obj.key[0] == 'tpgt': target = obj.parent fabric = target.parent lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=target.key[1], mode='lookup') tpgt = int(obj.key[1]) lio_tpg = TPG(lio_target, tpgt, mode='lookup') # FIXME IS this really needed ? lio_tpg.enable = True lio_tpg.delete() elif obj.key[0] == 'target': fabric = obj.parent wwn = obj.key[1] lio_fabric = FabricModule(fabric.key[1]) lio_target = Target(lio_fabric, wwn=wwn, mode='lookup') lio_target.delete() elif obj.key[0] == 'disk': plugin = obj.parent.key[1] name = obj.key[1] matching_lio_so = [so for so in root.storage_objects if so.backstore.plugin == plugin and so.name == name] log.debug("Looking for storage object %s in %s" % (obj.path_str, str(["%s/%s" % (so.backstore.plugin, so.name) for so in root.storage_objects]))) if len(matching_lio_so) > 1: raise ConfigError("Detected unsupported configfs storage objects " "allocation schema for storage object '%s'" % obj.path_str) elif len(matching_lio_so) == 0: raise ConfigError("Could not find storage object '%s'" % obj.path_str) else: lio_so = matching_lio_so[0] lio_so.delete()