Skip to main content
Glama
vespo92

TrueNAS Core MCP Server

create_iscsi_target

Create an iSCSI target for Kubernetes block storage by specifying the target name, dataset for storage, extent size, and portal ID in TrueNAS Core MCP Server.

Instructions

Create an iSCSI target for Kubernetes block storage

Args:
    name: Target name (e.g., "k8s-block-01")
    dataset: Dataset for storing the iSCSI extent
    size: Size of the iSCSI extent (e.g., "100G")
    portal_id: iSCSI portal ID to use

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
datasetYes
nameYes
portal_idNo
sizeYes

Implementation Reference

  • The main handler function decorated with @tool_handler that executes the create_iscsi_target tool. It generates an IQN, prepares target data, calls the TrueNAS API to create the target, and returns success response with next steps.
    async def create_iscsi_target(
        self,
        name: str,
        alias: Optional[str] = None,
        mode: str = "ISCSI",
        auth_networks: Optional[List[str]] = None
    ) -> Dict[str, Any]:
        """
        Create an iSCSI target
        
        Args:
            name: Target name (will be part of IQN)
            alias: Optional alias for the target
            mode: Target mode (ISCSI or FC)
            auth_networks: List of authorized networks
            
        Returns:
            Dictionary containing created target information
        """
        await self.ensure_initialized()
        
        # Generate IQN
        from datetime import datetime
        year_month = datetime.now().strftime("%Y-%m")
        iqn = f"iqn.{year_month}.com.truenas:{name}"
        
        target_data = {
            "name": iqn,
            "alias": alias or name,
            "mode": mode,
            "groups": []
        }
        
        # Create auth group if networks specified
        if auth_networks:
            # This would require creating an auth group first
            # For now, we'll note this in the response
            pass
        
        created = await self.client.post("/iscsi/target", target_data)
        
        return {
            "success": True,
            "message": f"iSCSI target '{name}' created successfully",
            "target": {
                "id": created.get("id"),
                "iqn": created.get("name"),
                "alias": created.get("alias")
            },
            "next_steps": [
                "Create an extent (LUN) for this target",
                "Map the extent to this target",
                "Configure initiator groups if needed",
                "Enable iSCSI service if not already enabled"
            ]
        }
  • Tool registration within the get_tool_definitions() method of SharingTools class. Registers 'create_iscsi_target' with handler reference, description, and input schema.
        ("list_iscsi_targets", self.list_iscsi_targets, "List all iSCSI targets", {}),
        ("create_iscsi_target", self.create_iscsi_target, "Create an iSCSI target",
         {"name": {"type": "string", "required": True},
          "alias": {"type": "string", "required": False}}),
    ]
  • Input schema definition for the create_iscsi_target tool, specifying required 'name' and optional 'alias' parameters.
    {"name": {"type": "string", "required": True},
     "alias": {"type": "string", "required": False}}),

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/vespo92/TrueNasCoreMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server